14e98e3e1Schristos /* The common simulator framework for GDB, the GNU Debugger. 24e98e3e1Schristos 3*88241920Schristos Copyright 2002-2024 Free Software Foundation, Inc. 44e98e3e1Schristos 54e98e3e1Schristos Contributed by Andrew Cagney and Red Hat. 64e98e3e1Schristos 74e98e3e1Schristos This file is part of GDB. 84e98e3e1Schristos 94e98e3e1Schristos This program is free software; you can redistribute it and/or modify 104e98e3e1Schristos it under the terms of the GNU General Public License as published by 114e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or 124e98e3e1Schristos (at your option) any later version. 134e98e3e1Schristos 144e98e3e1Schristos This program is distributed in the hope that it will be useful, 154e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 164e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 174e98e3e1Schristos GNU General Public License for more details. 184e98e3e1Schristos 194e98e3e1Schristos You should have received a copy of the GNU General Public License 204e98e3e1Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 214e98e3e1Schristos 224e98e3e1Schristos 234e98e3e1Schristos #ifndef HW_PROPERTIES_H 244e98e3e1Schristos #define HW_PROPERTIES_H 254e98e3e1Schristos 264e98e3e1Schristos /* The following are valid property types. The property `array' is 274e98e3e1Schristos for generic untyped data. */ 284e98e3e1Schristos 294e98e3e1Schristos typedef enum 304e98e3e1Schristos { 314e98e3e1Schristos array_property, 324e98e3e1Schristos boolean_property, 334e98e3e1Schristos #if 0 344e98e3e1Schristos ihandle_property, /*runtime*/ 354e98e3e1Schristos #endif 364e98e3e1Schristos integer_property, 374e98e3e1Schristos range_array_property, 384e98e3e1Schristos reg_array_property, 394e98e3e1Schristos string_property, 404e98e3e1Schristos string_array_property, 414e98e3e1Schristos } hw_property_type; 424e98e3e1Schristos 434e98e3e1Schristos struct hw_property 444e98e3e1Schristos { 454e98e3e1Schristos struct hw *owner; 464e98e3e1Schristos const char *name; 474e98e3e1Schristos hw_property_type type; 484e98e3e1Schristos unsigned sizeof_array; 494e98e3e1Schristos const void *array; 504e98e3e1Schristos const struct hw_property *original; 514e98e3e1Schristos object_disposition disposition; 524e98e3e1Schristos }; 534e98e3e1Schristos 544e98e3e1Schristos #define hw_property_owner(p) ((p)->owner + 0) 554e98e3e1Schristos #define hw_property_name(p) ((p)->name + 0) 564e98e3e1Schristos #define hw_property_type(p) ((p)->type + 0) 574e98e3e1Schristos #define hw_property_array(p) ((p)->array + 0) 584e98e3e1Schristos #define hw_property_sizeof_array(p) ((p)->sizeof_array + 0) 594e98e3e1Schristos #define hw_property_original(p) ((p)->original + 0) 604e98e3e1Schristos #define hw_property_disposition(p) ((p)->disposition + 0) 614e98e3e1Schristos 624e98e3e1Schristos 634e98e3e1Schristos /* Find/iterate over properites attached to a device. 644e98e3e1Schristos 654e98e3e1Schristos To iterate over all properties attached to a device, call 664e98e3e1Schristos hw_find_property (.., NULL) and then hw_property_next. */ 674e98e3e1Schristos 684e98e3e1Schristos const struct hw_property *hw_find_property 694e98e3e1Schristos (struct hw *me, 704e98e3e1Schristos const char *property); 714e98e3e1Schristos 724e98e3e1Schristos const struct hw_property *hw_next_property 734e98e3e1Schristos (const struct hw_property *previous); 744e98e3e1Schristos 754e98e3e1Schristos 764e98e3e1Schristos /* Manipulate the properties belonging to a given device. 774e98e3e1Schristos 784e98e3e1Schristos HW_ADD_* will, if the property is not already present, add a 794e98e3e1Schristos property to the device. Adding a property to a device after it has 804e98e3e1Schristos been created is a checked run-time error (use HW_SET_*). 814e98e3e1Schristos 824e98e3e1Schristos HW_SET_* will always update (or create) the property so that it has 834e98e3e1Schristos the specified value. Changing the type of a property is a checked 844e98e3e1Schristos run-time error. 854e98e3e1Schristos 864e98e3e1Schristos FIND returns the specified properties value. It is a checked 874e98e3e1Schristos runtime error to either request a nonexistant property or to 884e98e3e1Schristos request a property using the wrong type. Code locating a property 894e98e3e1Schristos should first check its type (using hw_find_property above) and then 904e98e3e1Schristos obtain its value using the below. 914e98e3e1Schristos 924e98e3e1Schristos Naming convention: 934e98e3e1Schristos 944e98e3e1Schristos void hw_add_<type>_property(struct hw *, const char *, <type>) 954e98e3e1Schristos void hw_add_*_array_property(struct hw *, const char *, const <type>*, int) 964e98e3e1Schristos void hw_set_*_property(struct hw *, const char *, <type>) 974e98e3e1Schristos void hw_set_*_array_property(struct hw *, const char *, const <type>*, int) 984e98e3e1Schristos <type> hw_find_*_property(struct hw *, const char *) 994e98e3e1Schristos int hw_find_*_array_property(struct hw *, const char *, int, <type>*) 1004e98e3e1Schristos 1014e98e3e1Schristos */ 1024e98e3e1Schristos 1034e98e3e1Schristos 1044e98e3e1Schristos void hw_add_array_property 1054e98e3e1Schristos (struct hw *me, 1064e98e3e1Schristos const char *property, 1074e98e3e1Schristos const void *array, 1084e98e3e1Schristos int sizeof_array); 1094e98e3e1Schristos 1104e98e3e1Schristos void hw_set_array_property 1114e98e3e1Schristos (struct hw *me, 1124e98e3e1Schristos const char *property, 1134e98e3e1Schristos const void *array, 1144e98e3e1Schristos int sizeof_array); 1154e98e3e1Schristos 1164e98e3e1Schristos const struct hw_property *hw_find_array_property 1174e98e3e1Schristos (struct hw *me, 1184e98e3e1Schristos const char *property); 1194e98e3e1Schristos 1204e98e3e1Schristos 1214e98e3e1Schristos 1224e98e3e1Schristos void hw_add_boolean_property 1234e98e3e1Schristos (struct hw *me, 1244e98e3e1Schristos const char *property, 1254e98e3e1Schristos int boolean); 1264e98e3e1Schristos 1274e98e3e1Schristos int hw_find_boolean_property 1284e98e3e1Schristos (struct hw *me, 1294e98e3e1Schristos const char *property); 1304e98e3e1Schristos 1314e98e3e1Schristos 1324e98e3e1Schristos 1334e98e3e1Schristos #if 0 1344e98e3e1Schristos typedef struct _ihandle_runtime_property_spec 1354e98e3e1Schristos { 1364e98e3e1Schristos const char *full_path; 1374e98e3e1Schristos } ihandle_runtime_property_spec; 1384e98e3e1Schristos 1394e98e3e1Schristos void hw_add_ihandle_runtime_property 1404e98e3e1Schristos (struct hw *me, 1414e98e3e1Schristos const char *property, 1424e98e3e1Schristos const ihandle_runtime_property_spec *ihandle); 1434e98e3e1Schristos 1444e98e3e1Schristos void hw_find_ihandle_runtime_property 1454e98e3e1Schristos (struct hw *me, 1464e98e3e1Schristos const char *property, 1474e98e3e1Schristos ihandle_runtime_property_spec *ihandle); 1484e98e3e1Schristos 1494e98e3e1Schristos void hw_set_ihandle_property 1504e98e3e1Schristos (struct hw *me, 1514e98e3e1Schristos const char *property, 1524e98e3e1Schristos hw_instance *ihandle); 1534e98e3e1Schristos 1544e98e3e1Schristos hw_instance * hw_find_ihandle_property 1554e98e3e1Schristos (struct hw *me, 1564e98e3e1Schristos const char *property); 1574e98e3e1Schristos #endif 1584e98e3e1Schristos 1594e98e3e1Schristos 1604e98e3e1Schristos void hw_add_integer_property 1614e98e3e1Schristos (struct hw *me, 1624e98e3e1Schristos const char *property, 1634e98e3e1Schristos signed_cell integer); 1644e98e3e1Schristos 1654e98e3e1Schristos signed_cell hw_find_integer_property 1664e98e3e1Schristos (struct hw *me, 1674e98e3e1Schristos const char *property); 1684e98e3e1Schristos 1694e98e3e1Schristos int hw_find_integer_array_property 1704e98e3e1Schristos (struct hw *me, 1714e98e3e1Schristos const char *property, 1724e98e3e1Schristos unsigned index, 1734e98e3e1Schristos signed_cell *integer); 1744e98e3e1Schristos 1754e98e3e1Schristos 1764e98e3e1Schristos 1774e98e3e1Schristos typedef struct _range_property_spec 1784e98e3e1Schristos { 1794e98e3e1Schristos hw_unit child_address; 1804e98e3e1Schristos hw_unit parent_address; 1814e98e3e1Schristos hw_unit size; 1824e98e3e1Schristos } range_property_spec; 1834e98e3e1Schristos 1844e98e3e1Schristos void hw_add_range_array_property 1854e98e3e1Schristos (struct hw *me, 1864e98e3e1Schristos const char *property, 1874e98e3e1Schristos const range_property_spec *ranges, 1884e98e3e1Schristos unsigned nr_ranges); 1894e98e3e1Schristos 1904e98e3e1Schristos int hw_find_range_array_property 1914e98e3e1Schristos (struct hw *me, 1924e98e3e1Schristos const char *property, 1934e98e3e1Schristos unsigned index, 1944e98e3e1Schristos range_property_spec *range); 1954e98e3e1Schristos 1964e98e3e1Schristos 1974e98e3e1Schristos 1984e98e3e1Schristos typedef struct _reg_property_spec 1994e98e3e1Schristos { 2004e98e3e1Schristos hw_unit address; 2014e98e3e1Schristos hw_unit size; 2024e98e3e1Schristos } reg_property_spec; 2034e98e3e1Schristos 2044e98e3e1Schristos void hw_add_reg_array_property 2054e98e3e1Schristos (struct hw *me, 2064e98e3e1Schristos const char *property, 2074e98e3e1Schristos const reg_property_spec *reg, 2084e98e3e1Schristos unsigned nr_regs); 2094e98e3e1Schristos 2104e98e3e1Schristos int hw_find_reg_array_property 2114e98e3e1Schristos (struct hw *me, 2124e98e3e1Schristos const char *property, 2134e98e3e1Schristos unsigned index, 2144e98e3e1Schristos reg_property_spec *reg); 2154e98e3e1Schristos 2164e98e3e1Schristos 2174e98e3e1Schristos 2184e98e3e1Schristos void hw_add_string_property 2194e98e3e1Schristos (struct hw *me, 2204e98e3e1Schristos const char *property, 2214e98e3e1Schristos const char *string); 2224e98e3e1Schristos 2234e98e3e1Schristos const char *hw_find_string_property 2244e98e3e1Schristos (struct hw *me, 2254e98e3e1Schristos const char *property); 2264e98e3e1Schristos 2274e98e3e1Schristos 2284e98e3e1Schristos 2294e98e3e1Schristos typedef const char *string_property_spec; 2304e98e3e1Schristos 2314e98e3e1Schristos void hw_add_string_array_property 2324e98e3e1Schristos (struct hw *me, 2334e98e3e1Schristos const char *property, 2344e98e3e1Schristos const string_property_spec *strings, 2354e98e3e1Schristos unsigned nr_strings); 2364e98e3e1Schristos 2374e98e3e1Schristos int hw_find_string_array_property 2384e98e3e1Schristos (struct hw *me, 2394e98e3e1Schristos const char *property, 2404e98e3e1Schristos unsigned index, 2414e98e3e1Schristos string_property_spec *string); 2424e98e3e1Schristos 2434e98e3e1Schristos 2444e98e3e1Schristos 2454e98e3e1Schristos void hw_add_duplicate_property 2464e98e3e1Schristos (struct hw *me, 2474e98e3e1Schristos const char *property, 2484e98e3e1Schristos const struct hw_property *original); 2494e98e3e1Schristos 2504e98e3e1Schristos #endif 251