1 /* $NetBSD: device.h,v 1.193 2026/01/17 02:01:39 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 cfattachiattr associates a cfattach (which normally does not 437 * carry interface attribute information) with a cfiattrdata (because 438 * in very rare cases, it may need to). 439 */ 440 struct cfattachiattr { 441 LIST_ENTRY(cfattachiattr) cfia_list; /* entry on global list */ 442 struct cfattach *cfia_attach; /* ptr to cfattach */ 443 const struct cfiattrdata *cfia_iattr; /* associated iattr data */ 444 }; 445 446 /* 447 * The cfattachinit is a data structure used to associate a list of 448 * cfattach's with cfdrivers as found in the static kernel configuration. 449 */ 450 struct cfattachinit { 451 const char *cfai_name; /* driver name */ 452 struct cfattach * const *cfai_list;/* list of attachments */ 453 /* associated iattrs (if any */ 454 struct cfattachiattr * const *cfai_iattrs; 455 }; 456 457 /* 458 * Configuration printing functions, and their return codes. The second 459 * argument is NULL if the device was configured; otherwise it is the name 460 * of the parent device. The return value is ignored if the device was 461 * configured, so most functions can return UNCONF unconditionally. 462 */ 463 typedef int (*cfprint_t)(void *, const char *); /* XXX const char * */ 464 #define QUIET 0 /* print nothing */ 465 #define UNCONF 1 /* print " not configured\n" */ 466 #define UNSUPP 2 /* print " not supported\n" */ 467 468 /* 469 * Pseudo-device attach information (function + number of pseudo-devs). 470 */ 471 struct pdevinit { 472 void (*pdev_attach)(int); 473 int pdev_count; 474 }; 475 476 /* This allows us to wildcard a device unit. */ 477 #define DVUNIT_ANY -1 478 479 #if defined(_KERNEL) || defined(_KMEMUSER) || defined(_STANDALONE) 480 /* 481 * Arguments passed to config_search() and config_found(). 482 */ 483 struct cfargs { 484 uintptr_t cfargs_version; /* version field */ 485 486 /* version 1 fields */ 487 cfsubmatch_t submatch; /* submatch function (direct config) */ 488 cfsearch_t search; /* search function (indirect config) */ 489 const char * iattr; /* interface attribute */ 490 const int * locators; /* locators array */ 491 devhandle_t devhandle; /* devhandle_t (by value) */ 492 493 /* version 2 fields below here */ 494 }; 495 496 #define CFARGS_VERSION 1 /* current cfargs version */ 497 498 #define CFARGS_NONE NULL /* no cfargs to pass */ 499 500 /* 501 * Construct a cfargs with this macro, like so: 502 * 503 * CFARGS(.submatch = config_stdsubmatch, 504 * .devhandle = my_devhandle) 505 * 506 * You must supply at least one field. If you don't need any, use the 507 * CFARGS_NONE macro. 508 */ 509 #define CFARGS(...) \ 510 &((const struct cfargs){ \ 511 .cfargs_version = CFARGS_VERSION, \ 512 __VA_ARGS__ \ 513 }) 514 #endif /* _KERNEL || _KMEMUSER || _STANDALONE */ 515 516 #ifdef _KERNEL 517 518 extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */ 519 extern struct cftablelist allcftables; /* list of all cfdata tables */ 520 extern device_t booted_device; /* the device we booted from */ 521 extern const char *booted_method; /* the method the device was found */ 522 extern int booted_partition; /* the partition on that device */ 523 extern daddr_t booted_startblk; /* or the start of a wedge */ 524 extern uint64_t booted_nblks; /* and the size of that wedge */ 525 extern char *bootspec; /* and the device/wedge name */ 526 extern bool root_is_mounted; /* true if root is mounted */ 527 528 struct vnode *opendisk(device_t); 529 int getdisksize(struct vnode *, uint64_t *, unsigned int *); 530 struct dkwedge_info; 531 int getdiskinfo(struct vnode *, struct dkwedge_info *); 532 533 void config_init(void); 534 int config_init_component(struct cfdriver *const*, 535 const struct cfattachinit *, struct cfdata *); 536 int config_fini_component(struct cfdriver *const*, 537 const struct cfattachinit *, struct cfdata *); 538 void config_init_mi(void); 539 void drvctl_init(void); 540 void drvctl_fini(void); 541 extern int (*devmon_insert_vec)(const char *, prop_dictionary_t); 542 543 int config_cfdriver_attach(struct cfdriver *); 544 int config_cfdriver_detach(struct cfdriver *); 545 546 int config_cfattach_attach(const char *, struct cfattach *); 547 int config_cfattach_detach(const char *, struct cfattach *); 548 549 int config_cfdata_attach(cfdata_t, int); 550 int config_cfdata_detach(cfdata_t); 551 552 struct cfdriver *config_cfdriver_lookup(const char *); 553 struct cfattach *config_cfattach_lookup(const char *, const char *); 554 const struct cfiattrdata *cfiattr_lookup(const char *, const struct cfdriver *, 555 const struct cfattach *); 556 557 const char *cfdata_ifattr(const struct cfdata *); 558 559 int config_stdsubmatch(device_t, cfdata_t, const int *, void *); 560 cfdata_t config_search(device_t, void *, const struct cfargs *); 561 cfdata_t config_rootsearch(cfsubmatch_t, const char *, void *); 562 device_t config_found(device_t, void *, cfprint_t, const struct cfargs *); 563 device_t config_rootfound(const char *, void *); 564 device_t config_attach(device_t, cfdata_t, void *, cfprint_t, 565 const struct cfargs *); 566 device_t config_found_acquire(device_t, void *, cfprint_t, 567 const struct cfargs *); 568 device_t config_attach_acquire(device_t, cfdata_t, void *, cfprint_t, 569 const struct cfargs *); 570 int config_match(device_t, cfdata_t, void *); 571 int config_probe(device_t, cfdata_t, void *); 572 573 bool ifattr_match(const char *, const char *); 574 575 device_t config_attach_pseudo(cfdata_t); 576 device_t config_attach_pseudo_acquire(cfdata_t, void *); 577 578 int config_detach(device_t, int); 579 int config_detach_release(device_t, int); 580 int config_detach_children(device_t, int flags); 581 void config_detach_commit(device_t); 582 bool config_detach_all(int); 583 int config_deactivate(device_t); 584 void config_defer(device_t, void (*)(device_t)); 585 void config_deferred(device_t); 586 void config_interrupts(device_t, void (*)(device_t)); 587 void config_mountroot(device_t, void (*)(device_t)); 588 void config_pending_incr(device_t); 589 void config_pending_decr(device_t); 590 void config_create_interruptthreads(void); 591 void config_create_mountrootthreads(void); 592 593 int config_finalize_register(device_t, int (*)(device_t)); 594 void config_finalize(void); 595 void config_finalize_mountroot(void); 596 597 void config_twiddle_init(void); 598 void config_twiddle_fn(void *); 599 600 void null_childdetached(device_t, device_t); 601 602 device_t device_lookup(cfdriver_t, int); 603 void *device_lookup_private(cfdriver_t, int); 604 605 device_t device_lookup_acquire(cfdriver_t, int); 606 void device_acquire(device_t); 607 void device_release(device_t); 608 609 void device_register(device_t, void *); 610 void device_register_post_config(device_t, void *); 611 612 devclass_t device_class(device_t); 613 cfdata_t device_cfdata(device_t); 614 cfdriver_t device_cfdriver(device_t); 615 cfattach_t device_cfattach(device_t); 616 int device_unit(device_t); 617 const char *device_xname(device_t); 618 device_t device_parent(device_t); 619 bool device_is_active(device_t); 620 bool device_activation(device_t, devact_level_t); 621 bool device_is_enabled(device_t); 622 bool device_has_power(device_t); 623 int device_locator(device_t, u_int); 624 void *device_private(device_t); 625 void device_set_private(device_t, void *); 626 prop_dictionary_t device_properties(device_t); 627 void device_set_handle(device_t, devhandle_t); 628 devhandle_t device_handle(device_t); 629 630 bool devhandle_is_valid(devhandle_t); 631 devhandle_t devhandle_invalid(void); 632 devhandle_type_t devhandle_type(devhandle_t); 633 int devhandle_compare(devhandle_t, devhandle_t); 634 devhandle_t devhandle_subclass(devhandle_t, struct devhandle_impl *, 635 device_call_t (*)(devhandle_t, const char *, 636 devhandle_t *)); 637 638 device_call_t devhandle_lookup_device_call(devhandle_t, const char *, 639 devhandle_t *); 640 void devhandle_impl_subclass(struct devhandle_impl *, 641 const struct devhandle_impl *, 642 device_call_t (*)(devhandle_t, const char *, 643 devhandle_t *)); 644 645 device_t deviter_first(deviter_t *, deviter_flags_t); 646 void deviter_init(deviter_t *, deviter_flags_t); 647 device_t deviter_next(deviter_t *); 648 void deviter_release(deviter_t *); 649 650 bool device_active(device_t, devactive_t); 651 bool device_active_register(device_t, 652 void (*)(device_t, devactive_t)); 653 void device_active_deregister(device_t, 654 void (*)(device_t, devactive_t)); 655 656 bool device_is_a(device_t, const char *); 657 bool device_attached_to_iattr(device_t, const char *); 658 659 device_t device_find_by_xname(const char *); 660 device_t device_find_by_driver_unit(const char *, int); 661 662 int device_enumerate_children(device_t, 663 bool (*)(device_t, devhandle_t, void *), void *); 664 665 int device_compatible_match(const char **, int, 666 const struct device_compatible_entry *); 667 int device_compatible_pmatch(const char **, int, 668 const struct device_compatible_entry *); 669 const struct device_compatible_entry * 670 device_compatible_lookup(const char **, int, 671 const struct device_compatible_entry *); 672 const struct device_compatible_entry * 673 device_compatible_plookup(const char **, int, 674 const struct device_compatible_entry *); 675 676 int device_compatible_match_strlist(const char *, size_t, 677 const struct device_compatible_entry *); 678 int device_compatible_pmatch_strlist(const char *, size_t, 679 const struct device_compatible_entry *); 680 const struct device_compatible_entry * 681 device_compatible_lookup_strlist(const char *, size_t, 682 const struct device_compatible_entry *); 683 const struct device_compatible_entry * 684 device_compatible_plookup_strlist(const char *, size_t, 685 const struct device_compatible_entry *); 686 687 int device_compatible_match_id(uintptr_t const, uintptr_t const, 688 const struct device_compatible_entry *); 689 const struct device_compatible_entry * 690 device_compatible_lookup_id(uintptr_t const, uintptr_t const, 691 const struct device_compatible_entry *); 692 693 void device_pmf_driver_child_register(device_t); 694 void device_pmf_driver_set_child_register(device_t, 695 void (*)(device_t)); 696 697 void *device_pmf_bus_private(device_t); 698 bool device_pmf_bus_suspend(device_t, const pmf_qual_t *); 699 bool device_pmf_bus_resume(device_t, const pmf_qual_t *); 700 bool device_pmf_bus_shutdown(device_t, int); 701 702 void device_pmf_bus_register(device_t, void *, 703 bool (*)(device_t, const pmf_qual_t *), 704 bool (*)(device_t, const pmf_qual_t *), 705 bool (*)(device_t, int), 706 void (*)(device_t)); 707 void device_pmf_bus_deregister(device_t); 708 709 device_t shutdown_first(struct shutdown_state *); 710 device_t shutdown_next(struct shutdown_state *); 711 712 /* 713 * device calls -- 714 * 715 * This provides a generic mechanism for invoking special methods on 716 * devices, often dependent on the device tree implementation used 717 * by the platform. 718 * 719 * While individual subsystems may define their own device calls, 720 * the ones prefixed with "device-" are reserved, and defined by 721 * the device autoconfiguration subsystem. It is the responsibility 722 * of each device tree back end to implement these calls. 723 * 724 * We define a generic interface; individual device calls feature 725 * type checking of the argument structure. The argument structures 726 * and the call binding data are automatically generated from device 727 * call interface descriptions by gendevcalls.awk. 728 */ 729 struct device_call_generic { 730 const char *name; 731 void *args; 732 }; 733 734 int device_call_generic(device_t, devhandle_t, 735 const struct device_call_generic *); 736 737 #define device_call(dev, call) \ 738 device_call_generic((dev), device_handle(dev), &(call)->generic) 739 #define devhandle_call(handle, call) \ 740 device_call_generic(NULL, (handle), &(call)->generic) 741 742 /* 743 * Device property infrastructure. 744 */ 745 bool device_hasprop(device_t, const char *); 746 ssize_t device_getproplen(device_t, const char *); 747 int device_getpropencoding(device_t, const char *); 748 prop_type_t device_getproptype(device_t, const char *); 749 750 ssize_t device_getprop_data(device_t, const char *, void *, size_t); 751 ssize_t device_getprop_string(device_t, const char *, char *, size_t); 752 bool device_getprop_bool(device_t, const char *); 753 754 void * device_getprop_data_alloc(device_t, const char *, size_t *); 755 char * device_getprop_string_alloc(device_t, const char *, size_t *); 756 757 bool device_getprop_int(device_t, const char *, int *); 758 bool device_getprop_uint(device_t, const char *, unsigned int *); 759 bool device_getprop_int32(device_t, const char *, int32_t *); 760 bool device_getprop_uint32(device_t, const char *, uint32_t *); 761 bool device_getprop_int64(device_t, const char *, int64_t *); 762 bool device_getprop_uint64(device_t, const char *, uint64_t *); 763 764 int device_getprop_int_default(device_t, const char *, int); 765 unsigned int device_getprop_uint_default(device_t, const char *, 766 unsigned int); 767 int32_t device_getprop_int32_default(device_t, const char *, int32_t); 768 uint32_t device_getprop_uint32_default(device_t, const char *, uint32_t); 769 int64_t device_getprop_int64_default(device_t, const char *, int64_t); 770 uint64_t device_getprop_uint64_default(device_t, const char *, uint64_t); 771 772 bool device_setprop_data(device_t, const char *, const void *, 773 size_t); 774 bool device_setprop_string(device_t, const char *, const char *); 775 bool device_setprop_bool(device_t, const char *, bool); 776 777 bool device_setprop_int(device_t, const char *, int); 778 bool device_setprop_uint(device_t, const char *, unsigned int); 779 bool device_setprop_int32(device_t, const char *, int32_t); 780 bool device_setprop_uint32(device_t, const char *, uint32_t); 781 bool device_setprop_int64(device_t, const char *, int64_t); 782 bool device_setprop_uint64(device_t, const char *, uint64_t); 783 784 void device_delprop(device_t, const char *); 785 786 #endif /* _KERNEL */ 787 788 #endif /* !_SYS_DEVICE_H_ */ 789