Index: conf/files =================================================================== RCS file: /home/ncvs/src/sys/conf/files,v retrieving revision 1.743 diff -u -r1.743 files --- conf/files 4 Jan 2003 22:07:48 -0000 1.743 +++ conf/files 8 Jan 2003 05:57:07 -0000 @@ -791,7 +791,8 @@ dev/xe/if_xe.c optional xe dev/xe/if_xe_pccard.c optional xe card dev/xe/if_xe_pccard.c optional xe pccard -dev/zs/zs.c optional zs sbus +dev/zs/zs.c optional zs +dev/zs/zs_sbus.c optional zs sbus fs/deadfs/dead_vnops.c standard fs/devfs/devfs_devs.c standard fs/devfs/devfs_rule.c standard Index: dev/zs/z8530var.h =================================================================== RCS file: dev/zs/z8530var.h diff -N dev/zs/z8530var.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dev/zs/z8530var.h 8 Jan 2003 06:22:10 -0000 @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2003 Jake Burkholder. + * 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 _DEV_ZS_ZSVAR_H_ +#define _DEV_ZS_ZSVAR_H_ + +struct zs_softc { + device_t sc_dev; + bus_space_tag_t sc_bt; + bus_space_handle_t sc_bh; + struct zstty_softc *sc_child[ZS_NCHAN]; + void *sc_softih; +}; + +int zs_attach(device_t dev); +int zs_probe(device_t dev); +void zs_intr(void *v); + +int zstty_keyboard(device_t dev); +int zstty_console(device_t dev, char *mode, int len); + +#endif Index: dev/zs/zs.c =================================================================== RCS file: /home/ncvs/src/sys/dev/zs/zs.c,v retrieving revision 1.3 diff -u -r1.3 zs.c --- dev/zs/zs.c 8 Jan 2003 04:30:30 -0000 1.3 +++ dev/zs/zs.c 8 Jan 2003 06:10:51 -0000 @@ -96,10 +96,8 @@ #include -#include -#include - #include +#include #define CDEV_MAJOR 182 @@ -147,19 +145,6 @@ uint8_t sc_obuf[CBLOCK]; }; -struct zs_softc { - device_t sc_dev; - bus_space_tag_t sc_bt; - bus_space_handle_t sc_bh; - struct zstty_softc *sc_child[ZS_NCHAN]; - void *sc_ih; - void *sc_softih; - struct resource *sc_irqres; - int sc_irqrid; - struct resource *sc_memres; - int sc_memrid; -}; - static uint8_t zs_init_reg[16] = { 0, /* 0: CMD (reset, etc.) */ 0, /* 1: No interrupts yet. */ @@ -179,17 +164,11 @@ ZSWR15_BREAK_IE, }; -static int zs_probe(device_t dev); -static int zs_attach(device_t dev); -static int zs_detach(device_t dev); - -static void zs_intr(void *v); static void zs_softintr(void *v); static void zs_shutdown(void *v); static int zstty_probe(device_t dev); static int zstty_attach(device_t dev); -static int zstty_detach(device_t dev); static int zstty_intr(struct zstty_softc *sc, uint8_t rr3); static void zstty_softintr(struct zstty_softc *sc) __unused; @@ -199,8 +178,6 @@ static void zstty_flush(struct zstty_softc *sc) __unused; static int zstty_speed(struct zstty_softc *sc, int rate); static void zstty_load_regs(struct zstty_softc *sc); -static int zstty_console(device_t dev, char *mode, int len); -static int zstty_keyboard(device_t dev); static cn_probe_t zs_cnprobe; static cn_init_t zs_cninit; @@ -239,92 +216,46 @@ /* kqfilter */ ttykqfilter, }; -static device_method_t zs_methods[] = { - DEVMETHOD(device_probe, zs_probe), - DEVMETHOD(device_attach, zs_attach), - DEVMETHOD(device_detach, zs_detach), - - DEVMETHOD(bus_print_child, bus_generic_print_child), - - { 0, 0 } -}; - static device_method_t zstty_methods[] = { DEVMETHOD(device_probe, zstty_probe), DEVMETHOD(device_attach, zstty_attach), - DEVMETHOD(device_detach, zstty_detach), + DEVMETHOD(device_detach, bus_generic_detach), { 0, 0 } }; -static driver_t zs_driver = { - "zs", - zs_methods, - sizeof(struct zs_softc), -}; - static driver_t zstty_driver = { "zstty", zstty_methods, sizeof(struct zstty_softc), }; -static devclass_t zs_devclass; static devclass_t zstty_devclass; static struct zstty_softc *zstty_cons; -DRIVER_MODULE(zs, sbus, zs_driver, zs_devclass, 0, 0); DRIVER_MODULE(zstty, zs, zstty_driver, zstty_devclass, 0, 0); CONS_DRIVER(zs, zs_cnprobe, zs_cninit, zs_cnterm, zs_cngetc, zs_cncheckc, zs_cnputc, zs_cndbctl); -static int +int zs_probe(device_t dev) { - if (strcmp(sbus_get_name(dev), "zs") != 0 || - device_get_unit(dev) != 0) - return (ENXIO); device_set_desc(dev, "Zilog Z8530"); return (0); } -static int +int zs_attach(device_t dev) { struct device *child[ZS_NCHAN]; - struct resource *irqres; - struct resource *memres; struct zs_softc *sc; - int irqrid; - int memrid; int i; - irqrid = 0; - irqres = NULL; - memres = NULL; - memrid = 0; sc = device_get_softc(dev); - memres = bus_alloc_resource(dev, SYS_RES_MEMORY, &memrid, 0, ~0, 1, - RF_ACTIVE); - if (memres == NULL) - goto error; - irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &irqrid, 0, ~0, 1, - RF_ACTIVE); - if (irqres == NULL) - goto error; - if (bus_setup_intr(dev, irqres, INTR_TYPE_TTY | INTR_FAST, zs_intr, - sc, &sc->sc_ih) != 0) - goto error; sc->sc_dev = dev; - sc->sc_irqres = irqres; - sc->sc_irqrid = irqrid; - sc->sc_memres = memres; - sc->sc_memrid = memrid; - sc->sc_bt = rman_get_bustag(memres); - sc->sc_bh = rman_get_bushandle(memres); for (i = 0; i < ZS_NCHAN; i++) child[i] = device_add_child(dev, "zstty", -1); @@ -347,23 +278,9 @@ SHUTDOWN_PRI_DEFAULT); return (0); - -error: - if (irqres != NULL) - bus_release_resource(dev, SYS_RES_IRQ, irqrid, irqres); - if (memres != NULL) - bus_release_resource(dev, SYS_RES_MEMORY, memrid, memres); - return (ENXIO); -} - -static int -zs_detach(device_t dev) -{ - - return (bus_generic_detach(dev)); } -static void +void zs_intr(void *v) { struct zs_softc *sc = v; @@ -515,13 +432,6 @@ return (0); } -static int -zstty_detach(device_t dev) -{ - - return (bus_generic_detach(dev)); -} - /* * Note that the rr3 value is shifted so the channel a status bits are in the * channel b bit positions, which makes the bit positions uniform for both @@ -1149,46 +1059,4 @@ ; ZS_WRITE(sc, ZS_DATA, c); zstty_cnclose(sc); -} - -static int -zstty_console(device_t dev, char *mode, int len) -{ - device_t parent; - phandle_t chosen; - phandle_t options; - ihandle_t stdin; - ihandle_t stdout; - char output[32]; - char input[32]; - char name[32]; - - parent = device_get_parent(dev); - chosen = OF_finddevice("/chosen"); - options = OF_finddevice("/options"); - if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1 || - OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1 || - OF_getprop(options, "input-device", input, sizeof(input)) == -1 || - OF_getprop(options, "output-device", output, sizeof(output)) == -1) - return (0); - if (sbus_get_node(parent) == OF_instance_to_package(stdin) && - sbus_get_node(parent) == OF_instance_to_package(stdout) && - strcmp(input, device_get_desc(dev)) == 0 && - strcmp(output, device_get_desc(dev)) == 0) { - if (mode != NULL) { - sprintf(name, "%s-mode", input); - return (OF_getprop(options, name, mode, len) != -1); - } else - return (1); - } - return (0); -} - -static int -zstty_keyboard(device_t dev) -{ - device_t parent; - - parent = device_get_parent(dev); - return (OF_getproplen(sbus_get_node(parent), "keyboard") == 0); } Index: dev/zs/zs_sbus.c =================================================================== RCS file: dev/zs/zs_sbus.c diff -N dev/zs/zs_sbus.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dev/zs/zs_sbus.c 8 Jan 2003 06:22:45 -0000 @@ -0,0 +1,171 @@ +/*- + * Copyright (c) 2003 Jake Burkholder. + * 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: src/sys/dev/zs/zs.c,v 1.3 2003/01/08 04:30:30 jake Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +struct zs_sbus_softc { + struct zs_softc sc_zs; + struct resource *sc_irqres; + int sc_irqrid; + void *sc_ih; + struct resource *sc_memres; + int sc_memrid; +}; + +static int zs_sbus_attach(device_t dev); +static int zs_sbus_detach(device_t dev); +static int zs_sbus_probe(device_t dev); + +static device_method_t zs_sbus_methods[] = { + DEVMETHOD(device_probe, zs_sbus_probe), + DEVMETHOD(device_attach, zs_sbus_attach), + DEVMETHOD(device_detach, zs_sbus_detach), + + DEVMETHOD(bus_print_child, bus_generic_print_child), + + { 0, 0 } +}; + +static driver_t zs_sbus_driver = { + "zs", + zs_sbus_methods, + sizeof(struct zs_sbus_softc), +}; + +static devclass_t zs_sbus_devclass; + +DRIVER_MODULE(zs, sbus, zs_sbus_driver, zs_sbus_devclass, 0, 0); + +static int +zs_sbus_probe(device_t dev) +{ + + if (strcmp(sbus_get_name(dev), "zs") != 0 || + device_get_unit(dev) != 0) + return (ENXIO); + return (zs_probe(dev)); +} + +static int +zs_sbus_attach(device_t dev) +{ + struct zs_sbus_softc *sc; + + sc = device_get_softc(dev); + sc->sc_memres = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->sc_memrid, + 0, ~0, 1, RF_ACTIVE); + if (sc->sc_memres == NULL) + goto error; + sc->sc_irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irqrid, 0, + ~0, 1, RF_ACTIVE); + if (sc->sc_irqres == NULL) + goto error; + if (bus_setup_intr(dev, sc->sc_irqres, INTR_TYPE_TTY | INTR_FAST, + zs_intr, sc, &sc->sc_ih) != 0) + goto error; + sc->sc_zs.sc_bt = rman_get_bustag(sc->sc_memres); + sc->sc_zs.sc_bh = rman_get_bushandle(sc->sc_memres); + return (zs_attach(dev)); + +error: + zs_sbus_detach(dev); + return (ENXIO); +} + +static int +zs_sbus_detach(device_t dev) +{ + struct zs_sbus_softc *sc; + + sc = device_get_softc(dev); + if (sc->sc_irqres != NULL) { + if (sc->sc_ih != NULL) + bus_teardown_intr(dev, sc->sc_irqres, sc->sc_ih); + bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid, + sc->sc_irqres); + } + if (sc->sc_memres != NULL) + bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_memrid, + sc->sc_memres); + return (0); +} + +int +zstty_console(device_t dev, char *mode, int len) +{ + device_t parent; + phandle_t chosen; + phandle_t options; + ihandle_t stdin; + ihandle_t stdout; + char output[32]; + char input[32]; + char name[32]; + + parent = device_get_parent(dev); + chosen = OF_finddevice("/chosen"); + options = OF_finddevice("/options"); + if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1 || + OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1 || + OF_getprop(options, "input-device", input, sizeof(input)) == -1 || + OF_getprop(options, "output-device", output, sizeof(output)) == -1) + return (0); + if (sbus_get_node(parent) == OF_instance_to_package(stdin) && + sbus_get_node(parent) == OF_instance_to_package(stdout) && + strcmp(input, device_get_desc(dev)) == 0 && + strcmp(output, device_get_desc(dev)) == 0) { + if (mode != NULL) { + sprintf(name, "%s-mode", input); + return (OF_getprop(options, name, mode, len) != -1); + } else + return (1); + } + return (0); +} + +int +zstty_keyboard(device_t dev) +{ + device_t parent; + + parent = device_get_parent(dev); + return (OF_getproplen(sbus_get_node(parent), "keyboard") == 0); +}