head 1.4; access; symbols netbsd-10-2-RELEASE:1.1 netbsd-11-0-RELEASE:1.1 netbsd-11-0-RC7:1.1 netbsd-11-0-RC6:1.1 netbsd-11-0-RC5:1.1 netbsd-11-0-RC4:1.1 netbsd-11-0-RC3:1.1 netbsd-11-0-RC2:1.1 netbsd-11-0-RC1:1.1 perseant-exfatfs-base-20250801:1.1 netbsd-11:1.1.0.12 netbsd-11-base:1.1 netbsd-10-1-RELEASE:1.1 perseant-exfatfs-base-20240630:1.1 perseant-exfatfs:1.1.0.10 perseant-exfatfs-base:1.1 netbsd-10-0-RELEASE:1.1 netbsd-10-0-RC6:1.1 netbsd-10-0-RC5:1.1 netbsd-10-0-RC4:1.1 netbsd-10-0-RC3:1.1 netbsd-10-0-RC2:1.1 thorpej-ifq:1.1.0.8 thorpej-ifq-base:1.1 thorpej-altq-separation:1.1.0.6 thorpej-altq-separation-base:1.1 netbsd-10-0-RC1:1.1 netbsd-10:1.1.0.4 netbsd-10-base:1.1 bouyer-sunxi-drm:1.1.0.2 bouyer-sunxi-drm-base:1.1; locks; strict; comment @# @; 1.4 date 2025.10.04.01.12.15; author thorpej; state Exp; branches; next 1.3; commitid RELXYBBc4j5GLbdG; 1.3 date 2025.10.03.16.49.07; author thorpej; state Exp; branches; next 1.2; commitid oEZGDXJ7Pcor09dG; 1.2 date 2025.09.08.00.12.21; author thorpej; state Exp; branches; next 1.1; commitid FCAZDq1BDKuKhQ9G; 1.1 date 2021.09.15.17.26.06; author thorpej; state Exp; branches; next ; commitid WGaROyayH4ZRK49D; desc @@ 1.4 log @Add a platform device tree passthrough for device properties. First, the device's properties dictionary is consulted, and if it doesn't have what we're looking for, we go ask the platform device tree. The upshot is that we can g/c (or not have to add) code that duplicates values from the device tree into the properties dictionary (either in something like device_register() or in a driver attachment front-end -- there are multiple example of both in the system, currently), and everyone gets to use a consistent interface (which will, over time, allow more code to de-duplicated). Implement back-ends for ACPI, Sun OpenBoot, and OpenFirmware (including FDT). @ text @$NetBSD: device_calls,v 1.3 2025/10/03 16:49:07 thorpej Exp $ /*- * Copyright (c) 2021, 2025 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * Device calls used by the device autoconfiguration subsystem */ subsystem device; /* * device-enumerate-children * * Enumerates the direct children of a device, invoking the callback for * each one. The callback is passed the devhandle_t corresponding to the * child device, as well as a user-supplied argument. If the callback * returns true, then enumeration continues. If the callback returns false, * enumeration is stopped. */ device-enumerate-children { bool (*callback)(device_t, devhandle_t, void *); void * callback_arg; }; /* * device-register * * This is a hook for the platform device tree implementation to * inspect or take action upon a new device before the machine- * specific device_register() function is called. */ device-register { void * aux; /* IN */ }; /* * device-is-system-todr * * This is a filter that is considered when attaching the system TODR / RTC. * For systems which may have multiple TODR / RTC devices, the platform * device tree may have information about which is authoritative. This is * an optional method, and in its absence, the system will proceed as if * the answer was "yes". */ device-is-system-todr { bool result; /* OUT */ }; /* * device-get-property * * Gets the specified property (and its attributes) and copies it into * the caller-provided buffer, in addtion to returning the property's * attributes: * ==> propsize The native size of the property in the backing * store. * ==> encoding The native encoding of numbers in the backing store, * _BIG_ENDIAN or _LITTLE_ENDIAN. * ==> type The native type of the property in the backing store. * If the backing store does not have a native typing * system, then it may return PROP_TYPE_UNKNOWN for this * attribute. * * If the requested property type is PROP_TYPE_UNKNOWN, then the pointer to * and size of the caller-provided buffer shall be NULL and 0, respectively. * Implementations may assert this. In this instance, the caller is requesting * only the property's attributes. * * Conversely, if the requested property type is not PROP_TYPE_UNKNOWN, * then the pointer to the caller-provided buffer shall not be NULL and * the size shall not be 0, and the type will be one of the four listed * below. Implementation may assert this. * * If the requested property type is PROP_TYPE_DATA or PROP_TYPE_STRING, * then the following rules apply: * ==> If the caller-provided buffer is insufficiently large to hold the * entire property, the "propsize" output must be set to reflect the * required buffer size and the EFBIG error returned. In this situation, * it is unspecified whether or not any data is copied into the caller- * provided buffer. * ==> If the backing store has a native STRING type, then the implementation * must allow STRING properties to be fetched as DATA objects. * * If the requested type is PROP_TYPE_STRING, the property value in returned * in the caller-provided buffer must be NUL-terminated. * * If the requested property type is PROP_TYPE_NUMBER, then the following * rules apply: * ==> The size of the caller-provided buffer shall be sizeof(uint64_t) and * will have alignment suitable for the type. Implementations may assert * this. * ==> The implementation must silently zero-extend whatever value is in the * backing store to a uint64_t and return that value. The front-end * will perform any type conversions, including range checks, requested * by the caller. * ==> The returned "propsize" must reflect an accurate representation of * the size of the property in the backing store; this information is * is used in type conversion. * ==> If the backing store's number encoding differs from the native number * encoding, then the backing store shall convert the number to the native * encoding. * * If the requested property type is PROP_TYPE_BOOL, then the following * rules apply: * ==> The size of the caller-provided buffer shall be sizeof(bool) and will * have alignment suitable for the type. Implementations may assert this. * ==> If the implementation's backing store does not provide a native boolean * type, then the implementation may use backing-store-specific conventions * to infer bool-ness of the property. If, in this situation, the property * does not match the backing store's boolean conventions, then the * implementation must return EFTYPE; the system will then use its own * default policy as a fallback. * * Call returns 0 if successful, or an error code upon failure: * * ENOENT The property does not exist. * * EFBIG The property is too large to fit in the provided buffer. * The "propsize" output is set to reflect the required * buffer size (for DATA and STRING properties). * * EFTYPE The property is a different type than what was requested. * * EINVAL The arguments provided to the call are invalid in a way * not covered by one of the above error cases. * * EIO An input/output error to the backing store occurred. * * The "flags" field of the arguments structure is reserved for future * expansion. * * The "dev" argument to the device-get-property call may be NULL. */ device-get-property { const char * prop; /* IN */ void * buf; /* IN */ size_t buflen; /* IN */ prop_type_t reqtype; /* IN */ int flags; /* IN */ ssize_t propsize; /* OUT */ int encoding; /* OUT */ prop_type_t type; /* OUT */ }; @ 1.3 log @Add a device_register() hook for the platform device tree. For ACPI and OpenFirmware (including FDT), use this to record the firmware path to the device in the "device-path" property. @ text @d1 1 a1 1 $NetBSD: device_calls,v 1.2 2025/09/08 00:12:21 thorpej Exp $ d4 1 a4 1 * Copyright (c) 2021 The NetBSD Foundation, Inc. d75 96 @ 1.2 log @Introduce a device call "device-is-system-todr", which allows the platform device tree to be consulted if there are multiple TODR / RTC devices present on the system; if the call is not supported, the behavior is un-changed: the first TODR device is attached, all others ignored. If the call is supported, devices other than the specified system TODR are skipped. Implement this device call for FDT. kern/59630 @ text @d1 1 a1 1 $NetBSD: device_calls,v 1.1 2021/09/15 17:26:06 thorpej Exp $ d53 11 @ 1.1 log @Device call interface definition files for the "device" and "pci" subsystems. @ text @d1 1 a1 1 $NetBSD$ d51 13 @