1/* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $ */ 2 3/*- 4 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 5 * Copyright (C) 1995, 1996 TooLs GmbH. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by TooLs GmbH. 19 * 4. The name of TooLs GmbH may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33/*- 34 * Copyright (C) 2000 Benno Rice. 35 * All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 46 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR 47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 49 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 50 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 51 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 52 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 53 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 54 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 55 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 */ 57 58#include <sys/cdefs.h>
| 1/* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $ */ 2 3/*- 4 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 5 * Copyright (C) 1995, 1996 TooLs GmbH. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by TooLs GmbH. 19 * 4. The name of TooLs GmbH may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33/*- 34 * Copyright (C) 2000 Benno Rice. 35 * All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 46 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR 47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 49 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 50 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 51 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 52 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 53 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 54 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 55 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 */ 57 58#include <sys/cdefs.h>
|
59__FBSDID("$FreeBSD: head/sys/dev/ofw/openfirm.c 208172 2010-05-16 22:01:43Z nwhitehorn $");
| 59__FBSDID("$FreeBSD: head/sys/dev/ofw/openfirm.c 208614 2010-05-28 10:43:56Z raj $");
|
60
| 60
|
| 61#include "opt_platform.h" 62
|
61#include <sys/param.h> 62#include <sys/kernel.h> 63#include <sys/malloc.h> 64#include <sys/systm.h> 65 66#include <machine/stdarg.h> 67 68#include <dev/ofw/ofwvar.h> 69#include <dev/ofw/openfirm.h> 70 71#include "ofw_if.h" 72 73MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties"); 74 75static ihandle_t stdout; 76 77static ofw_def_t *ofw_def_impl; 78static ofw_t ofw_obj; 79static struct ofw_kobj ofw_kernel_obj; 80static struct kobj_ops ofw_kernel_kops; 81 82/* 83 * OFW install routines. Highest priority wins, equal priority also 84 * overrides allowing last-set to win. 85 */ 86SET_DECLARE(ofw_set, ofw_def_t); 87 88boolean_t 89OF_install(char *name, int prio) 90{ 91 ofw_def_t *ofwp, **ofwpp; 92 static int curr_prio = 0; 93 94 /* 95 * Try and locate the OFW kobj corresponding to the name. 96 */ 97 SET_FOREACH(ofwpp, ofw_set) { 98 ofwp = *ofwpp; 99 100 if (ofwp->name && 101 !strcmp(ofwp->name, name) && 102 prio >= curr_prio) { 103 curr_prio = prio; 104 ofw_def_impl = ofwp; 105 return (TRUE); 106 } 107 } 108 109 return (FALSE); 110} 111 112/* Initializer */
| 63#include <sys/param.h> 64#include <sys/kernel.h> 65#include <sys/malloc.h> 66#include <sys/systm.h> 67 68#include <machine/stdarg.h> 69 70#include <dev/ofw/ofwvar.h> 71#include <dev/ofw/openfirm.h> 72 73#include "ofw_if.h" 74 75MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties"); 76 77static ihandle_t stdout; 78 79static ofw_def_t *ofw_def_impl; 80static ofw_t ofw_obj; 81static struct ofw_kobj ofw_kernel_obj; 82static struct kobj_ops ofw_kernel_kops; 83 84/* 85 * OFW install routines. Highest priority wins, equal priority also 86 * overrides allowing last-set to win. 87 */ 88SET_DECLARE(ofw_set, ofw_def_t); 89 90boolean_t 91OF_install(char *name, int prio) 92{ 93 ofw_def_t *ofwp, **ofwpp; 94 static int curr_prio = 0; 95 96 /* 97 * Try and locate the OFW kobj corresponding to the name. 98 */ 99 SET_FOREACH(ofwpp, ofw_set) { 100 ofwp = *ofwpp; 101 102 if (ofwp->name && 103 !strcmp(ofwp->name, name) && 104 prio >= curr_prio) { 105 curr_prio = prio; 106 ofw_def_impl = ofwp; 107 return (TRUE); 108 } 109 } 110 111 return (FALSE); 112} 113 114/* Initializer */
|
113void
| 115int
|
114OF_init(void *cookie) 115{ 116 phandle_t chosen;
| 116OF_init(void *cookie) 117{ 118 phandle_t chosen;
|
| 119 int rv;
|
117 118 ofw_obj = &ofw_kernel_obj; 119 /* 120 * Take care of compiling the selected class, and 121 * then statically initialize the OFW object. 122 */ 123 kobj_class_compile_static(ofw_def_impl, &ofw_kernel_kops); 124 kobj_init((kobj_t)ofw_obj, ofw_def_impl); 125
| 120 121 ofw_obj = &ofw_kernel_obj; 122 /* 123 * Take care of compiling the selected class, and 124 * then statically initialize the OFW object. 125 */ 126 kobj_class_compile_static(ofw_def_impl, &ofw_kernel_kops); 127 kobj_init((kobj_t)ofw_obj, ofw_def_impl); 128
|
126 OFW_INIT(ofw_obj, cookie);
| 129 rv = OFW_INIT(ofw_obj, cookie);
|
127
| 130
|
128 if ((chosen = OF_finddevice("/chosen")) == -1) 129 OF_exit(); 130 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) 131 stdout = -1;
| 131 if ((chosen = OF_finddevice("/chosen")) > 0) 132 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) 133 stdout = -1; 134 135 return (rv);
|
132} 133
| 136} 137
|
| 138#ifndef FDT
|
134void 135OF_printf(const char *fmt, ...) 136{ 137 va_list va; 138 char buf[1024]; 139 140 va_start(va, fmt); 141 vsprintf(buf, fmt, va); 142 OF_write(stdout, buf, strlen(buf)); 143 va_end(va); 144} 145 146/* 147 * Generic functions 148 */ 149 150/* Test to see if a service exists. */ 151int 152OF_test(const char *name) 153{ 154 155 return (OFW_TEST(ofw_obj, name)); 156}
| 139void 140OF_printf(const char *fmt, ...) 141{ 142 va_list va; 143 char buf[1024]; 144 145 va_start(va, fmt); 146 vsprintf(buf, fmt, va); 147 OF_write(stdout, buf, strlen(buf)); 148 va_end(va); 149} 150 151/* 152 * Generic functions 153 */ 154 155/* Test to see if a service exists. */ 156int 157OF_test(const char *name) 158{ 159 160 return (OFW_TEST(ofw_obj, name)); 161}
|
| 162#endif
|
157 158int 159OF_interpret(const char *cmd, int nreturns, ...) 160{ 161 va_list ap; 162 unsigned long slots[16]; 163 int i = 0; 164 int status; 165 166 status = OFW_INTERPRET(ofw_obj, cmd, nreturns, slots); 167 if (status == -1) 168 return (status); 169 170 va_start(ap, nreturns); 171 while (i < nreturns) 172 *va_arg(ap, cell_t *) = slots[i++]; 173 va_end(ap); 174 175 return (status); 176} 177 178/* 179 * Device tree functions 180 */ 181 182/* Return the next sibling of this node or 0. */ 183phandle_t 184OF_peer(phandle_t node) 185{ 186 187 return (OFW_PEER(ofw_obj, node)); 188} 189 190/* Return the first child of this node or 0. */ 191phandle_t 192OF_child(phandle_t node) 193{ 194 195 return (OFW_CHILD(ofw_obj, node)); 196} 197 198/* Return the parent of this node or 0. */ 199phandle_t 200OF_parent(phandle_t node) 201{ 202 203 return (OFW_PARENT(ofw_obj, node)); 204} 205 206/* Return the package handle that corresponds to an instance handle. */ 207phandle_t 208OF_instance_to_package(ihandle_t instance) 209{ 210 211 return (OFW_INSTANCE_TO_PACKAGE(ofw_obj, instance)); 212} 213 214/* Get the length of a property of a package. */ 215ssize_t 216OF_getproplen(phandle_t package, const char *propname) 217{ 218 219 return (OFW_GETPROPLEN(ofw_obj, package, propname)); 220} 221 222/* Get the value of a property of a package. */ 223ssize_t 224OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen) 225{ 226 227 return (OFW_GETPROP(ofw_obj, package, propname, buf, buflen)); 228} 229 230/*
| 163 164int 165OF_interpret(const char *cmd, int nreturns, ...) 166{ 167 va_list ap; 168 unsigned long slots[16]; 169 int i = 0; 170 int status; 171 172 status = OFW_INTERPRET(ofw_obj, cmd, nreturns, slots); 173 if (status == -1) 174 return (status); 175 176 va_start(ap, nreturns); 177 while (i < nreturns) 178 *va_arg(ap, cell_t *) = slots[i++]; 179 va_end(ap); 180 181 return (status); 182} 183 184/* 185 * Device tree functions 186 */ 187 188/* Return the next sibling of this node or 0. */ 189phandle_t 190OF_peer(phandle_t node) 191{ 192 193 return (OFW_PEER(ofw_obj, node)); 194} 195 196/* Return the first child of this node or 0. */ 197phandle_t 198OF_child(phandle_t node) 199{ 200 201 return (OFW_CHILD(ofw_obj, node)); 202} 203 204/* Return the parent of this node or 0. */ 205phandle_t 206OF_parent(phandle_t node) 207{ 208 209 return (OFW_PARENT(ofw_obj, node)); 210} 211 212/* Return the package handle that corresponds to an instance handle. */ 213phandle_t 214OF_instance_to_package(ihandle_t instance) 215{ 216 217 return (OFW_INSTANCE_TO_PACKAGE(ofw_obj, instance)); 218} 219 220/* Get the length of a property of a package. */ 221ssize_t 222OF_getproplen(phandle_t package, const char *propname) 223{ 224 225 return (OFW_GETPROPLEN(ofw_obj, package, propname)); 226} 227 228/* Get the value of a property of a package. */ 229ssize_t 230OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen) 231{ 232 233 return (OFW_GETPROP(ofw_obj, package, propname, buf, buflen)); 234} 235 236/*
|
231 * Resursively search the node and its parent for the given property, working
| 237 * Recursively search the node and its parent for the given property, working
|
232 * downward from the node to the device tree root. Returns the value of the 233 * first match. 234 */ 235ssize_t 236OF_searchprop(phandle_t node, const char *propname, void *buf, size_t len) 237{ 238 ssize_t rv; 239 240 for (; node != 0; node = OF_parent(node)) 241 if ((rv = OF_getprop(node, propname, buf, len)) != -1) 242 return (rv); 243 return (-1); 244} 245 246/* 247 * Store the value of a property of a package into newly allocated memory 248 * (using the M_OFWPROP malloc pool and M_WAITOK). elsz is the size of a 249 * single element, the number of elements is return in number. 250 */ 251ssize_t 252OF_getprop_alloc(phandle_t package, const char *propname, int elsz, void **buf) 253{ 254 int len; 255 256 *buf = NULL; 257 if ((len = OF_getproplen(package, propname)) == -1 || 258 len % elsz != 0) 259 return (-1); 260 261 *buf = malloc(len, M_OFWPROP, M_WAITOK); 262 if (OF_getprop(package, propname, *buf, len) == -1) { 263 free(*buf, M_OFWPROP); 264 *buf = NULL; 265 return (-1); 266 } 267 return (len / elsz); 268} 269 270/* Get the next property of a package. */ 271int 272OF_nextprop(phandle_t package, const char *previous, char *buf, size_t size) 273{ 274 275 return (OFW_NEXTPROP(ofw_obj, package, previous, buf, size)); 276} 277 278/* Set the value of a property of a package. */ 279int 280OF_setprop(phandle_t package, const char *propname, const void *buf, size_t len) 281{ 282 283 return (OFW_SETPROP(ofw_obj, package, propname, buf,len)); 284} 285 286/* Convert a device specifier to a fully qualified pathname. */ 287ssize_t 288OF_canon(const char *device, char *buf, size_t len) 289{ 290 291 return (OFW_CANON(ofw_obj, device, buf, len)); 292} 293 294/* Return a package handle for the specified device. */ 295phandle_t 296OF_finddevice(const char *device) 297{ 298 299 return (OFW_FINDDEVICE(ofw_obj, device)); 300} 301 302/* Return the fully qualified pathname corresponding to an instance. */ 303ssize_t 304OF_instance_to_path(ihandle_t instance, char *buf, size_t len) 305{ 306 307 return (OFW_INSTANCE_TO_PATH(ofw_obj, instance, buf, len)); 308} 309 310/* Return the fully qualified pathname corresponding to a package. */ 311ssize_t 312OF_package_to_path(phandle_t package, char *buf, size_t len) 313{ 314 315 return (OFW_PACKAGE_TO_PATH(ofw_obj, package, buf, len)); 316} 317
| 238 * downward from the node to the device tree root. Returns the value of the 239 * first match. 240 */ 241ssize_t 242OF_searchprop(phandle_t node, const char *propname, void *buf, size_t len) 243{ 244 ssize_t rv; 245 246 for (; node != 0; node = OF_parent(node)) 247 if ((rv = OF_getprop(node, propname, buf, len)) != -1) 248 return (rv); 249 return (-1); 250} 251 252/* 253 * Store the value of a property of a package into newly allocated memory 254 * (using the M_OFWPROP malloc pool and M_WAITOK). elsz is the size of a 255 * single element, the number of elements is return in number. 256 */ 257ssize_t 258OF_getprop_alloc(phandle_t package, const char *propname, int elsz, void **buf) 259{ 260 int len; 261 262 *buf = NULL; 263 if ((len = OF_getproplen(package, propname)) == -1 || 264 len % elsz != 0) 265 return (-1); 266 267 *buf = malloc(len, M_OFWPROP, M_WAITOK); 268 if (OF_getprop(package, propname, *buf, len) == -1) { 269 free(*buf, M_OFWPROP); 270 *buf = NULL; 271 return (-1); 272 } 273 return (len / elsz); 274} 275 276/* Get the next property of a package. */ 277int 278OF_nextprop(phandle_t package, const char *previous, char *buf, size_t size) 279{ 280 281 return (OFW_NEXTPROP(ofw_obj, package, previous, buf, size)); 282} 283 284/* Set the value of a property of a package. */ 285int 286OF_setprop(phandle_t package, const char *propname, const void *buf, size_t len) 287{ 288 289 return (OFW_SETPROP(ofw_obj, package, propname, buf,len)); 290} 291 292/* Convert a device specifier to a fully qualified pathname. */ 293ssize_t 294OF_canon(const char *device, char *buf, size_t len) 295{ 296 297 return (OFW_CANON(ofw_obj, device, buf, len)); 298} 299 300/* Return a package handle for the specified device. */ 301phandle_t 302OF_finddevice(const char *device) 303{ 304 305 return (OFW_FINDDEVICE(ofw_obj, device)); 306} 307 308/* Return the fully qualified pathname corresponding to an instance. */ 309ssize_t 310OF_instance_to_path(ihandle_t instance, char *buf, size_t len) 311{ 312 313 return (OFW_INSTANCE_TO_PATH(ofw_obj, instance, buf, len)); 314} 315 316/* Return the fully qualified pathname corresponding to a package. */ 317ssize_t 318OF_package_to_path(phandle_t package, char *buf, size_t len) 319{ 320 321 return (OFW_PACKAGE_TO_PATH(ofw_obj, package, buf, len)); 322} 323
|
| 324#ifndef FDT
|
318/* Call the method in the scope of a given instance. */ 319int 320OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns, 321 ...) 322{ 323 va_list ap; 324 unsigned long args_n_results[12]; 325 int n, status; 326 327 if (nargs > 6) 328 return (-1); 329 va_start(ap, nreturns); 330 for (n = 0; n < nargs; n++) 331 args_n_results[n] = va_arg(ap, unsigned long); 332 333 status = OFW_CALL_METHOD(ofw_obj, instance, method, nargs, nreturns, 334 args_n_results); 335 if (status != 0) 336 return (status); 337 338 for (; n < nargs + nreturns; n++) 339 *va_arg(ap, unsigned long *) = args_n_results[n]; 340 va_end(ap); 341 return (0); 342} 343 344/* 345 * Device I/O functions 346 */ 347 348/* Open an instance for a device. */ 349ihandle_t 350OF_open(const char *device) 351{ 352 353 return (OFW_OPEN(ofw_obj, device)); 354} 355 356/* Close an instance. */ 357void 358OF_close(ihandle_t instance) 359{ 360 361 OFW_CLOSE(ofw_obj, instance); 362} 363 364/* Read from an instance. */ 365ssize_t 366OF_read(ihandle_t instance, void *addr, size_t len) 367{ 368 369 return (OFW_READ(ofw_obj, instance, addr, len)); 370} 371 372/* Write to an instance. */ 373ssize_t 374OF_write(ihandle_t instance, const void *addr, size_t len) 375{ 376 377 return (OFW_WRITE(ofw_obj, instance, addr, len)); 378} 379 380/* Seek to a position. */ 381int 382OF_seek(ihandle_t instance, uint64_t pos) 383{ 384 385 return (OFW_SEEK(ofw_obj, instance, pos)); 386} 387 388/* 389 * Memory functions 390 */ 391 392/* Claim an area of memory. */ 393void * 394OF_claim(void *virt, size_t size, u_int align) 395{ 396 397 return (OFW_CLAIM(ofw_obj, virt, size, align)); 398} 399 400/* Release an area of memory. */ 401void 402OF_release(void *virt, size_t size) 403{ 404 405 OFW_RELEASE(ofw_obj, virt, size); 406} 407 408/* 409 * Control transfer functions 410 */ 411 412/* Suspend and drop back to the Open Firmware interface. */ 413void 414OF_enter() 415{ 416 417 OFW_ENTER(ofw_obj); 418} 419 420/* Shut down and drop back to the Open Firmware interface. */ 421void 422OF_exit() 423{ 424 425 /* Should not return */ 426 OFW_EXIT(ofw_obj); 427 428 for (;;) /* just in case */ 429 ; 430}
| 325/* Call the method in the scope of a given instance. */ 326int 327OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns, 328 ...) 329{ 330 va_list ap; 331 unsigned long args_n_results[12]; 332 int n, status; 333 334 if (nargs > 6) 335 return (-1); 336 va_start(ap, nreturns); 337 for (n = 0; n < nargs; n++) 338 args_n_results[n] = va_arg(ap, unsigned long); 339 340 status = OFW_CALL_METHOD(ofw_obj, instance, method, nargs, nreturns, 341 args_n_results); 342 if (status != 0) 343 return (status); 344 345 for (; n < nargs + nreturns; n++) 346 *va_arg(ap, unsigned long *) = args_n_results[n]; 347 va_end(ap); 348 return (0); 349} 350 351/* 352 * Device I/O functions 353 */ 354 355/* Open an instance for a device. */ 356ihandle_t 357OF_open(const char *device) 358{ 359 360 return (OFW_OPEN(ofw_obj, device)); 361} 362 363/* Close an instance. */ 364void 365OF_close(ihandle_t instance) 366{ 367 368 OFW_CLOSE(ofw_obj, instance); 369} 370 371/* Read from an instance. */ 372ssize_t 373OF_read(ihandle_t instance, void *addr, size_t len) 374{ 375 376 return (OFW_READ(ofw_obj, instance, addr, len)); 377} 378 379/* Write to an instance. */ 380ssize_t 381OF_write(ihandle_t instance, const void *addr, size_t len) 382{ 383 384 return (OFW_WRITE(ofw_obj, instance, addr, len)); 385} 386 387/* Seek to a position. */ 388int 389OF_seek(ihandle_t instance, uint64_t pos) 390{ 391 392 return (OFW_SEEK(ofw_obj, instance, pos)); 393} 394 395/* 396 * Memory functions 397 */ 398 399/* Claim an area of memory. */ 400void * 401OF_claim(void *virt, size_t size, u_int align) 402{ 403 404 return (OFW_CLAIM(ofw_obj, virt, size, align)); 405} 406 407/* Release an area of memory. */ 408void 409OF_release(void *virt, size_t size) 410{ 411 412 OFW_RELEASE(ofw_obj, virt, size); 413} 414 415/* 416 * Control transfer functions 417 */ 418 419/* Suspend and drop back to the Open Firmware interface. */ 420void 421OF_enter() 422{ 423 424 OFW_ENTER(ofw_obj); 425} 426 427/* Shut down and drop back to the Open Firmware interface. */ 428void 429OF_exit() 430{ 431 432 /* Should not return */ 433 OFW_EXIT(ofw_obj); 434 435 for (;;) /* just in case */ 436 ; 437}
|
| 438#endif
|
| |