Index: sys/dev/acpica/acpi.c =================================================================== --- sys/dev/acpica/acpi.c +++ sys/dev/acpica/acpi.c @@ -144,6 +144,8 @@ int rid); static uint32_t acpi_isa_get_logicalid(device_t dev); static int acpi_isa_get_compatid(device_t dev, uint32_t *cids, int count); +static ssize_t acpi_bus_get_prop(device_t bus, device_t child, const char *propname, + void *propvalue, size_t size); static int acpi_device_id_probe(device_t bus, device_t dev, char **ids, char **match); static ACPI_STATUS acpi_device_eval_obj(device_t bus, device_t dev, ACPI_STRING pathname, ACPI_OBJECT_LIST *parameters, @@ -223,6 +225,7 @@ DEVMETHOD(bus_hint_device_unit, acpi_hint_device_unit), DEVMETHOD(bus_get_cpus, acpi_get_cpus), DEVMETHOD(bus_get_domain, acpi_get_domain), + DEVMETHOD(bus_get_property, acpi_bus_get_prop), /* ACPI bus */ DEVMETHOD(acpi_id_probe, acpi_device_id_probe), @@ -1817,6 +1820,40 @@ return (AE_NOT_FOUND); } +static ssize_t +acpi_bus_get_prop(device_t bus, device_t child, const char *propname, + void *propvalue, size_t size) +{ + ACPI_STATUS status; + const ACPI_OBJECT *obj; + + status = acpi_device_get_prop(bus, child, __DECONST(char *, propname), + &obj); + if (ACPI_FAILURE(status)) + return (-1); + + switch (obj->Type) { + case ACPI_TYPE_INTEGER: + if (propvalue != NULL && size >= sizeof(uint64_t)) + *((uint64_t *) propvalue) = obj->Integer.Value; + return (sizeof(uint64_t)); + + case ACPI_TYPE_STRING: + if (propvalue != NULL && size > 0) + memcpy(propvalue, obj->String.Pointer, + MIN(size, obj->String.Length)); + return (obj->String.Length); + + case ACPI_TYPE_BUFFER: + if (propvalue != NULL && size > 0) + memcpy(propvalue, obj->Buffer.Pointer, + MIN(size, obj->Buffer.Length)); + return (obj->Buffer.Length); + } + + return (-1); +} + int acpi_device_pwr_for_sleep(device_t bus, device_t dev, int *dstate) { Index: sys/dev/fdt/simplebus.c =================================================================== --- sys/dev/fdt/simplebus.c +++ sys/dev/fdt/simplebus.c @@ -54,6 +54,9 @@ const char *name, int unit); static struct resource_list *simplebus_get_resource_list(device_t bus, device_t child); + +static ssize_t simplebus_get_property(device_t bus, device_t child, + const char *propname, void *propvalue, size_t size); /* * ofw_bus interface */ @@ -89,6 +92,7 @@ DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), DEVMETHOD(bus_child_pnpinfo, ofw_bus_gen_child_pnpinfo), DEVMETHOD(bus_get_resource_list, simplebus_get_resource_list), + DEVMETHOD(bus_get_property, simplebus_get_property), /* ofw_bus interface */ DEVMETHOD(ofw_bus_get_devinfo, simplebus_get_devinfo), @@ -350,6 +354,18 @@ return (&ndi->rl); } +static ssize_t +simplebus_get_property(device_t bus, device_t child, const char *propname, + void *propvalue, size_t size) +{ + phandle_t node = ofw_bus_get_node(child); + + if (propvalue == NULL || size == 0) + return (OF_getproplen(node, propname)); + + return (OF_getencprop(node, propname, propvalue, size)); +} + static struct resource * simplebus_alloc_resource(device_t bus, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) Index: sys/kern/bus_if.m =================================================================== --- sys/kern/bus_if.m +++ sys/kern/bus_if.m @@ -88,6 +88,13 @@ *newstart = start; return (0); } + + static ssize_t + null_get_property(device_t dev, device_t child, const char *propname, + void *propvalue, size_t size) + { + return (-1); + } }; /** @@ -924,3 +931,27 @@ device_t _child; int _flags; }; + +/** + * @brief Gets child's specific property + * + * The bus_get_property can be used to access device + * specific properties stored on the bus. If _propvalue + * is NULL or _size is 0, then method only returns size + * of the property. + * + * @param _dev the bus device + * @param _child the child device + * @param _propname property name + * @param _propvalue property value destination + * @param _size property value size + * + * @returns size of property if successful otherwise -1 + */ +METHOD ssize_t get_property { + device_t _dev; + device_t _child; + const char *_propname; + void *_propvalue; + size_t _size; +} DEFAULT null_get_property; Index: sys/kern/subr_bus.c =================================================================== --- sys/kern/subr_bus.c +++ sys/kern/subr_bus.c @@ -2708,6 +2708,14 @@ dev->flags &= ~DF_QUIET; } +ssize_t +device_get_property(device_t dev, const char *prop, void *val, size_t sz) +{ + device_t bus = device_get_parent(dev); + + return (BUS_GET_PROPERTY(bus, dev, prop, val, sz)); +} + /** * @brief Return non-zero if the DF_QUIET_CHIDLREN flag is set on the device */ Index: sys/sys/bus.h =================================================================== --- sys/sys/bus.h +++ sys/sys/bus.h @@ -631,6 +631,13 @@ int device_shutdown(device_t dev); void device_unbusy(device_t dev); void device_verbose(device_t dev); +ssize_t device_get_property(device_t dev, const char *prop, void *val, size_t sz); + +static __inline bool +device_has_property(device_t dev, const char *prop) +{ + return (device_get_property(dev, prop, NULL, 0) >= 0); +} /* * Access functions for devclass.