diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c index 1cc5207fb1b4..05ce13c8e1bc 100644 --- a/sys/dev/ofw/ofw_bus_subr.c +++ b/sys/dev/ofw/ofw_bus_subr.c @@ -1,266 +1,264 @@ /*- * Copyright (c) 2001 - 2003 by Thomas Moestl . * Copyright (c) 2005 Marius Strobl * 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, * without modification, immediately at the beginning of the file. * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include "ofw_bus_if.h" int ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *obd, phandle_t node) { if (obd == NULL) return (ENOMEM); /* The 'name' property is considered mandatory. */ if ((OF_getprop_alloc(node, "name", 1, (void **)&obd->obd_name)) == -1) return (EINVAL); OF_getprop_alloc(node, "compatible", 1, (void **)&obd->obd_compat); OF_getprop_alloc(node, "device_type", 1, (void **)&obd->obd_type); OF_getprop_alloc(node, "model", 1, (void **)&obd->obd_model); obd->obd_node = node; return (0); } void ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *obd) { if (obd == NULL) return; if (obd->obd_compat != NULL) free(obd->obd_compat, M_OFWPROP); if (obd->obd_model != NULL) free(obd->obd_model, M_OFWPROP); if (obd->obd_name != NULL) free(obd->obd_name, M_OFWPROP); if (obd->obd_type != NULL) free(obd->obd_type, M_OFWPROP); } -int +int ofw_bus_gen_child_pnpinfo_str(device_t cbdev, device_t child, char *buf, size_t buflen) { + if (ofw_bus_get_name(child) != NULL) { strlcat(buf, "name=", buflen); strlcat(buf, ofw_bus_get_name(child), buflen); } if (ofw_bus_get_compat(child) != NULL) { strlcat(buf, " compat=", buflen); strlcat(buf, ofw_bus_get_compat(child), buflen); } - return (0); }; const char * ofw_bus_gen_get_compat(device_t bus, device_t dev) { const struct ofw_bus_devinfo *obd; - - obd = OFW_BUS_GET_DEVINFO(bus, dev); + + obd = OFW_BUS_GET_DEVINFO(bus, dev); if (obd == NULL) return (NULL); return (obd->obd_compat); } - + const char * ofw_bus_gen_get_model(device_t bus, device_t dev) { const struct ofw_bus_devinfo *obd; - obd = OFW_BUS_GET_DEVINFO(bus, dev); + obd = OFW_BUS_GET_DEVINFO(bus, dev); if (obd == NULL) return (NULL); return (obd->obd_model); } const char * ofw_bus_gen_get_name(device_t bus, device_t dev) { const struct ofw_bus_devinfo *obd; - obd = OFW_BUS_GET_DEVINFO(bus, dev); + obd = OFW_BUS_GET_DEVINFO(bus, dev); if (obd == NULL) return (NULL); return (obd->obd_name); } phandle_t ofw_bus_gen_get_node(device_t bus, device_t dev) { const struct ofw_bus_devinfo *obd; - obd = OFW_BUS_GET_DEVINFO(bus, dev); + obd = OFW_BUS_GET_DEVINFO(bus, dev); if (obd == NULL) return (0); return (obd->obd_node); } const char * ofw_bus_gen_get_type(device_t bus, device_t dev) { const struct ofw_bus_devinfo *obd; - obd = OFW_BUS_GET_DEVINFO(bus, dev); + obd = OFW_BUS_GET_DEVINFO(bus, dev); if (obd == NULL) return (NULL); return (obd->obd_type); } void ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz) { pcell_t addrc; int msksz; if (OF_getprop(node, "#address-cells", &addrc, sizeof(addrc)) == -1) addrc = 2; ii->opi_addrc = addrc * sizeof(pcell_t); ii->opi_imapsz = OF_getprop_alloc(node, "interrupt-map", 1, (void **)&ii->opi_imap); if (ii->opi_imapsz > 0) { msksz = OF_getprop_alloc(node, "interrupt-map-mask", 1, (void **)&ii->opi_imapmsk); /* - * Failure to get the mask is ignored; a full mask is used then. - * Barf on bad mask sizes, however. + * Failure to get the mask is ignored; a full mask is used + * then. We barf on bad mask sizes, however. */ - if (msksz != -1 && msksz != ii->opi_addrc + intrsz) { + if (msksz != -1 && msksz != ii->opi_addrc + intrsz) panic("ofw_bus_setup_iinfo: bad interrupt-map-mask " "property!"); - } } - } int ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg, int regsz, void *pintr, int pintrsz, void *mintr, int mintrsz, void *maskbuf) { int rv; if (ii->opi_imapsz <= 0) return (0); KASSERT(regsz >= ii->opi_addrc, ("ofw_bus_lookup_imap: register size too small: %d < %d", regsz, ii->opi_addrc)); rv = OF_getprop(node, "reg", reg, regsz); if (rv < regsz) panic("ofw_bus_lookup_imap: could not get reg property"); return (ofw_bus_search_intrmap(pintr, pintrsz, reg, ii->opi_addrc, ii->opi_imap, ii->opi_imapsz, ii->opi_imapmsk, maskbuf, mintr, mintrsz)); } /* * Map an interrupt using the firmware reg, interrupt-map and * interrupt-map-mask properties. * The interrupt property to be mapped must be of size intrsz, and pointed to - * by intr. The regs property of the node for which the mapping is done must + * by intr. The regs property of the node for which the mapping is done must * be passed as regs. This property is an array of register specifications; * the size of the address part of such a specification must be passed as - * physsz. Only the first element of the property is used. + * physsz. Only the first element of the property is used. * imap and imapsz hold the interrupt mask and it's size. * imapmsk is a pointer to the interrupt-map-mask property, which must have * a size of physsz + intrsz; it may be NULL, in which case a full mask is * assumed. * maskbuf must point to a buffer of length physsz + intrsz. * The interrupt is returned in result, which must point to a buffer of length * rintrsz (which gives the expected size of the mapped interrupt). * Returns 1 if a mapping was found, 0 otherwise. */ int ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, void *imap, int imapsz, void *imapmsk, void *maskbuf, void *result, int rintrsz) { phandle_t parent; - u_int8_t *ref = maskbuf; - u_int8_t *uiintr = intr; - u_int8_t *uiregs = regs; - u_int8_t *uiimapmsk = imapmsk; - u_int8_t *mptr; + uint8_t *ref = maskbuf; + uint8_t *uiintr = intr; + uint8_t *uiregs = regs; + uint8_t *uiimapmsk = imapmsk; + uint8_t *mptr; pcell_t pintrsz; int i, rsz, tsz; rsz = -1; if (imapmsk != NULL) { for (i = 0; i < physsz; i++) ref[i] = uiregs[i] & uiimapmsk[i]; for (i = 0; i < intrsz; i++) ref[physsz + i] = uiintr[i] & uiimapmsk[physsz + i]; } else { bcopy(regs, ref, physsz); bcopy(intr, ref + physsz, intrsz); } mptr = imap; i = imapsz; while (i > 0) { bcopy(mptr + physsz + intrsz, &parent, sizeof(parent)); if (OF_searchprop(parent, "#interrupt-cells", &pintrsz, sizeof(pintrsz)) == -1) pintrsz = 1; /* default */ pintrsz *= sizeof(pcell_t); - /* Compute the map stride size */ + /* Compute the map stride size. */ tsz = physsz + intrsz + sizeof(phandle_t) + pintrsz; KASSERT(i >= tsz, ("ofw_bus_search_intrmap: truncated map")); - + /* * XXX: Apple hardware uses a second cell to set information - * on the interrupt trigger type. This information should + * on the interrupt trigger type. This information should * be used somewhere to program the PIC. */ if (bcmp(ref, mptr, physsz + intrsz) == 0) { bcopy(mptr + physsz + intrsz + sizeof(parent), result, rintrsz); return (1); } mptr += tsz; i -= tsz; } return (0); } diff --git a/sys/dev/ofw/ofw_bus_subr.h b/sys/dev/ofw/ofw_bus_subr.h index 58dd5873ca09..14bcbc9547e6 100644 --- a/sys/dev/ofw/ofw_bus_subr.h +++ b/sys/dev/ofw/ofw_bus_subr.h @@ -1,70 +1,70 @@ /*- * Copyright (c) 2005 Marius Strobl * 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, * without modification, immediately at the beginning of the file. * 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 _DEV_OFW_OFW_BUS_SUBR_H_ #define _DEV_OFW_OFW_BUS_SUBR_H_ #include #include #include "ofw_bus_if.h" #define ORIP_NOINT -1 #define ORIR_NOTFOUND 0xffffffff struct ofw_bus_iinfo { - u_int8_t *opi_imap; - u_int8_t *opi_imapmsk; + uint8_t *opi_imap; + uint8_t *opi_imapmsk; int opi_imapsz; pcell_t opi_addrc; }; +/* Generic implementation of ofw_bus_if.m methods and helper routines */ int ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *, phandle_t); void ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *); +ofw_bus_get_compat_t ofw_bus_gen_get_compat; +ofw_bus_get_model_t ofw_bus_gen_get_model; +ofw_bus_get_name_t ofw_bus_gen_get_name; +ofw_bus_get_node_t ofw_bus_gen_get_node; +ofw_bus_get_type_t ofw_bus_gen_get_type; + /* Helper method to report interesting OF properties in pnpinfo */ -int ofw_bus_gen_child_pnpinfo_str(device_t, device_t, char *, size_t); +bus_child_pnpinfo_str_t ofw_bus_gen_child_pnpinfo_str; /* Routines for processing firmware interrupt maps */ - void ofw_bus_setup_iinfo(phandle_t, struct ofw_bus_iinfo *, int); int ofw_bus_lookup_imap(phandle_t, struct ofw_bus_iinfo *, void *, int, void *, int, void *, int, void *); int ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *, void *, void *, int); -ofw_bus_get_compat_t ofw_bus_gen_get_compat; -ofw_bus_get_model_t ofw_bus_gen_get_model; -ofw_bus_get_name_t ofw_bus_gen_get_name; -ofw_bus_get_node_t ofw_bus_gen_get_node; -ofw_bus_get_type_t ofw_bus_gen_get_type; - #endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */ diff --git a/sys/dev/ofw/ofw_disk.c b/sys/dev/ofw/ofw_disk.c index d20cbc3211a6..66155d337ece 100644 --- a/sys/dev/ofw/ofw_disk.c +++ b/sys/dev/ofw/ofw_disk.c @@ -1,208 +1,208 @@ /*- * Copyright (C) 2002 Benno Rice * 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 Benno Rice ``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 TOOLS GMBH 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. * * */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #define OFWD_BLOCKSIZE 512 struct ofwd_softc { - struct bio_queue_head ofwd_bio_queue; - struct mtx ofwd_queue_mtx; + struct bio_queue_head ofwd_bio_queue; + struct mtx ofwd_queue_mtx; ihandle_t ofwd_instance; off_t ofwd_mediasize; - unsigned ofwd_sectorsize; - unsigned ofwd_fwheads; - unsigned ofwd_fwsectors; - struct proc *ofwd_procp; - struct g_geom *ofwd_gp; - struct g_provider *ofwd_pp; + unsigned ofwd_sectorsize; + unsigned ofwd_fwheads; + unsigned ofwd_fwsectors; + struct proc *ofwd_procp; + struct g_geom *ofwd_gp; + struct g_provider *ofwd_pp; } ofwd_softc; static g_init_t g_ofwd_init; static g_start_t g_ofwd_start; static g_access_t g_ofwd_access; struct g_class g_ofwd_class = { .name = "OFWD", .version = G_VERSION, .init = g_ofwd_init, .start = g_ofwd_start, .access = g_ofwd_access, }; DECLARE_GEOM_CLASS(g_ofwd_class, g_ofwd); static int ofwd_enable = 0; TUNABLE_INT("kern.ofw.disk", &ofwd_enable); static int ofwd_startio(struct ofwd_softc *sc, struct bio *bp) { u_int r; r = OF_seek(sc->ofwd_instance, bp->bio_offset); - switch (bp->bio_cmd) { - case BIO_READ: + switch (bp->bio_cmd) { + case BIO_READ: r = OF_read(sc->ofwd_instance, (void *)bp->bio_data, - bp->bio_length); - break; - case BIO_WRITE: + bp->bio_length); + break; + case BIO_WRITE: r = OF_write(sc->ofwd_instance, (void *)bp->bio_data, - bp->bio_length); - break; - } + bp->bio_length); + break; + } if (r != bp->bio_length) panic("ofwd: incorrect i/o count"); - bp->bio_resid = 0; - return (0); + bp->bio_resid = 0; + return (0); } static void ofwd_kthread(void *arg) { struct ofwd_softc *sc; struct bio *bp; int error; - sc = arg; - curthread->td_base_pri = PRIBIO; + sc = arg; + curthread->td_base_pri = PRIBIO; - for (;;) { + for (;;) { mtx_lock(&sc->ofwd_queue_mtx); bp = bioq_takefirst(&sc->ofwd_bio_queue); if (!bp) { msleep(sc, &sc->ofwd_queue_mtx, PRIBIO | PDROP, "ofwdwait", 0); - continue; + continue; } - mtx_unlock(&sc->ofwd_queue_mtx); - if (bp->bio_cmd == BIO_GETATTR) { + mtx_unlock(&sc->ofwd_queue_mtx); + if (bp->bio_cmd == BIO_GETATTR) { error = EOPNOTSUPP; - } else + } else error = ofwd_startio(sc, bp); if (error != -1) { - bp->bio_completed = bp->bio_length; - g_io_deliver(bp, error); - } + bp->bio_completed = bp->bio_length; + g_io_deliver(bp, error); + } } } static void g_ofwd_init(struct g_class *mp __unused) { - struct ofwd_softc *sc; - struct g_geom *gp; - struct g_provider *pp; - char path[128]; - char fname[32]; + char path[128]; + char fname[32]; phandle_t ofd; + struct ofwd_softc *sc; + struct g_geom *gp; + struct g_provider *pp; ihandle_t ifd; - int error; + int error; if (ofwd_enable == 0) return; ofd = OF_finddevice("ofwdisk"); if (ofd == -1) return; bzero(path, 128); OF_package_to_path(ofd, path, 128); OF_getprop(ofd, "file", fname, sizeof(fname)); printf("ofw_disk located at %s, file %s\n", path, fname); ifd = OF_open(path); if (ifd == -1) { printf("ofw_disk: could not create instance\n"); return; } sc = (struct ofwd_softc *)malloc(sizeof *sc, M_DEVBUF, - M_WAITOK|M_ZERO); + M_WAITOK|M_ZERO); bioq_init(&sc->ofwd_bio_queue); - mtx_init(&sc->ofwd_queue_mtx, "ofwd bio queue", NULL, MTX_DEF); + mtx_init(&sc->ofwd_queue_mtx, "ofwd bio queue", NULL, MTX_DEF); sc->ofwd_instance = ifd; - sc->ofwd_mediasize = (off_t)2*33554432; + sc->ofwd_mediasize = (off_t)2 * 33554432; sc->ofwd_sectorsize = OFWD_BLOCKSIZE; sc->ofwd_fwsectors = 0; sc->ofwd_fwheads = 0; error = kproc_create(ofwd_kthread, sc, &sc->ofwd_procp, 0, 0, - "ofwd0"); - if (error != 0) { + "ofwd0"); + if (error != 0) { free(sc, M_DEVBUF); - return; + return; } gp = g_new_geomf(&g_ofwd_class, "ofwd0"); gp->softc = sc; pp = g_new_providerf(gp, "ofwd0"); pp->mediasize = sc->ofwd_mediasize; pp->sectorsize = sc->ofwd_sectorsize; sc->ofwd_gp = gp; sc->ofwd_pp = pp; g_error_provider(pp, 0); } static void g_ofwd_start(struct bio *bp) { - struct ofwd_softc *sc; + struct ofwd_softc *sc; - sc = bp->bio_to->geom->softc; - mtx_lock(&sc->ofwd_queue_mtx); - bioq_disksort(&sc->ofwd_bio_queue, bp); - mtx_unlock(&sc->ofwd_queue_mtx); - wakeup(sc); + sc = bp->bio_to->geom->softc; + mtx_lock(&sc->ofwd_queue_mtx); + bioq_disksort(&sc->ofwd_bio_queue, bp); + mtx_unlock(&sc->ofwd_queue_mtx); + wakeup(sc); } static int g_ofwd_access(struct g_provider *pp, int r, int w, int e) { if (pp->geom->softc == NULL) return (ENXIO); - return (0); + return (0); } diff --git a/sys/dev/ofw/ofw_if.m b/sys/dev/ofw/ofw_if.m index 431ac910c66f..902f071aa40e 100644 --- a/sys/dev/ofw/ofw_if.m +++ b/sys/dev/ofw/ofw_if.m @@ -1,357 +1,354 @@ #- # 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 #include /** * @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 + * @brief Return next sibling of node. * * @param _node Selected node */ METHOD phandle_t peer { ofw_t _ofw; - phandle_t _node; + phandle_t _node; }; /** - * @brief Return parent of node + * @brief Return parent of node. * * @param _node Selected node */ METHOD phandle_t parent { ofw_t _ofw; - phandle_t _node; + phandle_t _node; }; /** - * @brief Return first child of node + * @brief Return first child of node. * * @param _node Selected node */ METHOD phandle_t child { ofw_t _ofw; - phandle_t _node; + phandle_t _node; }; /** - * @brief Return package corresponding to instance + * @brief Return package corresponding to instance. * * @param _handle Selected instance */ METHOD phandle_t instance_to_package { ofw_t _ofw; - ihandle_t _handle; + ihandle_t _handle; }; /** - * @brief Return length of node property + * @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; + phandle_t _node; + const char *_prop; }; /** - * @brief Read node property + * @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; + phandle_t _node; const char *_prop; void *_buf; size_t _size; }; /** - * @brief Get next property name + * @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; + phandle_t _node; const char *_prop; - char *_buf; + char *_buf; size_t _size; }; /** - * @brief Set property + * @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; + phandle_t _node; + const char *_prop; const void *_buf; size_t _size; }; /** - * @brief Canonicalize path + * @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 + * @brief Return phandle for named device. * * @param _path Device path */ METHOD phandle_t finddevice { ofw_t _ofw; - const char *_path; + const char *_path; }; /** - * @brief Return path for node instance + * @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; + char *_path; size_t _size; }; /** - * @brief Return path for node + * @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; + 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 + * @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; + int _nreturns; unsigned long *_args_and_returns; }; /** - * @brief Interpret a forth command + * @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; + int _nreturns; unsigned long *_returns; }; # Device I/O Functions (optional) /** - * @brief Open node, returning instance handle + * @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 + * @brief Close node instance. * * @param _instance Instance to close */ METHOD void close { ofw_t _ofw; ihandle_t _instance; } /** - * @brief Read from device + * @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 + * @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 + * @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 + * @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 + * @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 + * @brief Temporarily return control to firmware. */ METHOD void enter { ofw_t _ofw; }; /** - * @brief Halt and return control to firmware + * @brief Halt and return control to firmware. */ METHOD void exit { ofw_t _ofw; }; - - diff --git a/sys/dev/ofw/ofw_iicbus.c b/sys/dev/ofw/ofw_iicbus.c index e8effca14160..2ee9a7283184 100644 --- a/sys/dev/ofw/ofw_iicbus.c +++ b/sys/dev/ofw/ofw_iicbus.c @@ -1,190 +1,187 @@ /*- * Copyright (c) 2009, 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 unmodified, 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 ``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 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include "iicbus_if.h" /* Methods */ static device_probe_t ofw_iicbus_probe; static device_attach_t ofw_iicbus_attach; static device_t ofw_iicbus_add_child(device_t dev, int order, const char *name, int unit); static const struct ofw_bus_devinfo *ofw_iicbus_get_devinfo(device_t bus, device_t dev); static device_method_t ofw_iicbus_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ofw_iicbus_probe), DEVMETHOD(device_attach, ofw_iicbus_attach), /* Bus interface */ DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str), DEVMETHOD(bus_add_child, ofw_iicbus_add_child), /* ofw_bus interface */ DEVMETHOD(ofw_bus_get_devinfo, ofw_iicbus_get_devinfo), DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name), DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), - { 0, 0 } + KOBJMETHOD_END }; struct ofw_iicbus_devinfo { struct iicbus_ivar opd_dinfo; struct ofw_bus_devinfo opd_obdinfo; }; static devclass_t ofwiicbus_devclass; DEFINE_CLASS_1(iicbus, ofw_iicbus_driver, ofw_iicbus_methods, sizeof(struct iicbus_softc), iicbus_driver); DRIVER_MODULE(ofw_iicbus, iichb, ofw_iicbus_driver, ofwiicbus_devclass, 0, 0); MODULE_VERSION(ofw_iicbus, 1); MODULE_DEPEND(ofw_iicbus, iicbus, 1, 1, 1); static int ofw_iicbus_probe(device_t dev) { if (ofw_bus_get_node(dev) == 0) return (ENXIO); device_set_desc(dev, "OFW I2C bus"); return (0); } static int ofw_iicbus_attach(device_t dev) { struct iicbus_softc *sc = IICBUS_SOFTC(dev); struct ofw_iicbus_devinfo *dinfo; - phandle_t node, child; + phandle_t child; device_t childdev; uint32_t addr; sc->dev = dev; mtx_init(&sc->lock, "iicbus", NULL, MTX_DEF); iicbus_reset(dev, IIC_FASTEST, 0, NULL); bus_generic_probe(dev); bus_enumerate_hinted_children(dev); /* * Attach those children represented in the device tree. */ - - node = ofw_bus_get_node(dev); - - for (child = OF_child(node); child != 0; child = OF_peer(child)) { + for (child = OF_child(ofw_bus_get_node(dev)); child != 0; + child = OF_peer(child)) { /* * Try to get the I2C address first from the i2c-address - * property, then try the reg property. It moves around + * property, then try the reg property. It moves around * on different systems. */ - if (OF_getprop(child, "i2c-address", &addr, sizeof(addr)) == -1) if (OF_getprop(child, "reg", &addr, sizeof(addr)) == -1) continue; /* * Now set up the I2C and OFW bus layer devinfo and add it * to the bus. */ - dinfo = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF, M_NOWAIT | M_ZERO); if (dinfo == NULL) continue; dinfo->opd_dinfo.addr = addr; if (ofw_bus_gen_setup_devinfo(&dinfo->opd_obdinfo, child) != 0) { free(dinfo, M_DEVBUF); continue; } childdev = device_add_child(dev, NULL, -1); device_set_ivars(childdev, dinfo); } return (bus_generic_attach(dev)); } static device_t ofw_iicbus_add_child(device_t dev, int order, const char *name, int unit) { device_t child; struct ofw_iicbus_devinfo *devi; child = device_add_child_ordered(dev, order, name, unit); if (child == NULL) return (child); - devi = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF, + devi = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF, M_NOWAIT | M_ZERO); if (devi == NULL) { device_delete_child(dev, child); return (0); } - /* NULL all the OFW-related parts of the ivars for non-OFW children */ - + /* + * NULL all the OFW-related parts of the ivars for non-OFW + * children. + */ devi->opd_obdinfo.obd_node = -1; devi->opd_obdinfo.obd_name = NULL; devi->opd_obdinfo.obd_compat = NULL; devi->opd_obdinfo.obd_type = NULL; devi->opd_obdinfo.obd_model = NULL; device_set_ivars(child, devi); - + return (child); } static const struct ofw_bus_devinfo * ofw_iicbus_get_devinfo(device_t bus, device_t dev) { struct ofw_iicbus_devinfo *dinfo; dinfo = device_get_ivars(dev); return (&dinfo->opd_obdinfo); } - diff --git a/sys/dev/ofw/ofw_standard.c b/sys/dev/ofw/ofw_standard.c index addca7119037..de18a9e73df2 100644 --- a/sys/dev/ofw/ofw_standard.c +++ b/sys/dev/ofw/ofw_standard.c @@ -1,763 +1,762 @@ /* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $ */ /*- * Copyright (C) 1995, 1996 Wolfgang Solfrank. * Copyright (C) 1995, 1996 TooLs GmbH. * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by TooLs GmbH. * 4. The name of TooLs GmbH may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. */ /*- * Copyright (C) 2000 Benno Rice. * 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 Benno Rice ``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 TOOLS GMBH 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include -#include #include +#include + #include "ofw_if.h" 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, const char *propname, const 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 int ofw_std_seek(ofw_t ofw, ihandle_t instance, uint64_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 int (*openfirmware)(void *); -/* Initialiser */ +/* Initializer */ static void ofw_std_init(ofw_t ofw, void *openfirm) { + openfirmware = (int (*)(void *))openfirm; } /* * Generic functions */ /* Test to see if a service exists. */ static int ofw_std_test(ofw_t ofw, const char *name) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t service; cell_t missing; } args = { (cell_t)"test", 1, 1, }; args.service = (cell_t)name; if (openfirmware(&args) == -1) return (-1); return (args.missing); } static int ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns, unsigned long *returns) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t slot[16]; } args = { (cell_t)"interpret", 1, }; cell_t status; int i = 0, j = 0; args.nreturns = ++nreturns; args.slot[i++] = (cell_t)cmd; - if (openfirmware(&args) == -1) { + if (openfirmware(&args) == -1) return (-1); - } status = args.slot[i++]; while (i < 1 + nreturns) returns[j++] = args.slot[i++]; return (status); } /* * Device tree functions */ /* Return the next sibling of this node or 0. */ static phandle_t ofw_std_peer(ofw_t ofw, phandle_t node) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t node; cell_t next; } args = { (cell_t)"peer", 1, 1, }; args.node = node; if (openfirmware(&args) == -1) return (-1); return (args.next); } /* Return the first child of this node or 0. */ static phandle_t ofw_std_child(ofw_t ofw, phandle_t node) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t node; cell_t child; } args = { (cell_t)"child", 1, 1, }; args.node = node; if (openfirmware(&args) == -1) return (-1); return (args.child); } /* Return the parent of this node or 0. */ static phandle_t ofw_std_parent(ofw_t ofw, phandle_t node) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t node; cell_t parent; } args = { (cell_t)"parent", 1, 1, }; args.node = node; if (openfirmware(&args) == -1) return (-1); return (args.parent); } /* Return the package handle that corresponds to an instance handle. */ static phandle_t ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t instance; cell_t package; } args = { (cell_t)"instance-to-package", 1, 1, }; args.instance = instance; if (openfirmware(&args) == -1) return (-1); return (args.package); } /* Get the length of a property of a package. */ static ssize_t ofw_std_getproplen(ofw_t ofw, phandle_t package, const char *propname) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t package; cell_t propname; cell_t proplen; } args = { (cell_t)"getproplen", 2, 1, }; args.package = package; args.propname = (cell_t)propname; if (openfirmware(&args) == -1) return (-1); return (args.proplen); } /* Get the value of a property of a package. */ 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; cell_t nargs; cell_t nreturns; cell_t package; cell_t propname; cell_t buf; cell_t buflen; cell_t size; } args = { (cell_t)"getprop", 4, 1, }; args.package = package; args.propname = (cell_t)propname; args.buf = (cell_t)buf; args.buflen = buflen; if (openfirmware(&args) == -1) return (-1); return (args.size); } /* Get the next property of a package. */ static int ofw_std_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf, size_t size) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t package; cell_t previous; cell_t buf; cell_t flag; } args = { (cell_t)"nextprop", 3, 1, }; args.package = package; args.previous = (cell_t)previous; args.buf = (cell_t)buf; if (openfirmware(&args) == -1) return (-1); return (args.flag); } /* Set the value of a property of a package. */ /* XXX Has a bug on FirePower */ static int ofw_std_setprop(ofw_t ofw, phandle_t package, const char *propname, const void *buf, size_t len) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t package; cell_t propname; cell_t buf; cell_t len; cell_t size; } args = { (cell_t)"setprop", 4, 1, }; args.package = package; args.propname = (cell_t)propname; args.buf = (cell_t)buf; args.len = len; if (openfirmware(&args) == -1) return (-1); return (args.size); } /* Convert a device specifier to a fully qualified pathname. */ static ssize_t ofw_std_canon(ofw_t ofw, const char *device, char *buf, size_t len) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t device; cell_t buf; cell_t len; cell_t size; } args = { (cell_t)"canon", 3, 1, }; args.device = (cell_t)device; args.buf = (cell_t)buf; args.len = len; if (openfirmware(&args) == -1) return (-1); return (args.size); } /* Return a package handle for the specified device. */ static phandle_t ofw_std_finddevice(ofw_t ofw, const char *device) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t device; cell_t package; } args = { (cell_t)"finddevice", 1, 1, }; args.device = (cell_t)device; if (openfirmware(&args) == -1) return (-1); return (args.package); } /* Return the fully qualified pathname corresponding to an instance. */ static ssize_t ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t instance; cell_t buf; cell_t len; cell_t size; } args = { (cell_t)"instance-to-path", 3, 1, }; args.instance = instance; args.buf = (cell_t)buf; args.len = len; if (openfirmware(&args) == -1) return (-1); return (args.size); } /* Return the fully qualified pathname corresponding to a package. */ static ssize_t ofw_std_package_to_path(ofw_t ofw, phandle_t package, char *buf, size_t len) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t package; cell_t buf; cell_t len; cell_t size; } args = { (cell_t)"package-to-path", 3, 1, }; args.package = package; args.buf = (cell_t)buf; args.len = len; if (openfirmware(&args) == -1) return (-1); return (args.size); } /* Call the method in the scope of a given instance. */ 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 struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t method; cell_t instance; cell_t args_n_results[12]; } args = { (cell_t)"call-method", 2, 1, }; cell_t *cp; unsigned long *ap; int n; if (nargs > 6) return (-1); args.nargs = nargs + 2; args.nreturns = nreturns + 1; args.method = (cell_t)method; args.instance = instance; ap = args_and_returns; for (cp = args.args_n_results + (n = nargs); --n >= 0;) *--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;) *(ap++) = *--cp; return (0); } /* * Device I/O functions */ /* Open an instance for a device. */ static ihandle_t ofw_std_open(ofw_t ofw, const char *device) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t device; cell_t instance; } args = { (cell_t)"open", 1, 1, }; args.device = (cell_t)device; - if (openfirmware(&args) == -1 || args.instance == 0) { + if (openfirmware(&args) == -1 || args.instance == 0) return (-1); - } return (args.instance); } /* Close an instance. */ static void ofw_std_close(ofw_t ofw, ihandle_t instance) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t instance; } args = { (cell_t)"close", 1, }; args.instance = instance; openfirmware(&args); } /* Read from an instance. */ static ssize_t ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr, size_t len) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t instance; cell_t addr; cell_t len; cell_t actual; } args = { (cell_t)"read", 3, 1, }; args.instance = instance; args.addr = (cell_t)addr; args.len = len; if (openfirmware(&args) == -1) return (-1); return (args.actual); } /* Write to an instance. */ static ssize_t ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr, size_t len) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t instance; cell_t addr; cell_t len; cell_t actual; } args = { (cell_t)"write", 3, 1, }; args.instance = instance; args.addr = (cell_t)addr; args.len = len; if (openfirmware(&args) == -1) return (-1); return (args.actual); } /* Seek to a position. */ static int -ofw_std_seek(ofw_t ofw, ihandle_t instance, u_int64_t pos) +ofw_std_seek(ofw_t ofw, ihandle_t instance, uint64_t pos) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t instance; cell_t poshi; cell_t poslo; cell_t status; } args = { (cell_t)"seek", 3, 1, }; args.instance = instance; args.poshi = pos >> 32; args.poslo = pos; if (openfirmware(&args) == -1) return (-1); return (args.status); } /* * Memory functions */ /* Claim an area of memory. */ static caddr_t ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t virt; cell_t size; cell_t align; cell_t baseaddr; } args = { (cell_t)"claim", 3, 1, }; args.virt = (cell_t)virt; args.size = size; args.align = align; if (openfirmware(&args) == -1) return ((void *)-1); return ((void *)args.baseaddr); } /* Release an area of memory. */ static void ofw_std_release(ofw_t ofw, void *virt, size_t size) { static struct { cell_t name; cell_t nargs; cell_t nreturns; cell_t virt; cell_t size; } args = { (cell_t)"release", 2, }; args.virt = (cell_t)virt; args.size = size; openfirmware(&args); } /* * Control transfer functions */ /* Suspend and drop back to the Open Firmware interface. */ static void ofw_std_enter(ofw_t ofw) { static struct { cell_t name; cell_t nargs; cell_t nreturns; } args = { (cell_t)"enter", }; openfirmware(&args); /* We may come back. */ } /* Shut down and drop back to the Open Firmware interface. */ static void ofw_std_exit(ofw_t ofw) { static struct { cell_t name; cell_t nargs; cell_t nreturns; } args = { (cell_t)"exit", }; openfirmware(&args); for (;;) /* just in case */ ; } - diff --git a/sys/dev/ofw/ofwvar.h b/sys/dev/ofw/ofwvar.h index 950dded259ed..ddaa3db097dd 100644 --- a/sys/dev/ofw/ofwvar.h +++ b/sys/dev/ofw/ofwvar.h @@ -1,89 +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_ +#ifndef _DEV_OFW_OFWVAR_H_ +#define _DEV_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), * ... * OFWMETHOD(ofw_nextprop, fdt_nextprop), * { 0, 0 } * }; * * static ofw_def_t ofw_fdt = { - * "ofw_fdt", + * "ofw_fdt", * fdt_methods, * sizeof(fdt_softc), // or 0 if no softc * }; * * OFW_DEF(ofw_fdt); */ #include struct ofw_kobj { /* * An OFW instance is a kernel object. */ KOBJ_FIELDS; /* * Utility elements that an instance may use */ struct mtx ofw_mtx; /* available for instance use */ void *ofw_iptr; /* instance data pointer */ /* * Opaque data that can be overlaid with an instance-private - * structure. OFW code can test that this is large enough at - * compile time with a sizeof() test againt it's softc. There + * structure. OFW code can test that this is large enough at + * compile time with a sizeof() test againt it's softc. There * is also a run-time test when the MMU kernel object is * registered. */ -#define OFW_OPAQUESZ 64 +#define OFW_OPAQUESZ 64 u_int ofw_opaque[OFW_OPAQUESZ]; }; typedef struct ofw_kobj *ofw_t; typedef struct kobj_class ofw_def_t; -#define ofw_method_t kobj_method_t -#define OFWMETHOD KOBJMETHOD +#define ofw_method_t kobj_method_t +#define OFWMETHOD KOBJMETHOD -#define OFW_DEF(name) DATA_SET(ofw_set, name) +#define OFW_DEF(name) DATA_SET(ofw_set, name) -#endif /* _OFW_OFWVAR_H_ */ +#endif /* _DEV_OFW_OFWVAR_H_ */ diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c index 06b58d06331f..17cda68678aa 100644 --- a/sys/dev/ofw/openfirm.c +++ b/sys/dev/ofw/openfirm.c @@ -1,412 +1,430 @@ /* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $ */ /*- * Copyright (C) 1995, 1996 Wolfgang Solfrank. * Copyright (C) 1995, 1996 TooLs GmbH. * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by TooLs GmbH. * 4. The name of TooLs GmbH may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. */ /*- * Copyright (C) 2000 Benno Rice. * 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 Benno Rice ``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 TOOLS GMBH 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include -#include #include +#include #include "ofw_if.h" MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties"); static ihandle_t stdout; static ofw_def_t *ofw_def_impl; static ofw_t ofw_obj; static struct ofw_kobj ofw_kernel_obj; static struct kobj_ops ofw_kernel_kops; /* * OFW install routines. Highest priority wins, equal priority also * overrides allowing last-set to win. */ SET_DECLARE(ofw_set, ofw_def_t); boolean_t OF_install(char *name, int prio) { - ofw_def_t **ofwpp, *ofwp; + ofw_def_t *ofwp, **ofwpp; static int curr_prio = 0; /* - * Try and locate the OFW kobj corresponding to the name - */ + * Try and locate the OFW kobj corresponding to the name. + */ SET_FOREACH(ofwpp, ofw_set) { ofwp = *ofwpp; if (ofwp->name && !strcmp(ofwp->name, name) && prio >= curr_prio) { curr_prio = prio; ofw_def_impl = ofwp; return (TRUE); } } return (FALSE); } -/* Initialiser */ - +/* Initializer */ void OF_init(void *cookie) { phandle_t chosen; ofw_obj = &ofw_kernel_obj; /* * Take care of compiling the selected class, and - * then statically initialize the OFW object + * then statically initialize the OFW object. */ kobj_class_compile_static(ofw_def_impl, &ofw_kernel_kops); kobj_init((kobj_t)ofw_obj, ofw_def_impl); OFW_INIT(ofw_obj, cookie); if ((chosen = OF_finddevice("/chosen")) == -1) OF_exit(); if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) stdout = -1; } 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); } /* * Generic functions */ /* Test to see if a service exists. */ int OF_test(const char *name) { + return (OFW_TEST(ofw_obj, name)); } int OF_interpret(const char *cmd, int nreturns, ...) { va_list ap; unsigned long slots[16]; int i = 0; int status; status = OFW_INTERPRET(ofw_obj, cmd, nreturns, slots); if (status == -1) return (status); va_start(ap, nreturns); while (i < nreturns) *va_arg(ap, cell_t *) = slots[i++]; va_end(ap); return (status); } /* * Device tree functions */ /* Return the next sibling of this node or 0. */ phandle_t OF_peer(phandle_t node) { + return (OFW_PEER(ofw_obj, node)); } /* Return the first child of this node or 0. */ phandle_t OF_child(phandle_t node) { + return (OFW_CHILD(ofw_obj, node)); } /* Return the parent of this node or 0. */ phandle_t OF_parent(phandle_t node) { + return (OFW_PARENT(ofw_obj, node)); } /* Return the package handle that corresponds to an instance handle. */ phandle_t OF_instance_to_package(ihandle_t instance) { + return (OFW_INSTANCE_TO_PACKAGE(ofw_obj, instance)); } /* Get the length of a property of a package. */ ssize_t OF_getproplen(phandle_t package, const char *propname) { + return (OFW_GETPROPLEN(ofw_obj, package, propname)); } /* Get the value of a property of a package. */ ssize_t OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen) { + return (OFW_GETPROP(ofw_obj, package, propname, buf, buflen)); } /* * Resursively search the node and its parent for the given property, working * downward from the node to the device tree root. Returns the value of the * first match. */ ssize_t -OF_searchprop(phandle_t node, char *propname, void *buf, size_t len) +OF_searchprop(phandle_t node, const char *propname, void *buf, size_t len) { ssize_t rv; - for (; node != 0; node = OF_parent(node)) { + for (; node != 0; node = OF_parent(node)) if ((rv = OF_getprop(node, propname, buf, len)) != -1) return (rv); - } return (-1); } /* * 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 + * (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. */ ssize_t OF_getprop_alloc(phandle_t package, const 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, const char *previous, char *buf, size_t size) { + return (OFW_NEXTPROP(ofw_obj, package, previous, buf, size)); } /* Set the value of a property of a package. */ int OF_setprop(phandle_t package, const char *propname, const void *buf, size_t len) { + return (OFW_SETPROP(ofw_obj, package, propname, buf,len)); } /* Convert a device specifier to a fully qualified pathname. */ ssize_t OF_canon(const char *device, char *buf, size_t len) { + return (OFW_CANON(ofw_obj, device, buf, len)); } /* Return a package handle for the specified device. */ phandle_t OF_finddevice(const char *device) { + return (OFW_FINDDEVICE(ofw_obj, device)); } /* Return the fully qualified pathname corresponding to an instance. */ ssize_t OF_instance_to_path(ihandle_t instance, char *buf, size_t len) { + return (OFW_INSTANCE_TO_PATH(ofw_obj, instance, buf, len)); } /* Return the fully qualified pathname corresponding to a package. */ ssize_t OF_package_to_path(phandle_t package, char *buf, size_t len) { + return (OFW_PACKAGE_TO_PATH(ofw_obj, package, buf, len)); } /* Call the method in the scope of a given instance. */ int OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns, ...) { va_list ap; unsigned long args_n_results[12]; int n, status; if (nargs > 6) return (-1); va_start(ap, nreturns); for (n = 0; n < nargs; n++) args_n_results[n] = va_arg(ap, unsigned long); status = OFW_CALL_METHOD(ofw_obj, instance, method, nargs, nreturns, args_n_results); - if (status != 0) return (status); for (; n < nargs + nreturns; n++) *va_arg(ap, unsigned long *) = args_n_results[n]; va_end(ap); return (0); } /* * Device I/O functions */ /* Open an instance for a device. */ ihandle_t OF_open(const char *device) { + return (OFW_OPEN(ofw_obj, device)); } /* Close an instance. */ void OF_close(ihandle_t instance) { + OFW_CLOSE(ofw_obj, instance); } /* Read from an instance. */ ssize_t OF_read(ihandle_t instance, void *addr, size_t len) { + return (OFW_READ(ofw_obj, instance, addr, len)); } /* Write to an instance. */ ssize_t OF_write(ihandle_t instance, const void *addr, size_t len) { + return (OFW_WRITE(ofw_obj, instance, addr, len)); } /* Seek to a position. */ int OF_seek(ihandle_t instance, uint64_t pos) { + return (OFW_SEEK(ofw_obj, instance, pos)); } /* * Memory functions */ /* Claim an area of memory. */ void * OF_claim(void *virt, size_t size, u_int align) { + return (OFW_CLAIM(ofw_obj, virt, size, align)); } /* Release an area of memory. */ void OF_release(void *virt, size_t size) { + OFW_RELEASE(ofw_obj, virt, size); } /* * Control transfer functions */ /* Suspend and drop back to the Open Firmware interface. */ void OF_enter() { + OFW_ENTER(ofw_obj); } /* Shut down and drop back to the Open Firmware interface. */ void OF_exit() { + /* Should not return */ OFW_EXIT(ofw_obj); for (;;) /* just in case */ ; } - diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h index 614c4b2daf92..10e8aad80acd 100644 --- a/sys/dev/ofw/openfirm.h +++ b/sys/dev/ofw/openfirm.h @@ -1,143 +1,143 @@ /* $NetBSD: openfirm.h,v 1.1 1998/05/15 10:16:00 tsubai Exp $ */ /*- * Copyright (C) 1995, 1996 Wolfgang Solfrank. * Copyright (C) 1995, 1996 TooLs GmbH. * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by TooLs GmbH. * 4. The name of TooLs GmbH may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. */ /* * Copyright (C) 2000 Benno Rice. * 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 Benno Rice ``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 TOOLS GMBH 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 _OPENFIRM_H_ -#define _OPENFIRM_H_ +#ifndef _DEV_OPENFIRM_H_ +#define _DEV_OPENFIRM_H_ #include /* * Prototypes for Open Firmware Interface Routines */ -typedef uint32_t ihandle_t; +typedef uint32_t ihandle_t; typedef uint32_t phandle_t; typedef uint32_t pcell_t; #ifdef _KERNEL #include #include MALLOC_DECLARE(M_OFWPROP); /* - * Open Firmware interface initialization. OF_install installs the named + * Open Firmware interface initialization. OF_install installs the named * interface as the Open Firmware access mechanism, OF_init initializes it. */ boolean_t OF_install(char *name, int prio); void OF_init(void *cookie); /* * Known Open Firmware interface names */ #define OFW_STD_DIRECT "ofw_std" /* Standard OF interface */ #define OFW_STD_REAL "ofw_real" /* Real-mode OF interface */ #define OFW_FDT "ofw_fdt" /* Flattened Device Tree */ /* Generic functions */ -int OF_test(const char *); -void OF_printf(const char *, ...); +int OF_test(const char *name); +void OF_printf(const char *fmt, ...); /* Device tree functions */ phandle_t OF_peer(phandle_t node); phandle_t OF_child(phandle_t node); phandle_t OF_parent(phandle_t node); ssize_t OF_getproplen(phandle_t node, const char *propname); ssize_t OF_getprop(phandle_t node, const char *propname, void *buf, size_t len); -ssize_t OF_searchprop(phandle_t node, char *propname, void *buf, +ssize_t OF_searchprop(phandle_t node, const char *propname, void *buf, size_t len); ssize_t OF_getprop_alloc(phandle_t node, const char *propname, int elsz, void **buf); int OF_nextprop(phandle_t node, const char *propname, char *buf, size_t len); int OF_setprop(phandle_t node, const char *name, const void *buf, size_t len); ssize_t OF_canon(const char *path, char *buf, size_t len); phandle_t OF_finddevice(const char *path); ssize_t OF_package_to_path(phandle_t node, char *buf, size_t len); /* Device I/O functions */ ihandle_t OF_open(const char *path); void OF_close(ihandle_t instance); ssize_t OF_read(ihandle_t instance, void *buf, size_t len); ssize_t OF_write(ihandle_t instance, const void *buf, size_t len); int OF_seek(ihandle_t instance, uint64_t where); phandle_t OF_instance_to_package(ihandle_t instance); ssize_t OF_instance_to_path(ihandle_t instance, char *buf, size_t len); int OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns, ...); /* Memory functions */ -void *OF_claim(void *virtrequest, size_t size, u_int align); +void *OF_claim(void *virtrequest, size_t size, u_int align); void OF_release(void *virt, size_t size); /* Control transfer functions */ void OF_enter(void); void OF_exit(void) __attribute__((noreturn)); /* User interface functions */ int OF_interpret(const char *cmd, int nreturns, ...); #endif /* _KERNEL */ -#endif /* _OPENFIRM_H_ */ +#endif /* _DEV_OPENFIRM_H_ */ diff --git a/sys/dev/ofw/openfirmio.c b/sys/dev/ofw/openfirmio.c index d042f02d0b40..5803ec1d6c4a 100644 --- a/sys/dev/ofw/openfirmio.c +++ b/sys/dev/ofw/openfirmio.c @@ -1,302 +1,303 @@ /* $NetBSD: openfirmio.c,v 1.4 2002/09/06 13:23:19 gehenna Exp $ */ #include __FBSDID("$FreeBSD$"); /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This software was developed by the Computer Systems Engineering group * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and * contributed to Berkeley. * * All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Lawrence Berkeley Laboratory. * * 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. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. * * @(#)openfirm.c 8.1 (Berkeley) 6/11/93 * */ #include #include #include #include #include #include #include #include #include #include static struct cdev *openfirm_dev; static d_ioctl_t openfirm_ioctl; #define OPENFIRM_MINOR 0 static struct cdevsw openfirm_cdevsw = { .d_version = D_VERSION, .d_flags = D_NEEDGIANT, .d_ioctl = openfirm_ioctl, .d_name = "openfirm", }; static phandle_t lastnode; /* speed hack */ static int openfirm_checkid(phandle_t, phandle_t); static int openfirm_getstr(int, const char *, char **); /* * Verify target ID is valid (exists in the OPENPROM tree), as * listed from node ID sid forward. */ static int openfirm_checkid(phandle_t sid, phandle_t tid) { for (; sid != 0; sid = OF_peer(sid)) if (sid == tid || openfirm_checkid(OF_child(sid), tid)) return (1); return (0); } static int openfirm_getstr(int len, const char *user, char **cpp) { int error; char *cp; - /* Reject obvious bogus requests */ + /* Reject obvious bogus requests. */ if ((u_int)len > OFIOCMAXNAME) return (ENAMETOOLONG); *cpp = cp = malloc(len + 1, M_TEMP, M_WAITOK); if (cp == NULL) return (ENOMEM); error = copyin(user, cp, len); cp[len] = '\0'; return (error); } int openfirm_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td) { struct ofiocdesc *of; phandle_t node; int len, ok, error; char *name, *value; char newname[32]; if ((flags & FREAD) == 0) return (EBADF); of = (struct ofiocdesc *)data; switch (cmd) { case OFIOCGETOPTNODE: *(phandle_t *) data = OF_finddevice("/options"); return (0); case OFIOCGET: case OFIOCSET: case OFIOCNEXTPROP: case OFIOCFINDDEVICE: case OFIOCGETPROPLEN: node = of->of_nodeid; break; case OFIOCGETNEXT: case OFIOCGETCHILD: node = *(phandle_t *)data; break; default: return (ENOIOCTL); } if (node != 0 && node != lastnode) { - /* Not an easy one, must search for it */ + /* Not an easy one, we must search for it. */ ok = openfirm_checkid(OF_peer(0), node); if (!ok) return (EINVAL); lastnode = node; } name = value = NULL; error = 0; switch (cmd) { case OFIOCGET: case OFIOCGETPROPLEN: if (node == 0) return (EINVAL); error = openfirm_getstr(of->of_namelen, of->of_name, &name); if (error) break; len = OF_getproplen(node, name); if (cmd == OFIOCGETPROPLEN) { of->of_buflen = len; break; } if (len > of->of_buflen) { error = ENOMEM; break; } of->of_buflen = len; - /* -1 means no entry; 0 means no value */ + /* -1 means no entry; 0 means no value. */ if (len <= 0) break; value = malloc(len, M_TEMP, M_WAITOK); if (value == NULL) { error = ENOMEM; break; } len = OF_getprop(node, name, (void *)value, len); error = copyout(value, of->of_buf, len); break; case OFIOCSET: /* * Note: Text string values for at least the /options node * have to be null-terminated and the length parameter must - * include this terminating null. However, like OF_getprop(), + * include this terminating null. However, like OF_getprop(), * OF_setprop() will return the actual length of the text * string, i.e. omitting the terminating null. */ if ((flags & FWRITE) == 0) return (EBADF); if (node == 0) return (EINVAL); if ((u_int)of->of_buflen > OFIOCMAXVALUE) return (ENAMETOOLONG); error = openfirm_getstr(of->of_namelen, of->of_name, &name); if (error) break; value = malloc(of->of_buflen, M_TEMP, M_WAITOK); if (value == NULL) { error = ENOMEM; break; } error = copyin(of->of_buf, value, of->of_buflen); if (error) break; len = OF_setprop(node, name, value, of->of_buflen); if (len < 0) error = EINVAL; of->of_buflen = len; break; case OFIOCNEXTPROP: if (node == 0 || of->of_buflen < 0) return (EINVAL); if (of->of_namelen != 0) { error = openfirm_getstr(of->of_namelen, of->of_name, &name); if (error) break; } ok = OF_nextprop(node, name, newname, sizeof(newname)); if (ok == 0) { error = ENOENT; break; } if (ok == -1) { error = EINVAL; break; } len = strlen(newname) + 1; if (len > of->of_buflen) len = of->of_buflen; else of->of_buflen = len; error = copyout(newname, of->of_buf, len); break; case OFIOCGETNEXT: node = OF_peer(node); *(phandle_t *)data = lastnode = node; break; case OFIOCGETCHILD: if (node == 0) return (EINVAL); node = OF_child(node); *(phandle_t *)data = lastnode = node; break; case OFIOCFINDDEVICE: error = openfirm_getstr(of->of_namelen, of->of_name, &name); if (error) break; node = OF_finddevice(name); if (node == 0 || node == -1) { error = ENOENT; break; } of->of_nodeid = lastnode = node; break; } if (name != NULL) free(name, M_TEMP); if (value != NULL) free(value, M_TEMP); return (error); } static int openfirm_modevent(module_t mod, int type, void *data) { + switch(type) { case MOD_LOAD: if (bootverbose) printf("openfirm: \n"); /* * Allow only root access by default; this device may allow * users to peek into firmware passwords, and likely to crash * the machine on some boxen due to firmware quirks. */ openfirm_dev = make_dev(&openfirm_cdevsw, OPENFIRM_MINOR, UID_ROOT, GID_WHEEL, 0600, "openfirm"); return 0; case MOD_UNLOAD: destroy_dev(openfirm_dev); return 0; case MOD_SHUTDOWN: return 0; default: return EOPNOTSUPP; } } DEV_MODULE(openfirm, openfirm_modevent, NULL);