source: rtems-libbsd/freebsd/sys/dev/ofw/openfirm.c @ c1205ee

5-freebsd-12
Last change on this file since c1205ee was c1205ee, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 2, 2017 at 3:29:11 PM

FDT(4): Port to RTEMS

  • Property mode set to 100644
File size: 18.4 KB
Line 
1#include <machine/rtems-bsd-kernel-space.h>
2
3/*      $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $        */
4
5/*-
6 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
7 * Copyright (C) 1995, 1996 TooLs GmbH.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *      This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 *    derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35/*-
36 * Copyright (C) 2000 Benno Rice.
37 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 *    notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 *    notice, this list of conditions and the following disclaimer in the
46 *    documentation and/or other materials provided with the distribution.
47 *
48 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
49 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
53 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
54 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
55 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
56 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
57 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 */
59
60#include <sys/cdefs.h>
61__FBSDID("$FreeBSD$");
62
63#include <rtems/bsd/local/opt_platform.h>
64
65#include <rtems/bsd/sys/param.h>
66#include <sys/kernel.h>
67#include <rtems/bsd/sys/lock.h>
68#include <sys/malloc.h>
69#include <sys/mutex.h>
70#include <sys/queue.h>
71#include <sys/systm.h>
72#include <sys/endian.h>
73
74#include <machine/stdarg.h>
75
76#include <dev/ofw/ofwvar.h>
77#include <dev/ofw/openfirm.h>
78
79#include <rtems/bsd/local/ofw_if.h>
80
81static void OF_putchar(int c, void *arg);
82
83MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties");
84
85static ihandle_t stdout;
86
87#ifndef __rtems__
88static ofw_def_t        *ofw_def_impl = NULL;
89#else /* __rtems__ */
90#define ofw_def_impl (&ofw_fdt)
91#endif /* __rtems__ */
92static ofw_t            ofw_obj;
93static struct ofw_kobj  ofw_kernel_obj;
94static struct kobj_ops  ofw_kernel_kops;
95
96struct xrefinfo {
97        phandle_t       xref;
98        phandle_t       node;
99        device_t        dev;
100        SLIST_ENTRY(xrefinfo) next_entry;
101};
102
103static SLIST_HEAD(, xrefinfo) xreflist = SLIST_HEAD_INITIALIZER(xreflist);
104static struct mtx xreflist_lock;
105static boolean_t xref_init_done;
106
107#define FIND_BY_XREF    0
108#define FIND_BY_NODE    1
109#define FIND_BY_DEV     2
110
111/*
112 * xref-phandle-device lookup helper routines.
113 *
114 * As soon as we are able to use malloc(), walk the node tree and build a list
115 * of info that cross-references node handles, xref handles, and device_t
116 * instances.  This list exists primarily to allow association of a device_t
117 * with an xref handle, but it is also used to speed up translation between xref
118 * and node handles.  Before malloc() is available we have to recursively search
119 * the node tree each time we want to translate between a node and xref handle.
120 * Afterwards we can do the translations by searching this much shorter list.
121 */
122static void
123xrefinfo_create(phandle_t node)
124{
125        struct xrefinfo * xi;
126        phandle_t child, xref;
127
128        /*
129         * Recursively descend from parent, looking for nodes with a property
130         * named either "phandle", "ibm,phandle", or "linux,phandle".  For each
131         * such node found create an entry in the xreflist.
132         */
133        for (child = OF_child(node); child != 0; child = OF_peer(child)) {
134                xrefinfo_create(child);
135                if (OF_getencprop(child, "phandle", &xref, sizeof(xref)) ==
136                    -1 && OF_getencprop(child, "ibm,phandle", &xref,
137                    sizeof(xref)) == -1 && OF_getencprop(child,
138                    "linux,phandle", &xref, sizeof(xref)) == -1)
139                        continue;
140                xi = malloc(sizeof(*xi), M_OFWPROP, M_WAITOK | M_ZERO);
141                xi->node = child;
142                xi->xref = xref;
143                SLIST_INSERT_HEAD(&xreflist, xi, next_entry);
144        }
145}
146
147static void
148xrefinfo_init(void *unsed)
149{
150
151#ifdef __rtems__
152        if (OF_init(__DECONST(void *, bsp_fdt_get())) != 0)
153                return (ENXIO);
154#endif /* __rtems__ */
155        /*
156         * There is no locking during this init because it runs much earlier
157         * than any of the clients/consumers of the xref list data, but we do
158         * initialize the mutex that will be used for access later.
159         */
160        mtx_init(&xreflist_lock, "OF xreflist lock", NULL, MTX_DEF);
161        xrefinfo_create(OF_peer(0));
162        xref_init_done = true;
163}
164SYSINIT(xrefinfo, SI_SUB_KMEM, SI_ORDER_ANY, xrefinfo_init, NULL);
165
166static struct xrefinfo *
167xrefinfo_find(uintptr_t key, int find_by)
168{
169        struct xrefinfo *rv, *xi;
170
171        rv = NULL;
172        mtx_lock(&xreflist_lock);
173        SLIST_FOREACH(xi, &xreflist, next_entry) {
174                if ((find_by == FIND_BY_XREF && (phandle_t)key == xi->xref) ||
175                    (find_by == FIND_BY_NODE && (phandle_t)key == xi->node) ||
176                    (find_by == FIND_BY_DEV && key == (uintptr_t)xi->dev)) {
177                        rv = xi;
178                        break;
179                }
180        }
181        mtx_unlock(&xreflist_lock);
182        return (rv);
183}
184
185static struct xrefinfo *
186xrefinfo_add(phandle_t node, phandle_t xref, device_t dev)
187{
188        struct xrefinfo *xi;
189
190        xi = malloc(sizeof(*xi), M_OFWPROP, M_WAITOK);
191        xi->node = node;
192        xi->xref = xref;
193        xi->dev  = dev;
194        mtx_lock(&xreflist_lock);
195        SLIST_INSERT_HEAD(&xreflist, xi, next_entry);
196        mtx_unlock(&xreflist_lock);
197        return (xi);
198}
199
200/*
201 * OFW install routines.  Highest priority wins, equal priority also
202 * overrides allowing last-set to win.
203 */
204SET_DECLARE(ofw_set, ofw_def_t);
205
206boolean_t
207OF_install(char *name, int prio)
208{
209#ifndef __rtems__
210        ofw_def_t *ofwp, **ofwpp;
211        static int curr_prio = 0;
212
213        /*
214         * Try and locate the OFW kobj corresponding to the name.
215         */
216        SET_FOREACH(ofwpp, ofw_set) {
217                ofwp = *ofwpp;
218
219                if (ofwp->name &&
220                    !strcmp(ofwp->name, name) &&
221                    prio >= curr_prio) {
222                        curr_prio = prio;
223                        ofw_def_impl = ofwp;
224                        return (TRUE);
225                }
226        }
227
228        return (FALSE);
229#else /* __rtems__ */
230        return (TRUE);
231#endif /* __rtems__ */
232}
233
234/* Initializer */
235int
236OF_init(void *cookie)
237{
238        phandle_t chosen;
239        int rv;
240
241        if (ofw_def_impl == NULL)
242                return (-1);
243
244        ofw_obj = &ofw_kernel_obj;
245        /*
246         * Take care of compiling the selected class, and
247         * then statically initialize the OFW object.
248         */
249        kobj_class_compile_static(ofw_def_impl, &ofw_kernel_kops);
250        kobj_init_static((kobj_t)ofw_obj, ofw_def_impl);
251
252        rv = OFW_INIT(ofw_obj, cookie);
253
254        if ((chosen = OF_finddevice("/chosen")) != -1)
255                if (OF_getencprop(chosen, "stdout", &stdout,
256                    sizeof(stdout)) == -1)
257                        stdout = -1;
258
259        return (rv);
260}
261
262static void
263OF_putchar(int c, void *arg __unused)
264{
265        char cbuf;
266
267        if (c == '\n') {
268                cbuf = '\r';
269                OF_write(stdout, &cbuf, 1);
270        }
271
272        cbuf = c;
273        OF_write(stdout, &cbuf, 1);
274}
275
276void
277OF_printf(const char *fmt, ...)
278{
279        va_list va;
280
281        va_start(va, fmt);
282        (void)kvprintf(fmt, OF_putchar, NULL, 10, va);
283        va_end(va);
284}
285
286/*
287 * Generic functions
288 */
289
290/* Test to see if a service exists. */
291int
292OF_test(const char *name)
293{
294
295        if (ofw_def_impl == NULL)
296                return (-1);
297
298        return (OFW_TEST(ofw_obj, name));
299}
300
301int
302OF_interpret(const char *cmd, int nreturns, ...)
303{
304        va_list ap;
305        cell_t slots[16];
306        int i = 0;
307        int status;
308
309        if (ofw_def_impl == NULL)
310                return (-1);
311
312        status = OFW_INTERPRET(ofw_obj, cmd, nreturns, slots);
313        if (status == -1)
314                return (status);
315
316        va_start(ap, nreturns);
317        while (i < nreturns)
318                *va_arg(ap, cell_t *) = slots[i++];
319        va_end(ap);
320
321        return (status);
322}
323
324/*
325 * Device tree functions
326 */
327
328/* Return the next sibling of this node or 0. */
329phandle_t
330OF_peer(phandle_t node)
331{
332
333        if (ofw_def_impl == NULL)
334                return (0);
335
336        return (OFW_PEER(ofw_obj, node));
337}
338
339/* Return the first child of this node or 0. */
340phandle_t
341OF_child(phandle_t node)
342{
343
344        if (ofw_def_impl == NULL)
345                return (0);
346
347        return (OFW_CHILD(ofw_obj, node));
348}
349
350/* Return the parent of this node or 0. */
351phandle_t
352OF_parent(phandle_t node)
353{
354
355        if (ofw_def_impl == NULL)
356                return (0);
357
358        return (OFW_PARENT(ofw_obj, node));
359}
360
361/* Return the package handle that corresponds to an instance handle. */
362phandle_t
363OF_instance_to_package(ihandle_t instance)
364{
365
366        if (ofw_def_impl == NULL)
367                return (-1);
368
369        return (OFW_INSTANCE_TO_PACKAGE(ofw_obj, instance));
370}
371
372/* Get the length of a property of a package. */
373ssize_t
374OF_getproplen(phandle_t package, const char *propname)
375{
376
377        if (ofw_def_impl == NULL)
378                return (-1);
379
380        return (OFW_GETPROPLEN(ofw_obj, package, propname));
381}
382
383/* Check existence of a property of a package. */
384int
385OF_hasprop(phandle_t package, const char *propname)
386{
387
388        return (OF_getproplen(package, propname) >= 0 ? 1 : 0);
389}
390
391/* Get the value of a property of a package. */
392ssize_t
393OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen)
394{
395
396        if (ofw_def_impl == NULL)
397                return (-1);
398
399        return (OFW_GETPROP(ofw_obj, package, propname, buf, buflen));
400}
401
402ssize_t
403OF_getencprop(phandle_t node, const char *propname, pcell_t *buf, size_t len)
404{
405        ssize_t retval;
406        int i;
407
408        KASSERT(len % 4 == 0, ("Need a multiple of 4 bytes"));
409
410        retval = OF_getprop(node, propname, buf, len);
411        if (retval <= 0)
412                return (retval);
413
414        for (i = 0; i < len/4; i++)
415                buf[i] = be32toh(buf[i]);
416
417        return (retval);
418}
419
420/*
421 * Recursively search the node and its parent for the given property, working
422 * downward from the node to the device tree root.  Returns the value of the
423 * first match.
424 */
425ssize_t
426OF_searchprop(phandle_t node, const char *propname, void *buf, size_t len)
427{
428        ssize_t rv;
429
430        for (; node != 0; node = OF_parent(node))
431                if ((rv = OF_getprop(node, propname, buf, len)) != -1)
432                        return (rv);
433        return (-1);
434}
435
436ssize_t
437OF_searchencprop(phandle_t node, const char *propname, void *buf, size_t len)
438{
439        ssize_t rv;
440
441        for (; node != 0; node = OF_parent(node))
442                if ((rv = OF_getencprop(node, propname, buf, len)) != -1)
443                        return (rv);
444        return (-1);
445}
446
447/*
448 * Store the value of a property of a package into newly allocated memory
449 * (using the M_OFWPROP malloc pool and M_WAITOK).  elsz is the size of a
450 * single element, the number of elements is return in number.
451 */
452ssize_t
453OF_getprop_alloc(phandle_t package, const char *propname, int elsz, void **buf)
454{
455        int len;
456
457        *buf = NULL;
458        if ((len = OF_getproplen(package, propname)) == -1 ||
459            len % elsz != 0)
460                return (-1);
461
462        *buf = malloc(len, M_OFWPROP, M_WAITOK);
463        if (OF_getprop(package, propname, *buf, len) == -1) {
464                free(*buf, M_OFWPROP);
465                *buf = NULL;
466                return (-1);
467        }
468        return (len / elsz);
469}
470
471ssize_t
472OF_getencprop_alloc(phandle_t package, const char *name, int elsz, void **buf)
473{
474        ssize_t retval;
475        pcell_t *cell;
476        int i;
477
478        retval = OF_getprop_alloc(package, name, elsz, buf);
479        if (retval == -1)
480                return (-1);
481        if (retval * elsz % 4 != 0) {
482                free(*buf, M_OFWPROP);
483                *buf = NULL;
484                return (-1);
485        }
486
487        cell = *buf;
488        for (i = 0; i < retval * elsz / 4; i++)
489                cell[i] = be32toh(cell[i]);
490
491        return (retval);
492}
493
494/* Free buffer allocated by OF_getencprop_alloc or OF_getprop_alloc */
495void OF_prop_free(void *buf)
496{
497
498        free(buf, M_OFWPROP);
499}
500
501/* Get the next property of a package. */
502int
503OF_nextprop(phandle_t package, const char *previous, char *buf, size_t size)
504{
505
506        if (ofw_def_impl == NULL)
507                return (-1);
508
509        return (OFW_NEXTPROP(ofw_obj, package, previous, buf, size));
510}
511
512/* Set the value of a property of a package. */
513int
514OF_setprop(phandle_t package, const char *propname, const void *buf, size_t len)
515{
516
517        if (ofw_def_impl == NULL)
518                return (-1);
519
520        return (OFW_SETPROP(ofw_obj, package, propname, buf,len));
521}
522
523/* Convert a device specifier to a fully qualified pathname. */
524ssize_t
525OF_canon(const char *device, char *buf, size_t len)
526{
527
528        if (ofw_def_impl == NULL)
529                return (-1);
530
531        return (OFW_CANON(ofw_obj, device, buf, len));
532}
533
534/* Return a package handle for the specified device. */
535phandle_t
536OF_finddevice(const char *device)
537{
538
539        if (ofw_def_impl == NULL)
540                return (-1);
541
542        return (OFW_FINDDEVICE(ofw_obj, device));
543}
544
545/* Return the fully qualified pathname corresponding to an instance. */
546ssize_t
547OF_instance_to_path(ihandle_t instance, char *buf, size_t len)
548{
549
550        if (ofw_def_impl == NULL)
551                return (-1);
552
553        return (OFW_INSTANCE_TO_PATH(ofw_obj, instance, buf, len));
554}
555
556/* Return the fully qualified pathname corresponding to a package. */
557ssize_t
558OF_package_to_path(phandle_t package, char *buf, size_t len)
559{
560
561        if (ofw_def_impl == NULL)
562                return (-1);
563
564        return (OFW_PACKAGE_TO_PATH(ofw_obj, package, buf, len));
565}
566
567/* Look up effective phandle (see FDT/PAPR spec) */
568static phandle_t
569OF_child_xref_phandle(phandle_t parent, phandle_t xref)
570{
571        phandle_t child, rxref;
572
573        /*
574         * Recursively descend from parent, looking for a node with a property
575         * named either "phandle", "ibm,phandle", or "linux,phandle" that
576         * matches the xref we are looking for.
577         */
578
579        for (child = OF_child(parent); child != 0; child = OF_peer(child)) {
580                rxref = OF_child_xref_phandle(child, xref);
581                if (rxref != -1)
582                        return (rxref);
583
584                if (OF_getencprop(child, "phandle", &rxref, sizeof(rxref)) ==
585                    -1 && OF_getencprop(child, "ibm,phandle", &rxref,
586                    sizeof(rxref)) == -1 && OF_getencprop(child,
587                    "linux,phandle", &rxref, sizeof(rxref)) == -1)
588                        continue;
589
590                if (rxref == xref)
591                        return (child);
592        }
593
594        return (-1);
595}
596
597phandle_t
598OF_node_from_xref(phandle_t xref)
599{
600        struct xrefinfo *xi;
601        phandle_t node;
602
603        if (xref_init_done) {
604                if ((xi = xrefinfo_find(xref, FIND_BY_XREF)) == NULL)
605                        return (xref);
606                return (xi->node);
607        }
608
609        if ((node = OF_child_xref_phandle(OF_peer(0), xref)) == -1)
610                return (xref);
611        return (node);
612}
613
614phandle_t
615OF_xref_from_node(phandle_t node)
616{
617        struct xrefinfo *xi;
618        phandle_t xref;
619
620        if (xref_init_done) {
621                if ((xi = xrefinfo_find(node, FIND_BY_NODE)) == NULL)
622                        return (node);
623                return (xi->xref);
624        }
625
626        if (OF_getencprop(node, "phandle", &xref, sizeof(xref)) == -1 &&
627            OF_getencprop(node, "ibm,phandle", &xref, sizeof(xref)) == -1 &&
628            OF_getencprop(node, "linux,phandle", &xref, sizeof(xref)) == -1)
629                return (node);
630        return (xref);
631}
632
633device_t
634OF_device_from_xref(phandle_t xref)
635{
636        struct xrefinfo *xi;
637
638        if (xref_init_done) {
639                if ((xi = xrefinfo_find(xref, FIND_BY_XREF)) == NULL)
640                        return (NULL);
641                return (xi->dev);
642        }
643        panic("Attempt to find device before xreflist_init");
644}
645
646phandle_t
647OF_xref_from_device(device_t dev)
648{
649        struct xrefinfo *xi;
650
651        if (xref_init_done) {
652                if ((xi = xrefinfo_find((uintptr_t)dev, FIND_BY_DEV)) == NULL)
653                        return (0);
654                return (xi->xref);
655        }
656        panic("Attempt to find xref before xreflist_init");
657}
658
659int
660OF_device_register_xref(phandle_t xref, device_t dev)
661{
662        struct xrefinfo *xi;
663
664        /*
665         * If the given xref handle doesn't already exist in the list then we
666         * add a list entry.  In theory this can only happen on a system where
667         * nodes don't contain phandle properties and xref and node handles are
668         * synonymous, so the xref handle is added as the node handle as well.
669         */
670        if (xref_init_done) {
671                if ((xi = xrefinfo_find(xref, FIND_BY_XREF)) == NULL)
672                        xrefinfo_add(xref, xref, dev);
673                else 
674                        xi->dev = dev;
675                return (0);
676        }
677        panic("Attempt to register device before xreflist_init");
678}
679
680/*  Call the method in the scope of a given instance. */
681int
682OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns,
683    ...)
684{
685        va_list ap;
686        cell_t args_n_results[12];
687        int n, status;
688
689        if (nargs > 6 || ofw_def_impl == NULL)
690                return (-1);
691        va_start(ap, nreturns);
692        for (n = 0; n < nargs; n++)
693                args_n_results[n] = va_arg(ap, cell_t);
694
695        status = OFW_CALL_METHOD(ofw_obj, instance, method, nargs, nreturns,
696            args_n_results);
697        if (status != 0)
698                return (status);
699
700        for (; n < nargs + nreturns; n++)
701                *va_arg(ap, cell_t *) = args_n_results[n];
702        va_end(ap);
703        return (0);
704}
705
706/*
707 * Device I/O functions
708 */
709
710/* Open an instance for a device. */
711ihandle_t
712OF_open(const char *device)
713{
714
715        if (ofw_def_impl == NULL)
716                return (0);
717
718        return (OFW_OPEN(ofw_obj, device));
719}
720
721/* Close an instance. */
722void
723OF_close(ihandle_t instance)
724{
725
726        if (ofw_def_impl == NULL)
727                return;
728
729        OFW_CLOSE(ofw_obj, instance);
730}
731
732/* Read from an instance. */
733ssize_t
734OF_read(ihandle_t instance, void *addr, size_t len)
735{
736
737        if (ofw_def_impl == NULL)
738                return (-1);
739
740        return (OFW_READ(ofw_obj, instance, addr, len));
741}
742
743/* Write to an instance. */
744ssize_t
745OF_write(ihandle_t instance, const void *addr, size_t len)
746{
747
748        if (ofw_def_impl == NULL)
749                return (-1);
750
751        return (OFW_WRITE(ofw_obj, instance, addr, len));
752}
753
754/* Seek to a position. */
755int
756OF_seek(ihandle_t instance, uint64_t pos)
757{
758
759        if (ofw_def_impl == NULL)
760                return (-1);
761
762        return (OFW_SEEK(ofw_obj, instance, pos));
763}
764
765/*
766 * Memory functions
767 */
768
769/* Claim an area of memory. */
770void *
771OF_claim(void *virt, size_t size, u_int align)
772{
773
774        if (ofw_def_impl == NULL)
775                return ((void *)-1);
776
777        return (OFW_CLAIM(ofw_obj, virt, size, align));
778}
779
780/* Release an area of memory. */
781void
782OF_release(void *virt, size_t size)
783{
784
785        if (ofw_def_impl == NULL)
786                return;
787
788        OFW_RELEASE(ofw_obj, virt, size);
789}
790
791/*
792 * Control transfer functions
793 */
794
795/* Suspend and drop back to the Open Firmware interface. */
796void
797OF_enter()
798{
799
800        if (ofw_def_impl == NULL)
801                return;
802
803        OFW_ENTER(ofw_obj);
804}
805
806/* Shut down and drop back to the Open Firmware interface. */
807void
808OF_exit()
809{
810
811        if (ofw_def_impl == NULL)
812                panic("OF_exit: Open Firmware not available");
813
814        /* Should not return */
815        OFW_EXIT(ofw_obj);
816
817        for (;;)                        /* just in case */
818                ;
819}
Note: See TracBrowser for help on using the repository browser.