Date: Sat, 20 Dec 2008 00:33:10 +0000 (UTC) From: Nathan Whitehorn <nwhitehorn@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r186347 - in head/sys: conf dev/ofw kern powerpc/aim powerpc/booke powerpc/include powerpc/powerpc sparc64/include sparc64/sparc64 sun4v/sun4v sys Message-ID: <200812200033.mBK0XAwm086785@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: nwhitehorn Date: Sat Dec 20 00:33:10 2008 New Revision: 186347 URL: http://svn.freebsd.org/changeset/base/186347 Log: Modularize the Open Firmware client interface to allow run-time switching of OFW access semantics, in order to allow future support for real-mode OF access and flattened device frees. OF client interface modules are implemented using KOBJ, in a similar way to the PPC PMAP modules. Because we need Open Firmware to be available before mutexes can be used on sparc64, changes are also included to allow KOBJ to be used very early in the boot process by only using the mutex once we know it has been initialized. Reviewed by: marius, grehan Added: head/sys/dev/ofw/ofw_if.m (contents, props changed) head/sys/dev/ofw/ofw_standard.c - copied, changed from r186188, head/sys/dev/ofw/openfirm.c head/sys/dev/ofw/ofwvar.h (contents, props changed) Modified: head/sys/conf/files.powerpc head/sys/conf/files.sparc64 head/sys/conf/files.sun4v head/sys/dev/ofw/openfirm.c head/sys/dev/ofw/openfirm.h head/sys/dev/ofw/openfirmio.c head/sys/dev/ofw/openpromio.c head/sys/kern/subr_kobj.c head/sys/powerpc/aim/locore.S head/sys/powerpc/aim/machdep.c head/sys/powerpc/aim/ofw_machdep.c head/sys/powerpc/booke/machdep.c head/sys/powerpc/include/ofw_machdep.h head/sys/powerpc/powerpc/pmap_dispatch.c head/sys/sparc64/include/ofw_machdep.h head/sys/sparc64/sparc64/machdep.c head/sys/sparc64/sparc64/mp_machdep.c head/sys/sparc64/sparc64/support.S head/sys/sparc64/sparc64/trap.c head/sys/sparc64/sparc64/vm_machdep.c head/sys/sun4v/sun4v/machdep.c head/sys/sun4v/sun4v/mp_machdep.c head/sys/sun4v/sun4v/support.S head/sys/sun4v/sun4v/trap.c head/sys/sys/kobj.h Modified: head/sys/conf/files.powerpc ============================================================================== --- head/sys/conf/files.powerpc Sat Dec 20 00:04:04 2008 (r186346) +++ head/sys/conf/files.powerpc Sat Dec 20 00:33:10 2008 (r186347) @@ -30,9 +30,11 @@ dev/kbd/kbd.c optional sc dev/ofw/openfirm.c optional aim dev/ofw/openfirmio.c optional aim dev/ofw/ofw_bus_if.m optional aim +dev/ofw/ofw_if.m optional aim dev/ofw/ofw_bus_subr.c optional aim dev/ofw/ofw_console.c optional aim dev/ofw/ofw_disk.c optional ofwd aim +dev/ofw/ofw_standard.c optional aim dev/powermac_nvram/powermac_nvram.c optional powermac_nvram powermac dev/quicc/quicc_bfe_ocp.c optional quicc mpc85xx dev/scc/scc_bfe_macio.c optional scc powermac Modified: head/sys/conf/files.sparc64 ============================================================================== --- head/sys/conf/files.sparc64 Sat Dec 20 00:04:04 2008 (r186346) +++ head/sys/conf/files.sparc64 Sat Dec 20 00:33:10 2008 (r186347) @@ -42,8 +42,10 @@ dev/kbd/kbd.c optional atkbd | sc | uk dev/le/if_le_lebuffer.c optional le sbus dev/le/if_le_ledma.c optional le sbus dev/le/lebuffer_sbus.c optional le sbus +dev/ofw/ofw_if.m standard dev/ofw/ofw_bus_if.m standard dev/ofw/ofw_bus_subr.c standard +dev/ofw/ofw_standard.c standard dev/ofw/ofw_console.c optional ofw_console dev/ofw/openfirm.c standard dev/ofw/openfirmio.c standard Modified: head/sys/conf/files.sun4v ============================================================================== --- head/sys/conf/files.sun4v Sat Dec 20 00:04:04 2008 (r186346) +++ head/sys/conf/files.sun4v Sat Dec 20 00:33:10 2008 (r186347) @@ -21,8 +21,10 @@ ukbdmap.h optional ukbd_dflt_keymap \ crypto/blowfish/bf_enc.c optional crypto | ipsec crypto/des/des_enc.c optional crypto | ipsec | netsmb dev/ofw/ofw_bus_if.m standard +dev/ofw/ofw_if.m standard dev/ofw/ofw_bus_subr.c standard dev/ofw/ofw_console.c optional ofw_console +dev/ofw/ofw_standard.c standard dev/ofw/openfirm.c standard dev/ofw/openfirmio.c standard dev/ofw/openpromio.c standard Added: head/sys/dev/ofw/ofw_if.m ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/ofw/ofw_if.m Sat Dec 20 00:33:10 2008 (r186347) @@ -0,0 +1,357 @@ +#- +# Copyright (c) 2008 Nathan Whitehorn +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofwvar.h> + +/** + * @defgroup OFW ofw - KObj methods for Open Firmware RTAS implementations + * @brief A set of methods to implement the Open Firmware client side interface. + *@{ + */ + +INTERFACE ofw; + +/** + * @brief Initialize OFW client interface + * + * @param _cookie A handle to the client interface, generally the OF + * callback routine. + */ +METHOD void init { + ofw_t _ofw; + void *_cookie; +}; + +/** + * @brief Return next sibling of node + * + * @param _node Selected node + */ +METHOD phandle_t peer { + ofw_t _ofw; + phandle_t _node; +}; + +/** + * @brief Return parent of node + * + * @param _node Selected node + */ +METHOD phandle_t parent { + ofw_t _ofw; + phandle_t _node; +}; + +/** + * @brief Return first child of node + * + * @param _node Selected node + */ +METHOD phandle_t child { + ofw_t _ofw; + phandle_t _node; +}; + +/** + * @brief Return package corresponding to instance + * + * @param _handle Selected instance + */ +METHOD phandle_t instance_to_package { + ofw_t _ofw; + ihandle_t _handle; +}; + +/** + * @brief Return length of node property + * + * @param _node Selected node + * @param _prop Property name + */ +METHOD ssize_t getproplen { + ofw_t _ofw; + phandle_t _node; + const char *_prop; +}; + +/** + * @brief Read node property + * + * @param _node Selected node + * @param _prop Property name + * @param _buf Pointer to buffer + * @param _size Size of buffer + */ +METHOD ssize_t getprop { + ofw_t _ofw; + phandle_t _node; + const char *_prop; + void *_buf; + size_t _size; +}; + +/** + * @brief Get next property name + * + * @param _node Selected node + * @param _prop Current property name + * @param _buf Buffer for next property name + * @param _size Size of buffer + */ +METHOD int nextprop { + ofw_t _ofw; + phandle_t _node; + const char *_prop; + char *_buf; + size_t _size; +}; + +/** + * @brief Set property + * + * @param _node Selected node + * @param _prop Property name + * @param _buf Value to set + * @param _size Size of buffer + */ +METHOD int setprop { + ofw_t _ofw; + phandle_t _node; + const char *_prop; + const void *_buf; + size_t _size; +}; + +/** + * @brief Canonicalize path + * + * @param _path Path to canonicalize + * @param _buf Buffer for canonicalized path + * @param _size Size of buffer + */ +METHOD ssize_t canon { + ofw_t _ofw; + const char *_path; + char *_buf; + size_t _size; +}; + +/** + * @brief Return phandle for named device + * + * @param _path Device path + */ +METHOD phandle_t finddevice { + ofw_t _ofw; + const char *_path; +}; + +/** + * @brief Return path for node instance + * + * @param _handle Instance handle + * @param _path Buffer for path + * @param _size Size of buffer + */ +METHOD ssize_t instance_to_path { + ofw_t _ofw; + ihandle_t _handle; + char *_path; + size_t _size; +}; + +/** + * @brief Return path for node + * + * @param _node Package node + * @param _path Buffer for path + * @param _size Size of buffer + */ +METHOD ssize_t package_to_path { + ofw_t _ofw; + phandle_t _node; + char *_path; + size_t _size; +}; + + +# Methods for OF method calls (optional) + +/** + * @brief Test to see if a service exists. + * + * @param _name name of the service + */ +METHOD int test { + ofw_t _ofw; + const char *_name; +}; + +/** + * @brief Call method belonging to an instance handle + * + * @param _instance Instance handle + * @param _method Method name + * @param _nargs Number of arguments + * @param _nreturns Number of return values + * @param _args_and_returns Values for arguments, followed by returns + */ + +METHOD int call_method { + ofw_t _ofw; + ihandle_t _instance; + const char *_method; + int _nargs; + int _nreturns; + + unsigned long *_args_and_returns; +}; + +/** + * @brief Interpret a forth command + * + * @param _cmd Command + * @param _nreturns Number of return values + * @param _returns Values for returns + */ + +METHOD int interpret { + ofw_t _ofw; + const char *_cmd; + int _nreturns; + unsigned long *_returns; +}; + +# Device I/O Functions (optional) + +/** + * @brief Open node, returning instance handle + * + * @param _path Path to node + */ +METHOD ihandle_t open { + ofw_t _ofw; + const char *_path; +} + +/** + * @brief Close node instance + * + * @param _instance Instance to close + */ +METHOD void close { + ofw_t _ofw; + ihandle_t _instance; +} + +/** + * @brief Read from device + * + * @param _instance Device instance + * @param _buf Buffer to read to + * @param _size Size of buffer + */ +METHOD ssize_t read { + ofw_t _ofw; + ihandle_t _instance; + void *_buf; + size_t size; +} + +/** + * @brief Write to device + * + * @param _instance Device instance + * @param _buf Buffer to write from + * @param _size Size of buffer + */ +METHOD ssize_t write { + ofw_t _ofw; + ihandle_t _instance; + const void *_buf; + size_t size; +} + +/** + * @brief Seek device + * + * @param _instance Device instance + * @param _off Offset to which to seek + */ +METHOD int seek { + ofw_t _ofw; + ihandle_t _instance; + uint64_t _off; +} + +# Open Firmware memory management + +/** + * @brief Claim virtual memory + * + * @param _addr Requested memory location (NULL for first available) + * @param _size Requested size in bytes + * @param _align Requested alignment + */ +METHOD caddr_t claim { + ofw_t _ofw; + void *_addr; + size_t _size; + u_int _align; +} + +/** + * @brief Release virtual memory + * + * @param _addr Memory location + * @param _size Size in bytes + */ +METHOD void release { + ofw_t _ofw; + void *_addr; + size_t _size; +}; + +# Commands for returning control to the firmware + +/** + * @brief Temporarily return control to firmware + */ +METHOD void enter { + ofw_t _ofw; +}; + +/** + * @brief Halt and return control to firmware + */ +METHOD void exit { + ofw_t _ofw; +}; + + Copied and modified: head/sys/dev/ofw/ofw_standard.c (from r186188, head/sys/dev/ofw/openfirm.c) ============================================================================== --- head/sys/dev/ofw/openfirm.c Tue Dec 16 17:04:52 2008 (r186188, copy source) +++ head/sys/dev/ofw/ofw_standard.c Sat Dec 20 00:33:10 2008 (r186347) @@ -66,35 +66,93 @@ __FBSDID("$FreeBSD$"); #include <machine/stdarg.h> #include <dev/ofw/openfirm.h> +#include <dev/ofw/ofwvar.h> +#include "ofw_if.h" -MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties"); +static void ofw_std_init(ofw_t ofw, void *openfirm); +static int ofw_std_test(ofw_t ofw, const char *name); +static int ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns, + unsigned long *returns); +static phandle_t ofw_std_peer(ofw_t ofw, phandle_t node); +static phandle_t ofw_std_child(ofw_t ofw, phandle_t node); +static phandle_t ofw_std_parent(ofw_t ofw, phandle_t node); +static phandle_t ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance); +static ssize_t ofw_std_getproplen(ofw_t ofw, phandle_t package, + const char *propname); +static ssize_t ofw_std_getprop(ofw_t ofw, phandle_t package, + const char *propname, void *buf, size_t buflen); +static int ofw_std_nextprop(ofw_t ofw, phandle_t package, const char *previous, + char *buf, size_t); +static int ofw_std_setprop(ofw_t ofw, phandle_t package, char *propname, + void *buf, size_t len); +static ssize_t ofw_std_canon(ofw_t ofw, const char *device, char *buf, + size_t len); +static phandle_t ofw_std_finddevice(ofw_t ofw, const char *device); +static ssize_t ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance, + char *buf, size_t len); +static ssize_t ofw_std_package_to_path(ofw_t ofw, phandle_t package, char *buf, + size_t len); +static int ofw_std_call_method(ofw_t ofw, ihandle_t instance, + const char *method, int nargs, int nreturns, + unsigned long *args_and_returns); +static ihandle_t ofw_std_open(ofw_t ofw, const char *device); +static void ofw_std_close(ofw_t ofw, ihandle_t instance); +static ssize_t ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr, + size_t len); +static ssize_t ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr, + size_t len); +static int ofw_std_seek(ofw_t ofw, ihandle_t instance, u_int64_t pos); +static caddr_t ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align); +static void ofw_std_release(ofw_t ofw, void *virt, size_t size); +static void ofw_std_enter(ofw_t ofw); +static void ofw_std_exit(ofw_t ofw); + +static ofw_method_t ofw_std_methods[] = { + OFWMETHOD(ofw_init, ofw_std_init), + OFWMETHOD(ofw_peer, ofw_std_peer), + OFWMETHOD(ofw_child, ofw_std_child), + OFWMETHOD(ofw_parent, ofw_std_parent), + OFWMETHOD(ofw_instance_to_package, ofw_std_instance_to_package), + OFWMETHOD(ofw_getproplen, ofw_std_getproplen), + OFWMETHOD(ofw_getprop, ofw_std_getprop), + OFWMETHOD(ofw_nextprop, ofw_std_nextprop), + OFWMETHOD(ofw_setprop, ofw_std_setprop), + OFWMETHOD(ofw_canon, ofw_std_canon), + OFWMETHOD(ofw_finddevice, ofw_std_finddevice), + OFWMETHOD(ofw_instance_to_path, ofw_std_instance_to_path), + OFWMETHOD(ofw_package_to_path, ofw_std_package_to_path), + + OFWMETHOD(ofw_test, ofw_std_test), + OFWMETHOD(ofw_call_method, ofw_std_call_method), + OFWMETHOD(ofw_interpret, ofw_std_interpret), + OFWMETHOD(ofw_open, ofw_std_open), + OFWMETHOD(ofw_close, ofw_std_close), + OFWMETHOD(ofw_read, ofw_std_read), + OFWMETHOD(ofw_write, ofw_std_write), + OFWMETHOD(ofw_seek, ofw_std_seek), + OFWMETHOD(ofw_claim, ofw_std_claim), + OFWMETHOD(ofw_release, ofw_std_release), + OFWMETHOD(ofw_enter, ofw_std_enter), + OFWMETHOD(ofw_exit, ofw_std_exit), + + { 0, 0 } +}; + +static ofw_def_t ofw_std = { + OFW_STD_DIRECT, + ofw_std_methods, + 0 +}; +OFW_DEF(ofw_std); -static ihandle_t stdout; +static int (*openfirmware)(void *); /* Initialiser */ -void -OF_init(int (*openfirm)(void *)) +static void +ofw_std_init(ofw_t ofw, void *openfirm) { - phandle_t chosen; - - set_openfirm_callback(openfirm); - if ((chosen = OF_finddevice("/chosen")) == -1) - OF_exit(); - if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) - OF_exit(); -} - -void -OF_printf(const char *fmt, ...) -{ - va_list va; - char buf[1024]; - - va_start(va, fmt); - vsprintf(buf, fmt, va); - OF_write(stdout, buf, strlen(buf)); - va_end(va); + openfirmware = (int (*)(void *))openfirm; } /* @@ -102,8 +160,8 @@ OF_printf(const char *fmt, ...) */ /* Test to see if a service exists. */ -int -OF_test(char *name) +static int +ofw_std_test(ofw_t ofw, const char *name) { static struct { cell_t name; @@ -123,10 +181,10 @@ OF_test(char *name) return (args.missing); } -int -OF_interpret(char *cmd, int nreturns, ...) +static int +ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns, + unsigned long *returns) { - va_list ap; static struct { cell_t name; cell_t nargs; @@ -137,50 +195,26 @@ OF_interpret(char *cmd, int nreturns, .. 1, }; cell_t status; - int i = 0; + int i = 0, j = 0; - va_start(ap, nreturns); args.nreturns = ++nreturns; args.slot[i++] = (cell_t)cmd; - while (i < 1) - args.slot[i++] = va_arg(ap, cell_t); if (openfirmware(&args) == -1) { - va_end(ap); return (-1); } status = args.slot[i++]; while (i < 1 + nreturns) - *va_arg(ap, cell_t *) = args.slot[i++]; - va_end(ap); + returns[j] = args.slot[i++]; return (status); } -/* Return firmware millisecond count. */ -int -OF_milliseconds() -{ - static struct { - cell_t name; - cell_t nargs; - cell_t nreturns; - cell_t ms; - } args = { - (cell_t)"milliseconds", - 0, - 1, - }; - - openfirmware(&args); - return (args.ms); -} - /* * Device tree functions */ /* Return the next sibling of this node or 0. */ -phandle_t -OF_peer(phandle_t node) +static phandle_t +ofw_std_peer(ofw_t ofw, phandle_t node) { static struct { cell_t name; @@ -201,8 +235,8 @@ OF_peer(phandle_t node) } /* Return the first child of this node or 0. */ -phandle_t -OF_child(phandle_t node) +static phandle_t +ofw_std_child(ofw_t ofw, phandle_t node) { static struct { cell_t name; @@ -223,8 +257,8 @@ OF_child(phandle_t node) } /* Return the parent of this node or 0. */ -phandle_t -OF_parent(phandle_t node) +static phandle_t +ofw_std_parent(ofw_t ofw, phandle_t node) { static struct { cell_t name; @@ -245,8 +279,8 @@ OF_parent(phandle_t node) } /* Return the package handle that corresponds to an instance handle. */ -phandle_t -OF_instance_to_package(ihandle_t instance) +static phandle_t +ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance) { static struct { cell_t name; @@ -267,8 +301,8 @@ OF_instance_to_package(ihandle_t instanc } /* Get the length of a property of a package. */ -int -OF_getproplen(phandle_t package, char *propname) +static ssize_t +ofw_std_getproplen(ofw_t ofw, phandle_t package, const char *propname) { static struct { cell_t name; @@ -291,8 +325,9 @@ OF_getproplen(phandle_t package, char *p } /* Get the value of a property of a package. */ -int -OF_getprop(phandle_t package, char *propname, void *buf, int buflen) +static ssize_t +ofw_std_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf, + size_t buflen) { static struct { cell_t name; @@ -318,33 +353,10 @@ OF_getprop(phandle_t package, char *prop return (args.size); } -/* - * Store the value of a property of a package into newly allocated memory - * (using the M_OFWPROP malloc pool and M_WAITOK). elsz is the size of a - * single element, the number of elements is return in number. - */ -int -OF_getprop_alloc(phandle_t package, char *propname, int elsz, void **buf) -{ - int len; - - *buf = NULL; - if ((len = OF_getproplen(package, propname)) == -1 || - len % elsz != 0) - return (-1); - - *buf = malloc(len, M_OFWPROP, M_WAITOK); - if (OF_getprop(package, propname, *buf, len) == -1) { - free(*buf, M_OFWPROP); - *buf = NULL; - return (-1); - } - return (len / elsz); -} - /* Get the next property of a package. */ -int -OF_nextprop(phandle_t package, char *previous, char *buf) +static int +ofw_std_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf, + size_t size) { static struct { cell_t name; @@ -370,8 +382,9 @@ OF_nextprop(phandle_t package, char *pre /* Set the value of a property of a package. */ /* XXX Has a bug on FirePower */ -int -OF_setprop(phandle_t package, char *propname, void *buf, int len) +static int +ofw_std_setprop(ofw_t ofw, phandle_t package, char *propname, void *buf, + size_t len) { static struct { cell_t name; @@ -398,8 +411,8 @@ OF_setprop(phandle_t package, char *prop } /* Convert a device specifier to a fully qualified pathname. */ -int -OF_canon(const char *device, char *buf, int len) +static ssize_t +ofw_std_canon(ofw_t ofw, const char *device, char *buf, size_t len) { static struct { cell_t name; @@ -424,8 +437,8 @@ OF_canon(const char *device, char *buf, } /* Return a package handle for the specified device. */ -phandle_t -OF_finddevice(const char *device) +static phandle_t +ofw_std_finddevice(ofw_t ofw, const char *device) { static struct { cell_t name; @@ -446,8 +459,8 @@ OF_finddevice(const char *device) } /* Return the fully qualified pathname corresponding to an instance. */ -int -OF_instance_to_path(ihandle_t instance, char *buf, int len) +static ssize_t +ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len) { static struct { cell_t name; @@ -472,8 +485,8 @@ OF_instance_to_path(ihandle_t instance, } /* Return the fully qualified pathname corresponding to a package. */ -int -OF_package_to_path(phandle_t package, char *buf, int len) +static ssize_t +ofw_std_package_to_path(ofw_t ofw, phandle_t package, char *buf, size_t len) { static struct { cell_t name; @@ -498,10 +511,10 @@ OF_package_to_path(phandle_t package, ch } /* Call the method in the scope of a given instance. */ -int -OF_call_method(char *method, ihandle_t instance, int nargs, int nreturns, ...) +static int +ofw_std_call_method(ofw_t ofw, ihandle_t instance, const char *method, + int nargs, int nreturns, unsigned long *args_and_returns) { - va_list ap; static struct { cell_t name; cell_t nargs; @@ -515,6 +528,7 @@ OF_call_method(char *method, ihandle_t i 1, }; cell_t *cp; + unsigned long *ap; int n; if (nargs > 6) @@ -523,16 +537,16 @@ OF_call_method(char *method, ihandle_t i args.nreturns = nreturns + 1; args.method = (cell_t)method; args.instance = instance; - va_start(ap, nreturns); + + ap = args_and_returns; for (cp = args.args_n_results + (n = nargs); --n >= 0;) - *--cp = va_arg(ap, cell_t); + *--cp = *(ap++); if (openfirmware(&args) == -1) return (-1); if (args.args_n_results[nargs]) return (args.args_n_results[nargs]); for (cp = args.args_n_results + nargs + (n = args.nreturns); --n > 0;) - *va_arg(ap, cell_t *) = *--cp; - va_end(ap); + *(ap++) = *--cp; return (0); } @@ -541,8 +555,8 @@ OF_call_method(char *method, ihandle_t i */ /* Open an instance for a device. */ -ihandle_t -OF_open(char *device) +static ihandle_t +ofw_std_open(ofw_t ofw, const char *device) { static struct { cell_t name; @@ -564,8 +578,8 @@ OF_open(char *device) } /* Close an instance. */ -void -OF_close(ihandle_t instance) +static void +ofw_std_close(ofw_t ofw, ihandle_t instance) { static struct { cell_t name; @@ -582,8 +596,8 @@ OF_close(ihandle_t instance) } /* Read from an instance. */ -int -OF_read(ihandle_t instance, void *addr, int len) +static ssize_t +ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr, size_t len) { static struct { cell_t name; @@ -609,8 +623,8 @@ OF_read(ihandle_t instance, void *addr, } /* Write to an instance. */ -int -OF_write(ihandle_t instance, void *addr, int len) +static ssize_t +ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr, size_t len) { static struct { cell_t name; @@ -635,8 +649,8 @@ OF_write(ihandle_t instance, void *addr, } /* Seek to a position. */ -int -OF_seek(ihandle_t instance, u_int64_t pos) +static int +ofw_std_seek(ofw_t ofw, ihandle_t instance, u_int64_t pos) { static struct { cell_t name; @@ -665,8 +679,8 @@ OF_seek(ihandle_t instance, u_int64_t po */ /* Claim an area of memory. */ -void * -OF_claim(void *virt, u_int size, u_int align) +static caddr_t +ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align) { static struct { cell_t name; @@ -691,8 +705,8 @@ OF_claim(void *virt, u_int size, u_int a } /* Release an area of memory. */ -void -OF_release(void *virt, u_int size) +static void +ofw_std_release(ofw_t ofw, void *virt, size_t size) { static struct { cell_t name; @@ -714,29 +728,9 @@ OF_release(void *virt, u_int size) * Control transfer functions */ -/* Reset the system and call "boot <bootspec>". */ -void -OF_boot(char *bootspec) -{ - static struct { - cell_t name; - cell_t nargs; - cell_t nreturns; - cell_t bootspec; - } args = { - (cell_t)"boot", - 1, - }; - - args.bootspec = (cell_t)bootspec; - openfirmware(&args); - for (;;) /* just in case */ - ; -} - /* Suspend and drop back to the Open Firmware interface. */ -void -OF_enter() +static void +ofw_std_enter(ofw_t ofw) { static struct { cell_t name; @@ -751,8 +745,8 @@ OF_enter() } /* Shut down and drop back to the Open Firmware interface. */ -void -OF_exit() +static void +ofw_std_exit(ofw_t ofw) { static struct { cell_t name; @@ -767,44 +761,3 @@ OF_exit() ; } -/* Free <size> bytes starting at <virt>, then call <entry> with <arg>. */ -#if 0 -void -OF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len) -{ - static struct { - cell_t name; - cell_t nargs; - cell_t nreturns; - cell_t virt; - cell_t size; - cell_t entry; - cell_t arg; - cell_t len; - } args = { - (cell_t)"chain", - 5, - }; - - args.virt = (cell_t)virt; - args.size = size; - args.entry = (cell_t)entry; - args.arg = (cell_t)arg; - args.len = len; - openfirmware(&args); -} -#else -void -OF_chain(void *virt, u_int size, - void (*entry)(void *, u_int, void *, void *, u_int), void *arg, u_int len) -{ - /* - * This is a REALLY dirty hack till the firmware gets this going - */ -#if 0 - if (size > 0) - OF_release(virt, size); -#endif - entry(0, 0, openfirmware, arg, len); -} -#endif Added: head/sys/dev/ofw/ofwvar.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/ofw/ofwvar.h Sat Dec 20 00:33:10 2008 (r186347) @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 2005 Peter Grehan + * Copyright (c) 2008 Nathan Whitehorn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _OFW_OFWVAR_H_ +#define _OFW_OFWVAR_H_ + +/* + * An Open Firmware client implementation is declared with a kernel object and + * an associated method table, similar to a device driver. + * + * e.g. + * + * static ofw_method_t fdt_methods[] = { + * OFWMETHOD(ofw_init, fdt_init), + * OFWMETHOD(ofw_finddevice, fdt_finddevice), *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812200033.mBK0XAwm086785>