diff options
| author | Marcel Moolenaar <marcel@FreeBSD.org> | 2004-04-02 07:33:35 +0000 |
|---|---|---|
| committer | Marcel Moolenaar <marcel@FreeBSD.org> | 2004-04-02 07:33:35 +0000 |
| commit | 16283d130f5c65a3cb9894bb22a60bc2bb1330b0 (patch) | |
| tree | f9e307742af646e83f2f3e33eb3557048ff15922 /sys/dev/uart/uart_cpu_sparc64.c | |
| parent | af81ff3f490cce8931d10f066274f8cd451b3777 (diff) | |
Notes
Diffstat (limited to 'sys/dev/uart/uart_cpu_sparc64.c')
| -rw-r--r-- | sys/dev/uart/uart_cpu_sparc64.c | 130 |
1 files changed, 84 insertions, 46 deletions
diff --git a/sys/dev/uart/uart_cpu_sparc64.c b/sys/dev/uart/uart_cpu_sparc64.c index ea9c60dada42..a429441887d7 100644 --- a/sys/dev/uart/uart_cpu_sparc64.c +++ b/sys/dev/uart/uart_cpu_sparc64.c @@ -42,8 +42,6 @@ __FBSDID("$FreeBSD$"); bus_space_tag_t uart_bus_space_io; bus_space_tag_t uart_bus_space_mem; -static phandle_t uart_cpu_getdev_keyboard(phandle_t root); - static struct bus_space_tag bst_store[3]; static int @@ -70,21 +68,79 @@ uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) return ((b1->bsh == b2->bsh) ? 1 : 0); } +/* + * Get the address of the UART that is selected as the console, if the + * console is an UART of course. Note that we enforce that both stdin and + * stdout are selected. For weird configurations, use ofw_console(4). + * Note that the currently active console (i.e. /chosen/stdout and + * /chosen/stdin) may not be the same as the device selected in the + * environment (ie /options/output-device and /options/input-device) because + * the user may have changed the environment. In that case I would assume + * that the user expects that FreeBSD uses the new console setting. There's + * no choice, really. + */ +static phandle_t +uart_cpu_getdev_console(phandle_t options, char *dev, size_t devsz) +{ + char buf[32]; + phandle_t input; + + if (OF_getprop(options, "input-device", dev, devsz) == -1) + return (-1); + if ((input = OF_finddevice(dev)) == -1) + return (-1); + if (OF_getprop(input, "device_type", buf, sizeof(buf)) == -1) + return (-1); + if (strcmp(buf, "serial") != 0) + return (-1); + if (OF_getprop(options, "output-device", buf, sizeof(buf)) == -1) + return (-1); + if (OF_finddevice(buf) != input) + return (-1); + return (input); +} + +/* + * Get the address of the UART that's selected as the debug port. Since + * there's no place for this in the OF, we use the kernel environment + * variable "hw.uart.dbgport". Note however that the variable is not a + * list of attributes. It's single device name or alias, as known by + * the OF. + */ +static phandle_t +uart_cpu_getdev_dbgport(phandle_t options, char *dev, size_t devsz) +{ + char buf[32]; + phandle_t input; + + if (!getenv_string("hw.uart.dbgport", dev, devsz)) + return (-1); + if ((input = OF_finddevice(dev)) == -1) + return (-1); + if (OF_getprop(input, "device_type", buf, sizeof(buf)) == -1) + return (-1); + if (strcmp(buf, "serial") != 0) + return (-1); + return (input); +} + static phandle_t -uart_cpu_getdev_keyboard(phandle_t root) +uart_cpu_getdev_keyboard(phandle_t root, char *dev, size_t devsz) { - phandle_t child; - phandle_t node; char buf[32]; + phandle_t child, node; - for (child = OF_child(root); child != 0 && child != -1; - child = OF_peer(child)) { + child = OF_child(root); + while (child != 0 && child != -1) { if (OF_getprop(child, "device_type", buf, sizeof(buf)) != -1 && !strcmp(buf, "serial") && - OF_getprop(child, "keyboard", buf, sizeof(buf)) != -1) + OF_getprop(child, "keyboard", buf, sizeof(buf)) != -1) { + OF_getprop(child, "name", dev, devsz); return (child); - if ((node = uart_cpu_getdev_keyboard(child)) != -1) + } + if ((node = uart_cpu_getdev_keyboard(child, dev, devsz)) != -1) return (node); + child = OF_peer(child); } return (-1); } @@ -93,47 +149,29 @@ int uart_cpu_getdev(int devtype, struct uart_devinfo *di) { char buf[32], dev[32], compat[32]; - phandle_t input, options, output; + phandle_t input, options; bus_addr_t addr; int baud, bits, error, space, stop; char flag, par; - /* - * Get the address of the UART that is selected as the console, if - * the console is an UART of course. Note that we enforce that both - * stdin and stdout are selected. For weird configurations, use - * ofw_console(4). - * Note that the currently active console (ie /chosen/stdout and - * /chosen/stdin) may not be the same as the device selected in the - * environment (ie /options/output-device and /options/input-device) - * because the user may have changed the environment. In that case - * I would assume that the user expects that FreeBSD uses the new - * console setting. There's choice choice, really. - */ - if ((options = OF_finddevice("/options")) == -1) - return (ENXIO); - if (devtype == UART_DEV_CONSOLE) { - if (OF_getprop(options, "input-device", dev, sizeof(dev)) == -1) - return (ENXIO); - if ((input = OF_finddevice(dev)) == -1) - return (ENXIO); - if (OF_getprop(input, "device_type", buf, sizeof(buf)) == -1) - return (ENXIO); - if (strcmp(buf, "serial")) - return (ENODEV); - if (OF_getprop(options, "output-device", buf, sizeof(buf)) - == -1) - return (ENXIO); - if ((output = OF_finddevice(buf)) == -1) - return (ENXIO); - if (input != output) - return (ENXIO); - } else if (devtype == UART_DEV_KEYBOARD) { - if ((input = uart_cpu_getdev_keyboard(OF_peer(0))) == -1) - return (ENXIO); - } else - return (ENODEV); - + if ((options = OF_finddevice("/options")) == -1) + return (ENXIO); + switch (devtype) { + case UART_DEV_CONSOLE: + input = uart_cpu_getdev_console(options, dev, sizeof(dev)); + break; + case UART_DEV_DBGPORT: + input = uart_cpu_getdev_dbgport(options, dev, sizeof(dev)); + break; + case UART_DEV_KEYBOARD: + input = uart_cpu_getdev_keyboard(OF_peer(0), dev, sizeof(dev)); + break; + default: + input = -1; + break; + } + if (input == -1) + return (ENXIO); error = OF_decode_addr(input, &space, &addr); if (error) return (error); |
