device_calls revision 1.4
11.4Sthorpej$NetBSD: device_calls,v 1.4 2025/10/04 01:12:15 thorpej Exp $ 21.1Sthorpej 31.1Sthorpej/*- 41.4Sthorpej * Copyright (c) 2021, 2025 The NetBSD Foundation, Inc. 51.1Sthorpej * All rights reserved. 61.1Sthorpej * 71.1Sthorpej * This code is derived from software contributed to The NetBSD Foundation 81.1Sthorpej * by Jason R. Thorpe. 91.1Sthorpej * 101.1Sthorpej * Redistribution and use in source and binary forms, with or without 111.1Sthorpej * modification, are permitted provided that the following conditions 121.1Sthorpej * are met: 131.1Sthorpej * 1. Redistributions of source code must retain the above copyright 141.1Sthorpej * notice, this list of conditions and the following disclaimer. 151.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 161.1Sthorpej * notice, this list of conditions and the following disclaimer in the 171.1Sthorpej * documentation and/or other materials provided with the distribution. 181.1Sthorpej * 191.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 301.1Sthorpej */ 311.1Sthorpej 321.1Sthorpej/* 331.1Sthorpej * Device calls used by the device autoconfiguration subsystem 341.1Sthorpej */ 351.1Sthorpej 361.1Sthorpejsubsystem device; 371.1Sthorpej 381.1Sthorpej/* 391.1Sthorpej * device-enumerate-children 401.1Sthorpej * 411.1Sthorpej * Enumerates the direct children of a device, invoking the callback for 421.1Sthorpej * each one. The callback is passed the devhandle_t corresponding to the 431.1Sthorpej * child device, as well as a user-supplied argument. If the callback 441.1Sthorpej * returns true, then enumeration continues. If the callback returns false, 451.1Sthorpej * enumeration is stopped. 461.1Sthorpej */ 471.1Sthorpejdevice-enumerate-children { 481.1Sthorpej bool (*callback)(device_t, devhandle_t, void *); 491.1Sthorpej void * callback_arg; 501.1Sthorpej}; 511.2Sthorpej 521.2Sthorpej/* 531.3Sthorpej * device-register 541.3Sthorpej * 551.3Sthorpej * This is a hook for the platform device tree implementation to 561.3Sthorpej * inspect or take action upon a new device before the machine- 571.3Sthorpej * specific device_register() function is called. 581.3Sthorpej */ 591.3Sthorpejdevice-register { 601.3Sthorpej void * aux; /* IN */ 611.3Sthorpej}; 621.3Sthorpej 631.3Sthorpej/* 641.2Sthorpej * device-is-system-todr 651.2Sthorpej * 661.2Sthorpej * This is a filter that is considered when attaching the system TODR / RTC. 671.2Sthorpej * For systems which may have multiple TODR / RTC devices, the platform 681.2Sthorpej * device tree may have information about which is authoritative. This is 691.2Sthorpej * an optional method, and in its absence, the system will proceed as if 701.2Sthorpej * the answer was "yes". 711.2Sthorpej */ 721.2Sthorpejdevice-is-system-todr { 731.2Sthorpej bool result; /* OUT */ 741.2Sthorpej}; 751.4Sthorpej 761.4Sthorpej/* 771.4Sthorpej * device-get-property 781.4Sthorpej * 791.4Sthorpej * Gets the specified property (and its attributes) and copies it into 801.4Sthorpej * the caller-provided buffer, in addtion to returning the property's 811.4Sthorpej * attributes: 821.4Sthorpej * ==> propsize The native size of the property in the backing 831.4Sthorpej * store. 841.4Sthorpej * ==> encoding The native encoding of numbers in the backing store, 851.4Sthorpej * _BIG_ENDIAN or _LITTLE_ENDIAN. 861.4Sthorpej * ==> type The native type of the property in the backing store. 871.4Sthorpej * If the backing store does not have a native typing 881.4Sthorpej * system, then it may return PROP_TYPE_UNKNOWN for this 891.4Sthorpej * attribute. 901.4Sthorpej * 911.4Sthorpej * If the requested property type is PROP_TYPE_UNKNOWN, then the pointer to 921.4Sthorpej * and size of the caller-provided buffer shall be NULL and 0, respectively. 931.4Sthorpej * Implementations may assert this. In this instance, the caller is requesting 941.4Sthorpej * only the property's attributes. 951.4Sthorpej * 961.4Sthorpej * Conversely, if the requested property type is not PROP_TYPE_UNKNOWN, 971.4Sthorpej * then the pointer to the caller-provided buffer shall not be NULL and 981.4Sthorpej * the size shall not be 0, and the type will be one of the four listed 991.4Sthorpej * below. Implementation may assert this. 1001.4Sthorpej * 1011.4Sthorpej * If the requested property type is PROP_TYPE_DATA or PROP_TYPE_STRING, 1021.4Sthorpej * then the following rules apply: 1031.4Sthorpej * ==> If the caller-provided buffer is insufficiently large to hold the 1041.4Sthorpej * entire property, the "propsize" output must be set to reflect the 1051.4Sthorpej * required buffer size and the EFBIG error returned. In this situation, 1061.4Sthorpej * it is unspecified whether or not any data is copied into the caller- 1071.4Sthorpej * provided buffer. 1081.4Sthorpej * ==> If the backing store has a native STRING type, then the implementation 1091.4Sthorpej * must allow STRING properties to be fetched as DATA objects. 1101.4Sthorpej * 1111.4Sthorpej * If the requested type is PROP_TYPE_STRING, the property value in returned 1121.4Sthorpej * in the caller-provided buffer must be NUL-terminated. 1131.4Sthorpej * 1141.4Sthorpej * If the requested property type is PROP_TYPE_NUMBER, then the following 1151.4Sthorpej * rules apply: 1161.4Sthorpej * ==> The size of the caller-provided buffer shall be sizeof(uint64_t) and 1171.4Sthorpej * will have alignment suitable for the type. Implementations may assert 1181.4Sthorpej * this. 1191.4Sthorpej * ==> The implementation must silently zero-extend whatever value is in the 1201.4Sthorpej * backing store to a uint64_t and return that value. The front-end 1211.4Sthorpej * will perform any type conversions, including range checks, requested 1221.4Sthorpej * by the caller. 1231.4Sthorpej * ==> The returned "propsize" must reflect an accurate representation of 1241.4Sthorpej * the size of the property in the backing store; this information is 1251.4Sthorpej * is used in type conversion. 1261.4Sthorpej * ==> If the backing store's number encoding differs from the native number 1271.4Sthorpej * encoding, then the backing store shall convert the number to the native 1281.4Sthorpej * encoding. 1291.4Sthorpej * 1301.4Sthorpej * If the requested property type is PROP_TYPE_BOOL, then the following 1311.4Sthorpej * rules apply: 1321.4Sthorpej * ==> The size of the caller-provided buffer shall be sizeof(bool) and will 1331.4Sthorpej * have alignment suitable for the type. Implementations may assert this. 1341.4Sthorpej * ==> If the implementation's backing store does not provide a native boolean 1351.4Sthorpej * type, then the implementation may use backing-store-specific conventions 1361.4Sthorpej * to infer bool-ness of the property. If, in this situation, the property 1371.4Sthorpej * does not match the backing store's boolean conventions, then the 1381.4Sthorpej * implementation must return EFTYPE; the system will then use its own 1391.4Sthorpej * default policy as a fallback. 1401.4Sthorpej * 1411.4Sthorpej * Call returns 0 if successful, or an error code upon failure: 1421.4Sthorpej * 1431.4Sthorpej * ENOENT The property does not exist. 1441.4Sthorpej * 1451.4Sthorpej * EFBIG The property is too large to fit in the provided buffer. 1461.4Sthorpej * The "propsize" output is set to reflect the required 1471.4Sthorpej * buffer size (for DATA and STRING properties). 1481.4Sthorpej * 1491.4Sthorpej * EFTYPE The property is a different type than what was requested. 1501.4Sthorpej * 1511.4Sthorpej * EINVAL The arguments provided to the call are invalid in a way 1521.4Sthorpej * not covered by one of the above error cases. 1531.4Sthorpej * 1541.4Sthorpej * EIO An input/output error to the backing store occurred. 1551.4Sthorpej * 1561.4Sthorpej * The "flags" field of the arguments structure is reserved for future 1571.4Sthorpej * expansion. 1581.4Sthorpej * 1591.4Sthorpej * The "dev" argument to the device-get-property call may be NULL. 1601.4Sthorpej */ 1611.4Sthorpejdevice-get-property { 1621.4Sthorpej const char * prop; /* IN */ 1631.4Sthorpej void * buf; /* IN */ 1641.4Sthorpej size_t buflen; /* IN */ 1651.4Sthorpej prop_type_t reqtype; /* IN */ 1661.4Sthorpej int flags; /* IN */ 1671.4Sthorpej ssize_t propsize; /* OUT */ 1681.4Sthorpej int encoding; /* OUT */ 1691.4Sthorpej prop_type_t type; /* OUT */ 1701.4Sthorpej}; 171