1 1.4 thorpej $NetBSD: device_calls,v 1.4 2025/10/04 01:12:15 thorpej Exp $ 2 1.1 thorpej 3 1.1 thorpej /*- 4 1.4 thorpej * Copyright (c) 2021, 2025 The NetBSD Foundation, Inc. 5 1.1 thorpej * All rights reserved. 6 1.1 thorpej * 7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.1 thorpej * by Jason R. Thorpe. 9 1.1 thorpej * 10 1.1 thorpej * Redistribution and use in source and binary forms, with or without 11 1.1 thorpej * modification, are permitted provided that the following conditions 12 1.1 thorpej * are met: 13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright 14 1.1 thorpej * notice, this list of conditions and the following disclaimer. 15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the 17 1.1 thorpej * documentation and/or other materials provided with the distribution. 18 1.1 thorpej * 19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.1 thorpej */ 31 1.1 thorpej 32 1.1 thorpej /* 33 1.1 thorpej * Device calls used by the device autoconfiguration subsystem 34 1.1 thorpej */ 35 1.1 thorpej 36 1.1 thorpej subsystem device; 37 1.1 thorpej 38 1.1 thorpej /* 39 1.1 thorpej * device-enumerate-children 40 1.1 thorpej * 41 1.1 thorpej * Enumerates the direct children of a device, invoking the callback for 42 1.1 thorpej * each one. The callback is passed the devhandle_t corresponding to the 43 1.1 thorpej * child device, as well as a user-supplied argument. If the callback 44 1.1 thorpej * returns true, then enumeration continues. If the callback returns false, 45 1.1 thorpej * enumeration is stopped. 46 1.1 thorpej */ 47 1.1 thorpej device-enumerate-children { 48 1.1 thorpej bool (*callback)(device_t, devhandle_t, void *); 49 1.1 thorpej void * callback_arg; 50 1.1 thorpej }; 51 1.2 thorpej 52 1.2 thorpej /* 53 1.3 thorpej * device-register 54 1.3 thorpej * 55 1.3 thorpej * This is a hook for the platform device tree implementation to 56 1.3 thorpej * inspect or take action upon a new device before the machine- 57 1.3 thorpej * specific device_register() function is called. 58 1.3 thorpej */ 59 1.3 thorpej device-register { 60 1.3 thorpej void * aux; /* IN */ 61 1.3 thorpej }; 62 1.3 thorpej 63 1.3 thorpej /* 64 1.2 thorpej * device-is-system-todr 65 1.2 thorpej * 66 1.2 thorpej * This is a filter that is considered when attaching the system TODR / RTC. 67 1.2 thorpej * For systems which may have multiple TODR / RTC devices, the platform 68 1.2 thorpej * device tree may have information about which is authoritative. This is 69 1.2 thorpej * an optional method, and in its absence, the system will proceed as if 70 1.2 thorpej * the answer was "yes". 71 1.2 thorpej */ 72 1.2 thorpej device-is-system-todr { 73 1.2 thorpej bool result; /* OUT */ 74 1.2 thorpej }; 75 1.4 thorpej 76 1.4 thorpej /* 77 1.4 thorpej * device-get-property 78 1.4 thorpej * 79 1.4 thorpej * Gets the specified property (and its attributes) and copies it into 80 1.4 thorpej * the caller-provided buffer, in addtion to returning the property's 81 1.4 thorpej * attributes: 82 1.4 thorpej * ==> propsize The native size of the property in the backing 83 1.4 thorpej * store. 84 1.4 thorpej * ==> encoding The native encoding of numbers in the backing store, 85 1.4 thorpej * _BIG_ENDIAN or _LITTLE_ENDIAN. 86 1.4 thorpej * ==> type The native type of the property in the backing store. 87 1.4 thorpej * If the backing store does not have a native typing 88 1.4 thorpej * system, then it may return PROP_TYPE_UNKNOWN for this 89 1.4 thorpej * attribute. 90 1.4 thorpej * 91 1.4 thorpej * If the requested property type is PROP_TYPE_UNKNOWN, then the pointer to 92 1.4 thorpej * and size of the caller-provided buffer shall be NULL and 0, respectively. 93 1.4 thorpej * Implementations may assert this. In this instance, the caller is requesting 94 1.4 thorpej * only the property's attributes. 95 1.4 thorpej * 96 1.4 thorpej * Conversely, if the requested property type is not PROP_TYPE_UNKNOWN, 97 1.4 thorpej * then the pointer to the caller-provided buffer shall not be NULL and 98 1.4 thorpej * the size shall not be 0, and the type will be one of the four listed 99 1.4 thorpej * below. Implementation may assert this. 100 1.4 thorpej * 101 1.4 thorpej * If the requested property type is PROP_TYPE_DATA or PROP_TYPE_STRING, 102 1.4 thorpej * then the following rules apply: 103 1.4 thorpej * ==> If the caller-provided buffer is insufficiently large to hold the 104 1.4 thorpej * entire property, the "propsize" output must be set to reflect the 105 1.4 thorpej * required buffer size and the EFBIG error returned. In this situation, 106 1.4 thorpej * it is unspecified whether or not any data is copied into the caller- 107 1.4 thorpej * provided buffer. 108 1.4 thorpej * ==> If the backing store has a native STRING type, then the implementation 109 1.4 thorpej * must allow STRING properties to be fetched as DATA objects. 110 1.4 thorpej * 111 1.4 thorpej * If the requested type is PROP_TYPE_STRING, the property value in returned 112 1.4 thorpej * in the caller-provided buffer must be NUL-terminated. 113 1.4 thorpej * 114 1.4 thorpej * If the requested property type is PROP_TYPE_NUMBER, then the following 115 1.4 thorpej * rules apply: 116 1.4 thorpej * ==> The size of the caller-provided buffer shall be sizeof(uint64_t) and 117 1.4 thorpej * will have alignment suitable for the type. Implementations may assert 118 1.4 thorpej * this. 119 1.4 thorpej * ==> The implementation must silently zero-extend whatever value is in the 120 1.4 thorpej * backing store to a uint64_t and return that value. The front-end 121 1.4 thorpej * will perform any type conversions, including range checks, requested 122 1.4 thorpej * by the caller. 123 1.4 thorpej * ==> The returned "propsize" must reflect an accurate representation of 124 1.4 thorpej * the size of the property in the backing store; this information is 125 1.4 thorpej * is used in type conversion. 126 1.4 thorpej * ==> If the backing store's number encoding differs from the native number 127 1.4 thorpej * encoding, then the backing store shall convert the number to the native 128 1.4 thorpej * encoding. 129 1.4 thorpej * 130 1.4 thorpej * If the requested property type is PROP_TYPE_BOOL, then the following 131 1.4 thorpej * rules apply: 132 1.4 thorpej * ==> The size of the caller-provided buffer shall be sizeof(bool) and will 133 1.4 thorpej * have alignment suitable for the type. Implementations may assert this. 134 1.4 thorpej * ==> If the implementation's backing store does not provide a native boolean 135 1.4 thorpej * type, then the implementation may use backing-store-specific conventions 136 1.4 thorpej * to infer bool-ness of the property. If, in this situation, the property 137 1.4 thorpej * does not match the backing store's boolean conventions, then the 138 1.4 thorpej * implementation must return EFTYPE; the system will then use its own 139 1.4 thorpej * default policy as a fallback. 140 1.4 thorpej * 141 1.4 thorpej * Call returns 0 if successful, or an error code upon failure: 142 1.4 thorpej * 143 1.4 thorpej * ENOENT The property does not exist. 144 1.4 thorpej * 145 1.4 thorpej * EFBIG The property is too large to fit in the provided buffer. 146 1.4 thorpej * The "propsize" output is set to reflect the required 147 1.4 thorpej * buffer size (for DATA and STRING properties). 148 1.4 thorpej * 149 1.4 thorpej * EFTYPE The property is a different type than what was requested. 150 1.4 thorpej * 151 1.4 thorpej * EINVAL The arguments provided to the call are invalid in a way 152 1.4 thorpej * not covered by one of the above error cases. 153 1.4 thorpej * 154 1.4 thorpej * EIO An input/output error to the backing store occurred. 155 1.4 thorpej * 156 1.4 thorpej * The "flags" field of the arguments structure is reserved for future 157 1.4 thorpej * expansion. 158 1.4 thorpej * 159 1.4 thorpej * The "dev" argument to the device-get-property call may be NULL. 160 1.4 thorpej */ 161 1.4 thorpej device-get-property { 162 1.4 thorpej const char * prop; /* IN */ 163 1.4 thorpej void * buf; /* IN */ 164 1.4 thorpej size_t buflen; /* IN */ 165 1.4 thorpej prop_type_t reqtype; /* IN */ 166 1.4 thorpej int flags; /* IN */ 167 1.4 thorpej ssize_t propsize; /* OUT */ 168 1.4 thorpej int encoding; /* OUT */ 169 1.4 thorpej prop_type_t type; /* OUT */ 170 1.4 thorpej }; 171