1 /* $NetBSD: device.h,v 1.192 2025/10/12 23:34:23 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 2021 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /* 30 * Copyright (c) 1996, 2000 Christopher G. Demetriou 31 * All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 3. All advertising materials mentioning features or use of this software 42 * must display the following acknowledgement: 43 * This product includes software developed for the 44 * NetBSD Project. See http://www.NetBSD.org/ for 45 * information about NetBSD. 46 * 4. The name of the author may not be used to endorse or promote products 47 * derived from this software without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 50 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 51 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 52 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 53 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 58 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 * 60 * --(license Id: LICENSE.proto,v 1.1 2000/06/13 21:40:26 cgd Exp )-- 61 */ 62 63 /* 64 * Copyright (c) 1992, 1993 65 * The Regents of the University of California. All rights reserved. 66 * 67 * This software was developed by the Computer Systems Engineering group 68 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 69 * contributed to Berkeley. 70 * 71 * All advertising materials mentioning features or use of this software 72 * must display the following acknowledgement: 73 * This product includes software developed by the University of 74 * California, Lawrence Berkeley Laboratories. 75 * 76 * Redistribution and use in source and binary forms, with or without 77 * modification, are permitted provided that the following conditions 78 * are met: 79 * 1. Redistributions of source code must retain the above copyright 80 * notice, this list of conditions and the following disclaimer. 81 * 2. Redistributions in binary form must reproduce the above copyright 82 * notice, this list of conditions and the following disclaimer in the 83 * documentation and/or other materials provided with the distribution. 84 * 3. Neither the name of the University nor the names of its contributors 85 * may be used to endorse or promote products derived from this software 86 * without specific prior written permission. 87 * 88 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 89 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 90 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 91 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 92 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 93 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 94 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 95 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 96 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 97 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 98 * SUCH DAMAGE. 99 * 100 * @(#)device.h 8.2 (Berkeley) 2/17/94 101 */ 102 103 #ifndef _SYS_DEVICE_H_ 104 #define _SYS_DEVICE_H_ 105 106 #include <sys/device_if.h> 107 #include <sys/evcnt.h> 108 #include <sys/queue.h> 109 110 #if defined(_KERNEL) || defined(_KMEMUSER) 111 #include <sys/mutex.h> 112 #include <sys/condvar.h> 113 #include <sys/pmf.h> 114 #endif 115 116 #include <prop/proplib.h> 117 118 /* 119 * Minimal device structures. 120 * Note that all ``system'' device types are listed here. 121 */ 122 typedef enum devclass { 123 DV_DULL, /* generic, no special info */ 124 DV_CPU, /* CPU (carries resource utilization) */ 125 DV_DISK, /* disk drive (label, etc) */ 126 DV_IFNET, /* network interface */ 127 DV_TAPE, /* tape device */ 128 DV_TTY, /* serial line interface (?) */ 129 DV_AUDIODEV, /* audio device */ 130 DV_DISPLAYDEV, /* display device */ 131 DV_BUS, /* bus device */ 132 DV_VIRTUAL, /* unbacked virtual device */ 133 } devclass_t; 134 135 /* 136 * Actions for ca_activate. 137 */ 138 typedef enum devact { 139 DVACT_DEACTIVATE /* deactivate the device */ 140 } devact_t; 141 142 typedef enum { 143 DVA_SYSTEM, 144 DVA_HARDWARE 145 } devactive_t; 146 147 typedef struct cfdata *cfdata_t; 148 typedef struct cfdriver *cfdriver_t; 149 typedef struct cfattach *cfattach_t; 150 151 #if defined(_KERNEL) || defined(_KMEMUSER) || defined(_STANDALONE) 152 /* 153 * devhandle_t -- 154 * 155 * This is an abstraction of the device handles used by ACPI, 156 * OpenFirmware, and others, to support device enumeration and 157 * device tree linkage. A devhandle_t can be safely passed 158 * by value. 159 */ 160 struct devhandle { 161 const struct devhandle_impl * impl; 162 union { 163 /* 164 * Storage for the device handle. Which storage field 165 * is used is at the sole discretion of the type 166 * implementation. 167 */ 168 void * pointer; 169 const void * const_pointer; 170 uintptr_t uintptr; 171 intptr_t integer; 172 }; 173 }; 174 typedef struct devhandle devhandle_t; 175 #endif 176 177 #if defined(_KERNEL) || defined(_KMEMUSER) 178 struct device_compatible_entry { 179 union { 180 const char *compat; 181 uintptr_t id; 182 }; 183 union { 184 const void *data; 185 uintptr_t value; 186 }; 187 }; 188 189 #define DEVICE_COMPAT_EOL { .compat = NULL } 190 191 struct device_suspensor { 192 const device_suspensor_t *ds_delegator; 193 char ds_name[32]; 194 }; 195 196 struct device_garbage { 197 device_t *dg_devs; 198 int dg_ndevs; 199 }; 200 201 202 typedef enum { 203 /* Used to represent invalid states. */ 204 DEVHANDLE_TYPE_INVALID = 0, 205 206 /* ACPI */ 207 DEVHANDLE_TYPE_ACPI = 0x41435049, /* 'ACPI' */ 208 209 /* OpenFirmware, FDT */ 210 DEVHANDLE_TYPE_OF = 0x4f504657, /* 'OPFW' */ 211 212 /* Sun OpenBoot */ 213 DEVHANDLE_TYPE_OPENBOOT = 0x4f504254, /* 'OPBT' */ 214 215 /* Private (opaque data) */ 216 DEVHANDLE_TYPE_PRIVATE = 0x50525654, /* 'PRVT' */ 217 218 /* Max value. */ 219 DEVHANDLE_TYPE_MAX = 0xffffffff 220 } devhandle_type_t; 221 222 /* Device method call function signature. */ 223 typedef int (*device_call_t)(device_t, devhandle_t, void *); 224 225 struct device_call_descriptor { 226 const char *name; 227 device_call_t call; 228 }; 229 230 #define _DEVICE_CALL_REGISTER(_g_, _c_) \ 231 __link_set_add_rodata(_g_, __CONCAT(_c_,_descriptor)); 232 #define DEVICE_CALL_REGISTER(_g_, _n_, _c_) \ 233 static const struct device_call_descriptor __CONCAT(_c_,_descriptor) = {\ 234 .name = (_n_), .call = (_c_) \ 235 }; \ 236 _DEVICE_CALL_REGISTER(_g_, _c_) 237 238 #define SYSDFLT_DEVICE_CALL_REGISTER(_n_, _c_) \ 239 DEVICE_CALL_REGISTER(sysdflt_device_calls, _n_, _c_) 240 241 struct devhandle_impl { 242 devhandle_type_t type; 243 const struct devhandle_impl * super; 244 device_call_t (*lookup_device_call)(devhandle_t, 245 const char *, devhandle_t *); 246 }; 247 248 /* Max size of a device external name (including terminating NUL) */ 249 #define DEVICE_XNAME_SIZE 16 250 251 struct device; 252 253 /* 254 * struct cfattach::ca_flags (must not overlap with device_impl.h 255 * struct device::dv_flags for now) 256 */ 257 #define DVF_PRIV_ALLOC 0x0002 /* device private storage != device */ 258 #define DVF_DETACH_SHUTDOWN 0x0080 /* device detaches safely at shutdown */ 259 260 #ifdef _KERNEL 261 TAILQ_HEAD(devicelist, device); 262 #endif 263 264 enum deviter_flags { 265 DEVITER_F_RW = 0x1 266 , DEVITER_F_SHUTDOWN = 0x2 267 , DEVITER_F_LEAVES_FIRST = 0x4 268 , DEVITER_F_ROOT_FIRST = 0x8 269 }; 270 271 typedef enum deviter_flags deviter_flags_t; 272 273 struct deviter { 274 device_t di_prev; 275 deviter_flags_t di_flags; 276 int di_curdepth; 277 int di_maxdepth; 278 devgen_t di_gen; 279 }; 280 281 typedef struct deviter deviter_t; 282 283 struct shutdown_state { 284 bool initialized; 285 deviter_t di; 286 }; 287 #endif 288 289 /* 290 * Description of a locator, as part of interface attribute definitions. 291 */ 292 struct cflocdesc { 293 const char *cld_name; 294 const char *cld_defaultstr; /* NULL if no default */ 295 int cld_default; 296 }; 297 298 /* 299 * Description of an interface attribute, provided by potential 300 * parent device drivers, referred to by child device configuration data. 301 */ 302 struct cfiattrdata { 303 const char *ci_name; 304 int ci_loclen; 305 const struct cflocdesc ci_locdesc[ 306 #if defined(__GNUC__) && __GNUC__ <= 2 307 0 308 #endif 309 ]; 310 }; 311 312 /* 313 * Description of a configuration parent. Each device attachment attaches 314 * to an "interface attribute", which is given in this structure. The parent 315 * *must* carry this attribute. Optionally, an individual device instance 316 * may also specify a specific parent device instance. 317 */ 318 struct cfparent { 319 const char *cfp_iattr; /* interface attribute */ 320 const char *cfp_parent; /* optional specific parent */ 321 int cfp_unit; /* optional specific unit 322 (DVUNIT_ANY to wildcard) */ 323 }; 324 325 /* 326 * Configuration data (i.e., data placed in ioconf.c). 327 */ 328 struct cfdata { 329 const char *cf_name; /* driver name */ 330 const char *cf_atname; /* attachment name */ 331 unsigned int cf_unit:24; /* unit number */ 332 unsigned char cf_fstate; /* finding state (below) */ 333 int *cf_loc; /* locators (machine dependent) */ 334 int cf_flags; /* flags from config */ 335 const struct cfparent *cf_pspec;/* parent specification */ 336 }; 337 #define FSTATE_NOTFOUND 0 /* has not been found */ 338 #define FSTATE_FOUND 1 /* has been found */ 339 #define FSTATE_STAR 2 /* duplicable */ 340 #define FSTATE_DSTAR 3 /* has not been found, and disabled */ 341 #define FSTATE_DNOTFOUND 4 /* duplicate, and disabled */ 342 343 /* 344 * Multiple configuration data tables may be maintained. This structure 345 * provides the linkage. 346 */ 347 struct cftable { 348 cfdata_t ct_cfdata; /* pointer to cfdata table */ 349 TAILQ_ENTRY(cftable) ct_list; /* list linkage */ 350 }; 351 #ifdef _KERNEL 352 TAILQ_HEAD(cftablelist, cftable); 353 #endif 354 355 typedef int (*cfsubmatch_t)(device_t, cfdata_t, const int *, void *); 356 typedef int (*cfsearch_t)(device_t, cfdata_t, const int *, void *); 357 358 /* 359 * `configuration' attachment and driver (what the machine-independent 360 * autoconf uses). As devices are found, they are applied against all 361 * the potential matches. The one with the best match is taken, and a 362 * device structure (plus any other data desired) is allocated. Pointers 363 * to these are placed into an array of pointers. The array itself must 364 * be dynamic since devices can be found long after the machine is up 365 * and running. 366 * 367 * Devices can have multiple configuration attachments if they attach 368 * to different attributes (busses, or whatever), to allow specification 369 * of multiple match and attach functions. There is only one configuration 370 * driver per driver, so that things like unit numbers and the device 371 * structure array will be shared. 372 */ 373 struct cfattach { 374 const char *ca_name; /* name of attachment */ 375 LIST_ENTRY(cfattach) ca_list; /* link on cfdriver's list */ 376 size_t ca_devsize; /* size of dev data (for alloc) */ 377 int ca_flags; /* flags for driver allocation etc */ 378 int (*ca_match)(device_t, cfdata_t, void *); 379 void (*ca_attach)(device_t, device_t, void *); 380 int (*ca_detach)(device_t, int); 381 int (*ca_activate)(device_t, devact_t); 382 /* technically, the next 2 belong into "struct cfdriver" */ 383 int (*ca_rescan)(device_t, const char *, 384 const int *); /* scan for new children */ 385 void (*ca_childdetached)(device_t, device_t); 386 }; 387 LIST_HEAD(cfattachlist, cfattach); 388 389 #define CFATTACH_DECL3_NEW(name, ddsize, matfn, attfn, detfn, actfn, \ 390 rescanfn, chdetfn, __flags) \ 391 struct cfattach __CONCAT(name,_ca) = { \ 392 .ca_name = ___STRING(name), \ 393 .ca_devsize = ddsize, \ 394 .ca_flags = (__flags) | DVF_PRIV_ALLOC, \ 395 .ca_match = matfn, \ 396 .ca_attach = attfn, \ 397 .ca_detach = detfn, \ 398 .ca_activate = actfn, \ 399 .ca_rescan = rescanfn, \ 400 .ca_childdetached = chdetfn, \ 401 } 402 403 #define CFATTACH_DECL2_NEW(name, ddsize, matfn, attfn, detfn, actfn, \ 404 rescanfn, chdetfn) \ 405 CFATTACH_DECL3_NEW(name, ddsize, matfn, attfn, detfn, actfn, \ 406 rescanfn, chdetfn, 0) 407 408 #define CFATTACH_DECL_NEW(name, ddsize, matfn, attfn, detfn, actfn) \ 409 CFATTACH_DECL2_NEW(name, ddsize, matfn, attfn, detfn, actfn, NULL, NULL) 410 411 /* Flags given to config_detach(), and the ca_detach function. */ 412 #define DETACH_FORCE 0x01 /* force detachment; hardware gone */ 413 #define DETACH_QUIET 0x02 /* don't print a notice */ 414 #define DETACH_SHUTDOWN 0x04 /* detach because of system shutdown */ 415 #define DETACH_POWEROFF 0x08 /* going to power off; power down devices */ 416 417 struct cfdriver { 418 LIST_ENTRY(cfdriver) cd_list; /* link on allcfdrivers */ 419 struct cfattachlist cd_attach; /* list of all attachments */ 420 device_t *cd_devs; /* devices found */ 421 const char *cd_name; /* device name */ 422 enum devclass cd_class; /* device classification */ 423 int cd_ndevs; /* size of cd_devs array */ 424 const struct cfiattrdata * const *cd_attrs; /* attributes provided */ 425 }; 426 LIST_HEAD(cfdriverlist, cfdriver); 427 428 #define CFDRIVER_DECL(name, class, attrs) \ 429 struct cfdriver __CONCAT(name,_cd) = { \ 430 .cd_name = ___STRING(name), \ 431 .cd_class = class, \ 432 .cd_attrs = attrs, \ 433 } 434 435 /* 436 * The cfattachinit is a data structure used to associate a list of 437 * cfattach's with cfdrivers as found in the static kernel configuration. 438 */ 439 struct cfattachinit { 440 const char *cfai_name; /* driver name */ 441 struct cfattach * const *cfai_list;/* list of attachments */ 442 }; 443 444 /* 445 * Configuration printing functions, and their return codes. The second 446 * argument is NULL if the device was configured; otherwise it is the name 447 * of the parent device. The return value is ignored if the device was 448 * configured, so most functions can return UNCONF unconditionally. 449 */ 450 typedef int (*cfprint_t)(void *, const char *); /* XXX const char * */ 451 #define QUIET 0 /* print nothing */ 452 #define UNCONF 1 /* print " not configured\n" */ 453 #define UNSUPP 2 /* print " not supported\n" */ 454 455 /* 456 * Pseudo-device attach information (function + number of pseudo-devs). 457 */ 458 struct pdevinit { 459 void (*pdev_attach)(int); 460 int pdev_count; 461 }; 462 463 /* This allows us to wildcard a device unit. */ 464 #define DVUNIT_ANY -1 465 466 #if defined(_KERNEL) || defined(_KMEMUSER) || defined(_STANDALONE) 467 /* 468 * Arguments passed to config_search() and config_found(). 469 */ 470 struct cfargs { 471 uintptr_t cfargs_version; /* version field */ 472 473 /* version 1 fields */ 474 cfsubmatch_t submatch; /* submatch function (direct config) */ 475 cfsearch_t search; /* search function (indirect config) */ 476 const char * iattr; /* interface attribute */ 477 const int * locators; /* locators array */ 478 devhandle_t devhandle; /* devhandle_t (by value) */ 479 480 /* version 2 fields below here */ 481 }; 482 483 #define CFARGS_VERSION 1 /* current cfargs version */ 484 485 #define CFARGS_NONE NULL /* no cfargs to pass */ 486 487 /* 488 * Construct a cfargs with this macro, like so: 489 * 490 * CFARGS(.submatch = config_stdsubmatch, 491 * .devhandle = my_devhandle) 492 * 493 * You must supply at least one field. If you don't need any, use the 494 * CFARGS_NONE macro. 495 */ 496 #define CFARGS(...) \ 497 &((const struct cfargs){ \ 498 .cfargs_version = CFARGS_VERSION, \ 499 __VA_ARGS__ \ 500 }) 501 #endif /* _KERNEL || _KMEMUSER || _STANDALONE */ 502 503 #ifdef _KERNEL 504 505 extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */ 506 extern struct cftablelist allcftables; /* list of all cfdata tables */ 507 extern device_t booted_device; /* the device we booted from */ 508 extern const char *booted_method; /* the method the device was found */ 509 extern int booted_partition; /* the partition on that device */ 510 extern daddr_t booted_startblk; /* or the start of a wedge */ 511 extern uint64_t booted_nblks; /* and the size of that wedge */ 512 extern char *bootspec; /* and the device/wedge name */ 513 extern bool root_is_mounted; /* true if root is mounted */ 514 515 struct vnode *opendisk(device_t); 516 int getdisksize(struct vnode *, uint64_t *, unsigned int *); 517 struct dkwedge_info; 518 int getdiskinfo(struct vnode *, struct dkwedge_info *); 519 520 void config_init(void); 521 int config_init_component(struct cfdriver *const*, 522 const struct cfattachinit *, struct cfdata *); 523 int config_fini_component(struct cfdriver *const*, 524 const struct cfattachinit *, struct cfdata *); 525 void config_init_mi(void); 526 void drvctl_init(void); 527 void drvctl_fini(void); 528 extern int (*devmon_insert_vec)(const char *, prop_dictionary_t); 529 530 int config_cfdriver_attach(struct cfdriver *); 531 int config_cfdriver_detach(struct cfdriver *); 532 533 int config_cfattach_attach(const char *, struct cfattach *); 534 int config_cfattach_detach(const char *, struct cfattach *); 535 536 int config_cfdata_attach(cfdata_t, int); 537 int config_cfdata_detach(cfdata_t); 538 539 struct cfdriver *config_cfdriver_lookup(const char *); 540 struct cfattach *config_cfattach_lookup(const char *, const char *); 541 const struct cfiattrdata *cfiattr_lookup(const char *, const struct cfdriver *); 542 543 const char *cfdata_ifattr(const struct cfdata *); 544 545 int config_stdsubmatch(device_t, cfdata_t, const int *, void *); 546 cfdata_t config_search(device_t, void *, const struct cfargs *); 547 cfdata_t config_rootsearch(cfsubmatch_t, const char *, void *); 548 device_t config_found(device_t, void *, cfprint_t, const struct cfargs *); 549 device_t config_rootfound(const char *, void *); 550 device_t config_attach(device_t, cfdata_t, void *, cfprint_t, 551 const struct cfargs *); 552 device_t config_found_acquire(device_t, void *, cfprint_t, 553 const struct cfargs *); 554 device_t config_attach_acquire(device_t, cfdata_t, void *, cfprint_t, 555 const struct cfargs *); 556 int config_match(device_t, cfdata_t, void *); 557 int config_probe(device_t, cfdata_t, void *); 558 559 bool ifattr_match(const char *, const char *); 560 561 device_t config_attach_pseudo(cfdata_t); 562 device_t config_attach_pseudo_acquire(cfdata_t, void *); 563 564 int config_detach(device_t, int); 565 int config_detach_release(device_t, int); 566 int config_detach_children(device_t, int flags); 567 void config_detach_commit(device_t); 568 bool config_detach_all(int); 569 int config_deactivate(device_t); 570 void config_defer(device_t, void (*)(device_t)); 571 void config_deferred(device_t); 572 void config_interrupts(device_t, void (*)(device_t)); 573 void config_mountroot(device_t, void (*)(device_t)); 574 void config_pending_incr(device_t); 575 void config_pending_decr(device_t); 576 void config_create_interruptthreads(void); 577 void config_create_mountrootthreads(void); 578 579 int config_finalize_register(device_t, int (*)(device_t)); 580 void config_finalize(void); 581 void config_finalize_mountroot(void); 582 583 void config_twiddle_init(void); 584 void config_twiddle_fn(void *); 585 586 void null_childdetached(device_t, device_t); 587 588 device_t device_lookup(cfdriver_t, int); 589 void *device_lookup_private(cfdriver_t, int); 590 591 device_t device_lookup_acquire(cfdriver_t, int); 592 void device_acquire(device_t); 593 void device_release(device_t); 594 595 void device_register(device_t, void *); 596 void device_register_post_config(device_t, void *); 597 598 devclass_t device_class(device_t); 599 cfdata_t device_cfdata(device_t); 600 cfdriver_t device_cfdriver(device_t); 601 cfattach_t device_cfattach(device_t); 602 int device_unit(device_t); 603 const char *device_xname(device_t); 604 device_t device_parent(device_t); 605 bool device_is_active(device_t); 606 bool device_activation(device_t, devact_level_t); 607 bool device_is_enabled(device_t); 608 bool device_has_power(device_t); 609 int device_locator(device_t, u_int); 610 void *device_private(device_t); 611 void device_set_private(device_t, void *); 612 prop_dictionary_t device_properties(device_t); 613 void device_set_handle(device_t, devhandle_t); 614 devhandle_t device_handle(device_t); 615 616 bool devhandle_is_valid(devhandle_t); 617 devhandle_t devhandle_invalid(void); 618 devhandle_type_t devhandle_type(devhandle_t); 619 int devhandle_compare(devhandle_t, devhandle_t); 620 devhandle_t devhandle_subclass(devhandle_t, struct devhandle_impl *, 621 device_call_t (*)(devhandle_t, const char *, 622 devhandle_t *)); 623 624 device_call_t devhandle_lookup_device_call(devhandle_t, const char *, 625 devhandle_t *); 626 void devhandle_impl_subclass(struct devhandle_impl *, 627 const struct devhandle_impl *, 628 device_call_t (*)(devhandle_t, const char *, 629 devhandle_t *)); 630 631 device_t deviter_first(deviter_t *, deviter_flags_t); 632 void deviter_init(deviter_t *, deviter_flags_t); 633 device_t deviter_next(deviter_t *); 634 void deviter_release(deviter_t *); 635 636 bool device_active(device_t, devactive_t); 637 bool device_active_register(device_t, 638 void (*)(device_t, devactive_t)); 639 void device_active_deregister(device_t, 640 void (*)(device_t, devactive_t)); 641 642 bool device_is_a(device_t, const char *); 643 bool device_attached_to_iattr(device_t, const char *); 644 645 device_t device_find_by_xname(const char *); 646 device_t device_find_by_driver_unit(const char *, int); 647 648 int device_enumerate_children(device_t, 649 bool (*)(device_t, devhandle_t, void *), void *); 650 651 int device_compatible_match(const char **, int, 652 const struct device_compatible_entry *); 653 int device_compatible_pmatch(const char **, int, 654 const struct device_compatible_entry *); 655 const struct device_compatible_entry * 656 device_compatible_lookup(const char **, int, 657 const struct device_compatible_entry *); 658 const struct device_compatible_entry * 659 device_compatible_plookup(const char **, int, 660 const struct device_compatible_entry *); 661 662 int device_compatible_match_strlist(const char *, size_t, 663 const struct device_compatible_entry *); 664 int device_compatible_pmatch_strlist(const char *, size_t, 665 const struct device_compatible_entry *); 666 const struct device_compatible_entry * 667 device_compatible_lookup_strlist(const char *, size_t, 668 const struct device_compatible_entry *); 669 const struct device_compatible_entry * 670 device_compatible_plookup_strlist(const char *, size_t, 671 const struct device_compatible_entry *); 672 673 int device_compatible_match_id(uintptr_t const, uintptr_t const, 674 const struct device_compatible_entry *); 675 const struct device_compatible_entry * 676 device_compatible_lookup_id(uintptr_t const, uintptr_t const, 677 const struct device_compatible_entry *); 678 679 void device_pmf_driver_child_register(device_t); 680 void device_pmf_driver_set_child_register(device_t, 681 void (*)(device_t)); 682 683 void *device_pmf_bus_private(device_t); 684 bool device_pmf_bus_suspend(device_t, const pmf_qual_t *); 685 bool device_pmf_bus_resume(device_t, const pmf_qual_t *); 686 bool device_pmf_bus_shutdown(device_t, int); 687 688 void device_pmf_bus_register(device_t, void *, 689 bool (*)(device_t, const pmf_qual_t *), 690 bool (*)(device_t, const pmf_qual_t *), 691 bool (*)(device_t, int), 692 void (*)(device_t)); 693 void device_pmf_bus_deregister(device_t); 694 695 device_t shutdown_first(struct shutdown_state *); 696 device_t shutdown_next(struct shutdown_state *); 697 698 /* 699 * device calls -- 700 * 701 * This provides a generic mechanism for invoking special methods on 702 * devices, often dependent on the device tree implementation used 703 * by the platform. 704 * 705 * While individual subsystems may define their own device calls, 706 * the ones prefixed with "device-" are reserved, and defined by 707 * the device autoconfiguration subsystem. It is the responsibility 708 * of each device tree back end to implement these calls. 709 * 710 * We define a generic interface; individual device calls feature 711 * type checking of the argument structure. The argument structures 712 * and the call binding data are automatically generated from device 713 * call interface descriptions by gendevcalls.awk. 714 */ 715 struct device_call_generic { 716 const char *name; 717 void *args; 718 }; 719 720 int device_call_generic(device_t, devhandle_t, 721 const struct device_call_generic *); 722 723 #define device_call(dev, call) \ 724 device_call_generic((dev), device_handle(dev), &(call)->generic) 725 #define devhandle_call(handle, call) \ 726 device_call_generic(NULL, (handle), &(call)->generic) 727 728 /* 729 * Device property infrastructure. 730 */ 731 bool device_hasprop(device_t, const char *); 732 ssize_t device_getproplen(device_t, const char *); 733 int device_getpropencoding(device_t, const char *); 734 prop_type_t device_getproptype(device_t, const char *); 735 736 ssize_t device_getprop_data(device_t, const char *, void *, size_t); 737 ssize_t device_getprop_string(device_t, const char *, char *, size_t); 738 bool device_getprop_bool(device_t, const char *); 739 740 void * device_getprop_data_alloc(device_t, const char *, size_t *); 741 char * device_getprop_string_alloc(device_t, const char *, size_t *); 742 743 bool device_getprop_int(device_t, const char *, int *); 744 bool device_getprop_uint(device_t, const char *, unsigned int *); 745 bool device_getprop_int32(device_t, const char *, int32_t *); 746 bool device_getprop_uint32(device_t, const char *, uint32_t *); 747 bool device_getprop_int64(device_t, const char *, int64_t *); 748 bool device_getprop_uint64(device_t, const char *, uint64_t *); 749 750 int device_getprop_int_default(device_t, const char *, int); 751 unsigned int device_getprop_uint_default(device_t, const char *, 752 unsigned int); 753 int32_t device_getprop_int32_default(device_t, const char *, int32_t); 754 uint32_t device_getprop_uint32_default(device_t, const char *, uint32_t); 755 int64_t device_getprop_int64_default(device_t, const char *, int64_t); 756 uint64_t device_getprop_uint64_default(device_t, const char *, uint64_t); 757 758 bool device_setprop_data(device_t, const char *, const void *, 759 size_t); 760 bool device_setprop_string(device_t, const char *, const char *); 761 bool device_setprop_bool(device_t, const char *, bool); 762 763 bool device_setprop_int(device_t, const char *, int); 764 bool device_setprop_uint(device_t, const char *, unsigned int); 765 bool device_setprop_int32(device_t, const char *, int32_t); 766 bool device_setprop_uint32(device_t, const char *, uint32_t); 767 bool device_setprop_int64(device_t, const char *, int64_t); 768 bool device_setprop_uint64(device_t, const char *, uint64_t); 769 770 void device_delprop(device_t, const char *); 771 772 #endif /* _KERNEL */ 773 774 #endif /* !_SYS_DEVICE_H_ */ 775