ofw_if.m (41fe50f5deab9062cdf5915541105e47679ba571) | ofw_if.m (481d6b549b172c5faea8d3b94de5a5b0ab1f5f9a) |
---|---|
1#- 2# Copyright (c) 2008 Nathan Whitehorn 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27# 28 29#include <dev/ofw/openfirm.h> 30#include <dev/ofw/ofwvar.h> 31 32/** 33 * @defgroup OFW ofw - KObj methods for Open Firmware RTAS implementations 34 * @brief A set of methods to implement the Open Firmware client side interface. | 1#- 2# Copyright (c) 2008 Nathan Whitehorn 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27# 28 29#include <dev/ofw/openfirm.h> 30#include <dev/ofw/ofwvar.h> 31 32/** 33 * @defgroup OFW ofw - KObj methods for Open Firmware RTAS implementations 34 * @brief A set of methods to implement the Open Firmware client side interface. |
35 *@{ | 35 * @{ |
36 */ 37 38INTERFACE ofw; 39 40/** 41 * @brief Initialize OFW client interface 42 * 43 * @param _cookie A handle to the client interface, generally the OF 44 * callback routine. 45 */ 46METHOD void init { 47 ofw_t _ofw; 48 void *_cookie; 49}; 50 51/** | 36 */ 37 38INTERFACE ofw; 39 40/** 41 * @brief Initialize OFW client interface 42 * 43 * @param _cookie A handle to the client interface, generally the OF 44 * callback routine. 45 */ 46METHOD void init { 47 ofw_t _ofw; 48 void *_cookie; 49}; 50 51/** |
52 * @brief Return next sibling of node | 52 * @brief Return next sibling of node. |
53 * 54 * @param _node Selected node 55 */ 56METHOD phandle_t peer { 57 ofw_t _ofw; | 53 * 54 * @param _node Selected node 55 */ 56METHOD phandle_t peer { 57 ofw_t _ofw; |
58 phandle_t _node; | 58 phandle_t _node; |
59}; 60 61/** | 59}; 60 61/** |
62 * @brief Return parent of node | 62 * @brief Return parent of node. |
63 * 64 * @param _node Selected node 65 */ 66METHOD phandle_t parent { 67 ofw_t _ofw; | 63 * 64 * @param _node Selected node 65 */ 66METHOD phandle_t parent { 67 ofw_t _ofw; |
68 phandle_t _node; | 68 phandle_t _node; |
69}; 70 71/** | 69}; 70 71/** |
72 * @brief Return first child of node | 72 * @brief Return first child of node. |
73 * 74 * @param _node Selected node 75 */ 76METHOD phandle_t child { 77 ofw_t _ofw; | 73 * 74 * @param _node Selected node 75 */ 76METHOD phandle_t child { 77 ofw_t _ofw; |
78 phandle_t _node; | 78 phandle_t _node; |
79}; 80 81/** | 79}; 80 81/** |
82 * @brief Return package corresponding to instance | 82 * @brief Return package corresponding to instance. |
83 * 84 * @param _handle Selected instance 85 */ 86METHOD phandle_t instance_to_package { 87 ofw_t _ofw; | 83 * 84 * @param _handle Selected instance 85 */ 86METHOD phandle_t instance_to_package { 87 ofw_t _ofw; |
88 ihandle_t _handle; | 88 ihandle_t _handle; |
89}; 90 91/** | 89}; 90 91/** |
92 * @brief Return length of node property | 92 * @brief Return length of node property. |
93 * 94 * @param _node Selected node 95 * @param _prop Property name 96 */ 97METHOD ssize_t getproplen { 98 ofw_t _ofw; | 93 * 94 * @param _node Selected node 95 * @param _prop Property name 96 */ 97METHOD ssize_t getproplen { 98 ofw_t _ofw; |
99 phandle_t _node; 100 const char *_prop; | 99 phandle_t _node; 100 const char *_prop; |
101}; 102 103/** | 101}; 102 103/** |
104 * @brief Read node property | 104 * @brief Read node property. |
105 * 106 * @param _node Selected node 107 * @param _prop Property name 108 * @param _buf Pointer to buffer 109 * @param _size Size of buffer 110 */ 111METHOD ssize_t getprop { 112 ofw_t _ofw; | 105 * 106 * @param _node Selected node 107 * @param _prop Property name 108 * @param _buf Pointer to buffer 109 * @param _size Size of buffer 110 */ 111METHOD ssize_t getprop { 112 ofw_t _ofw; |
113 phandle_t _node; | 113 phandle_t _node; |
114 const char *_prop; 115 void *_buf; 116 size_t _size; 117}; 118 119/** | 114 const char *_prop; 115 void *_buf; 116 size_t _size; 117}; 118 119/** |
120 * @brief Get next property name | 120 * @brief Get next property name. |
121 * 122 * @param _node Selected node 123 * @param _prop Current property name 124 * @param _buf Buffer for next property name 125 * @param _size Size of buffer 126 */ 127METHOD int nextprop { 128 ofw_t _ofw; | 121 * 122 * @param _node Selected node 123 * @param _prop Current property name 124 * @param _buf Buffer for next property name 125 * @param _size Size of buffer 126 */ 127METHOD int nextprop { 128 ofw_t _ofw; |
129 phandle_t _node; | 129 phandle_t _node; |
130 const char *_prop; | 130 const char *_prop; |
131 char *_buf; | 131 char *_buf; |
132 size_t _size; 133}; 134 135/** | 132 size_t _size; 133}; 134 135/** |
136 * @brief Set property | 136 * @brief Set property. |
137 * 138 * @param _node Selected node 139 * @param _prop Property name 140 * @param _buf Value to set 141 * @param _size Size of buffer 142 */ 143METHOD int setprop { 144 ofw_t _ofw; | 137 * 138 * @param _node Selected node 139 * @param _prop Property name 140 * @param _buf Value to set 141 * @param _size Size of buffer 142 */ 143METHOD int setprop { 144 ofw_t _ofw; |
145 phandle_t _node; 146 const char *_prop; | 145 phandle_t _node; 146 const char *_prop; |
147 const void *_buf; 148 size_t _size; 149}; 150 151/** | 147 const void *_buf; 148 size_t _size; 149}; 150 151/** |
152 * @brief Canonicalize path | 152 * @brief Canonicalize path. |
153 * 154 * @param _path Path to canonicalize 155 * @param _buf Buffer for canonicalized path 156 * @param _size Size of buffer 157 */ 158METHOD ssize_t canon { 159 ofw_t _ofw; 160 const char *_path; 161 char *_buf; 162 size_t _size; 163}; 164 165/** | 153 * 154 * @param _path Path to canonicalize 155 * @param _buf Buffer for canonicalized path 156 * @param _size Size of buffer 157 */ 158METHOD ssize_t canon { 159 ofw_t _ofw; 160 const char *_path; 161 char *_buf; 162 size_t _size; 163}; 164 165/** |
166 * @brief Return phandle for named device | 166 * @brief Return phandle for named device. |
167 * 168 * @param _path Device path 169 */ 170METHOD phandle_t finddevice { 171 ofw_t _ofw; | 167 * 168 * @param _path Device path 169 */ 170METHOD phandle_t finddevice { 171 ofw_t _ofw; |
172 const char *_path; | 172 const char *_path; |
173}; 174 175/** | 173}; 174 175/** |
176 * @brief Return path for node instance | 176 * @brief Return path for node instance. |
177 * 178 * @param _handle Instance handle 179 * @param _path Buffer for path 180 * @param _size Size of buffer 181 */ 182METHOD ssize_t instance_to_path { 183 ofw_t _ofw; 184 ihandle_t _handle; | 177 * 178 * @param _handle Instance handle 179 * @param _path Buffer for path 180 * @param _size Size of buffer 181 */ 182METHOD ssize_t instance_to_path { 183 ofw_t _ofw; 184 ihandle_t _handle; |
185 char *_path; | 185 char *_path; |
186 size_t _size; 187}; 188 189/** | 186 size_t _size; 187}; 188 189/** |
190 * @brief Return path for node | 190 * @brief Return path for node. |
191 * 192 * @param _node Package node 193 * @param _path Buffer for path 194 * @param _size Size of buffer 195 */ 196METHOD ssize_t package_to_path { 197 ofw_t _ofw; 198 phandle_t _node; | 191 * 192 * @param _node Package node 193 * @param _path Buffer for path 194 * @param _size Size of buffer 195 */ 196METHOD ssize_t package_to_path { 197 ofw_t _ofw; 198 phandle_t _node; |
199 char *_path; | 199 char *_path; |
200 size_t _size; 201}; 202 | 200 size_t _size; 201}; 202 |
203 | |
204# Methods for OF method calls (optional) 205 206/** 207 * @brief Test to see if a service exists. 208 * 209 * @param _name name of the service 210 */ 211METHOD int test { 212 ofw_t _ofw; 213 const char *_name; 214}; 215 216/** | 203# Methods for OF method calls (optional) 204 205/** 206 * @brief Test to see if a service exists. 207 * 208 * @param _name name of the service 209 */ 210METHOD int test { 211 ofw_t _ofw; 212 const char *_name; 213}; 214 215/** |
217 * @brief Call method belonging to an instance handle | 216 * @brief Call method belonging to an instance handle. |
218 * 219 * @param _instance Instance handle 220 * @param _method Method name 221 * @param _nargs Number of arguments 222 * @param _nreturns Number of return values 223 * @param _args_and_returns Values for arguments, followed by returns 224 */ 225 226METHOD int call_method { 227 ofw_t _ofw; 228 ihandle_t _instance; 229 const char *_method; 230 int _nargs; | 217 * 218 * @param _instance Instance handle 219 * @param _method Method name 220 * @param _nargs Number of arguments 221 * @param _nreturns Number of return values 222 * @param _args_and_returns Values for arguments, followed by returns 223 */ 224 225METHOD int call_method { 226 ofw_t _ofw; 227 ihandle_t _instance; 228 const char *_method; 229 int _nargs; |
231 int _nreturns; | 230 int _nreturns; |
232 233 unsigned long *_args_and_returns; 234}; 235 236/** | 231 232 unsigned long *_args_and_returns; 233}; 234 235/** |
237 * @brief Interpret a forth command | 236 * @brief Interpret a forth command. |
238 * 239 * @param _cmd Command 240 * @param _nreturns Number of return values 241 * @param _returns Values for returns 242 */ 243 244METHOD int interpret { 245 ofw_t _ofw; 246 const char *_cmd; | 237 * 238 * @param _cmd Command 239 * @param _nreturns Number of return values 240 * @param _returns Values for returns 241 */ 242 243METHOD int interpret { 244 ofw_t _ofw; 245 const char *_cmd; |
247 int _nreturns; | 246 int _nreturns; |
248 unsigned long *_returns; 249}; 250 251# Device I/O Functions (optional) 252 253/** | 247 unsigned long *_returns; 248}; 249 250# Device I/O Functions (optional) 251 252/** |
254 * @brief Open node, returning instance handle | 253 * @brief Open node, returning instance handle. |
255 * 256 * @param _path Path to node 257 */ 258METHOD ihandle_t open { 259 ofw_t _ofw; 260 const char *_path; 261} 262 263/** | 254 * 255 * @param _path Path to node 256 */ 257METHOD ihandle_t open { 258 ofw_t _ofw; 259 const char *_path; 260} 261 262/** |
264 * @brief Close node instance | 263 * @brief Close node instance. |
265 * 266 * @param _instance Instance to close 267 */ 268METHOD void close { 269 ofw_t _ofw; 270 ihandle_t _instance; 271} 272 273/** | 264 * 265 * @param _instance Instance to close 266 */ 267METHOD void close { 268 ofw_t _ofw; 269 ihandle_t _instance; 270} 271 272/** |
274 * @brief Read from device | 273 * @brief Read from device. |
275 * 276 * @param _instance Device instance 277 * @param _buf Buffer to read to 278 * @param _size Size of buffer 279 */ 280METHOD ssize_t read { 281 ofw_t _ofw; 282 ihandle_t _instance; 283 void *_buf; 284 size_t size; 285} 286 287/** | 274 * 275 * @param _instance Device instance 276 * @param _buf Buffer to read to 277 * @param _size Size of buffer 278 */ 279METHOD ssize_t read { 280 ofw_t _ofw; 281 ihandle_t _instance; 282 void *_buf; 283 size_t size; 284} 285 286/** |
288 * @brief Write to device | 287 * @brief Write to device. |
289 * 290 * @param _instance Device instance 291 * @param _buf Buffer to write from 292 * @param _size Size of buffer 293 */ 294METHOD ssize_t write { 295 ofw_t _ofw; 296 ihandle_t _instance; 297 const void *_buf; 298 size_t size; 299} 300 301/** | 288 * 289 * @param _instance Device instance 290 * @param _buf Buffer to write from 291 * @param _size Size of buffer 292 */ 293METHOD ssize_t write { 294 ofw_t _ofw; 295 ihandle_t _instance; 296 const void *_buf; 297 size_t size; 298} 299 300/** |
302 * @brief Seek device | 301 * @brief Seek device. |
303 * 304 * @param _instance Device instance 305 * @param _off Offset to which to seek 306 */ 307METHOD int seek { 308 ofw_t _ofw; 309 ihandle_t _instance; 310 uint64_t _off; 311} 312 313# Open Firmware memory management 314 315/** | 302 * 303 * @param _instance Device instance 304 * @param _off Offset to which to seek 305 */ 306METHOD int seek { 307 ofw_t _ofw; 308 ihandle_t _instance; 309 uint64_t _off; 310} 311 312# Open Firmware memory management 313 314/** |
316 * @brief Claim virtual memory | 315 * @brief Claim virtual memory. |
317 * 318 * @param _addr Requested memory location (NULL for first available) 319 * @param _size Requested size in bytes 320 * @param _align Requested alignment 321 */ 322METHOD caddr_t claim { 323 ofw_t _ofw; 324 void *_addr; 325 size_t _size; 326 u_int _align; 327} 328 329/** | 316 * 317 * @param _addr Requested memory location (NULL for first available) 318 * @param _size Requested size in bytes 319 * @param _align Requested alignment 320 */ 321METHOD caddr_t claim { 322 ofw_t _ofw; 323 void *_addr; 324 size_t _size; 325 u_int _align; 326} 327 328/** |
330 * @brief Release virtual memory | 329 * @brief Release virtual memory. |
331 * 332 * @param _addr Memory location 333 * @param _size Size in bytes 334 */ 335METHOD void release { 336 ofw_t _ofw; 337 void *_addr; 338 size_t _size; 339}; 340 341# Commands for returning control to the firmware 342 343/** | 330 * 331 * @param _addr Memory location 332 * @param _size Size in bytes 333 */ 334METHOD void release { 335 ofw_t _ofw; 336 void *_addr; 337 size_t _size; 338}; 339 340# Commands for returning control to the firmware 341 342/** |
344 * @brief Temporarily return control to firmware | 343 * @brief Temporarily return control to firmware. |
345 */ 346METHOD void enter { 347 ofw_t _ofw; 348}; 349 350/** | 344 */ 345METHOD void enter { 346 ofw_t _ofw; 347}; 348 349/** |
351 * @brief Halt and return control to firmware | 350 * @brief Halt and return control to firmware. |
352 */ 353METHOD void exit { 354 ofw_t _ofw; 355}; | 351 */ 352METHOD void exit { 353 ofw_t _ofw; 354}; |
356 357 | |