2 * Copyright (c) 2010 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Alex Hornung <ahornung@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/types.h>
35 #include <sys/device.h>
37 #include <sys/socket.h>
38 #include <sys/ioctl.h>
40 #include <sys/queue.h>
42 #include <cpu/inttypes.h>
58 #include <libprop/proplib.h>
62 static int64_t udev_generation;
63 TAILQ_HEAD(pdev_array_list_head, pdev_array_entry) pdev_array_list;
66 pdev_array_entry_ref(struct pdev_array_entry *pae)
72 pdev_array_entry_unref(struct pdev_array_entry *pae)
74 if (--pae->refs == 0) {
75 TAILQ_REMOVE(&pdev_array_list, pae, link);
76 prop_object_release(pae->pdev_array); /* XXX */
82 pdev_array_entry_insert(prop_array_t pa)
84 struct pdev_array_entry *pae, *opae = NULL;
87 errx(1, "null prop_array in insert_pdev_array");
88 pae = malloc(sizeof(struct pdev_array_entry));
90 errx(1, "insert_pdev_array could not allocate mem");
91 memset(pae, 0, sizeof(struct pdev_array_entry));
93 pae->generation = udev_generation++;
94 pae->refs = 1; /* One ref because it's the most recent one */
97 * If the TAILQ is not empty, unref the last entry,
98 * as it isn't needed anymore.
100 if (!TAILQ_EMPTY(&pdev_array_list))
101 opae = TAILQ_LAST(&pdev_array_list, pdev_array_list_head);
103 TAILQ_INSERT_TAIL(&pdev_array_list, pae, link);
106 pdev_array_entry_unref(opae);
110 pdev_array_clean(void)
112 struct pdev_array_entry *pae;
114 while ((pae = TAILQ_LAST(&pdev_array_list, pdev_array_list_head)) != NULL) {
115 TAILQ_REMOVE(&pdev_array_list, pae, link);
116 prop_object_release(pae->pdev_array);
121 struct pdev_array_entry *
122 pdev_array_entry_get(int64_t generation)
124 struct pdev_array_entry *pae;
127 TAILQ_FOREACH(pae, &pdev_array_list, link) {
128 if (pae->generation == generation) {
137 pdev_array_entry_ref(pae);
141 struct pdev_array_entry *
142 pdev_array_entry_get_last(void)
144 struct pdev_array_entry *pae;
146 pae = TAILQ_LAST(&pdev_array_list, pdev_array_list_head);
148 pdev_array_entry_ref(pae);