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