1139749Simp/*- 2127215Smarcel * Copyright (c) 2003, 2004 Marcel Moolenaar 3119815Smarcel * All rights reserved. 4119815Smarcel * 5119815Smarcel * Redistribution and use in source and binary forms, with or without 6119815Smarcel * modification, are permitted provided that the following conditions 7119815Smarcel * are met: 8119815Smarcel * 9119815Smarcel * 1. Redistributions of source code must retain the above copyright 10119815Smarcel * notice, this list of conditions and the following disclaimer. 11119815Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12119815Smarcel * notice, this list of conditions and the following disclaimer in the 13119815Smarcel * documentation and/or other materials provided with the distribution. 14119815Smarcel * 15119815Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16119815Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17119815Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18119815Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19119815Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20119815Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21119815Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22119815Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23119815Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24119815Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25119815Smarcel */ 26119815Smarcel 27119815Smarcel#include <sys/cdefs.h> 28119815Smarcel__FBSDID("$FreeBSD$"); 29119815Smarcel 30119815Smarcel#include <sys/param.h> 31119815Smarcel#include <sys/systm.h> 32119815Smarcel#include <sys/bus.h> 33119815Smarcel 34119815Smarcel#include <machine/bus.h> 35119815Smarcel 36119815Smarcel#include <dev/uart/uart.h> 37119815Smarcel#include <dev/uart/uart_cpu.h> 38119815Smarcel 39216592Stijlbus_space_tag_t uart_bus_space_io = X86_BUS_SPACE_IO; 40216592Stijlbus_space_tag_t uart_bus_space_mem = X86_BUS_SPACE_MEM; 41127215Smarcel 42119815Smarcelint 43119866Smarceluart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) 44119866Smarcel{ 45119866Smarcel 46119866Smarcel return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0); 47119866Smarcel} 48119866Smarcel 49119866Smarcelint 50119815Smarceluart_cpu_getdev(int devtype, struct uart_devinfo *di) 51119815Smarcel{ 52168281Smarcel struct uart_class *class; 53119815Smarcel unsigned int i, ivar; 54119815Smarcel 55168281Smarcel class = &uart_ns8250_class; 56168281Smarcel if (class == NULL) 57168281Smarcel return (ENXIO); 58168281Smarcel 59127215Smarcel /* Check the environment. */ 60168281Smarcel if (uart_getenv(devtype, di, class) == 0) 61127215Smarcel return (0); 62127215Smarcel 63119815Smarcel /* 64119815Smarcel * Scan the hints. We only try units 0 to 3 (inclusive). This 65119815Smarcel * covers the ISA legacy where 4 UARTs had their resources 66119815Smarcel * predefined. 67119815Smarcel */ 68119815Smarcel for (i = 0; i < 4; i++) { 69119815Smarcel if (resource_int_value("uart", i, "flags", &ivar)) 70119815Smarcel continue; 71119815Smarcel if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar)) 72119815Smarcel continue; 73119815Smarcel if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar)) 74119815Smarcel continue; 75119815Smarcel /* 76119815Smarcel * We have a possible device. Make sure it's enabled and 77119815Smarcel * that we have an I/O port. 78119815Smarcel */ 79119815Smarcel if (resource_int_value("uart", i, "disabled", &ivar) == 0 && 80119815Smarcel ivar != 0) 81119815Smarcel continue; 82119815Smarcel if (resource_int_value("uart", i, "port", &ivar) != 0 || 83119815Smarcel ivar == 0) 84119815Smarcel continue; 85119815Smarcel /* 86119815Smarcel * Got it. Fill in the instance and return it. We only have 87119815Smarcel * ns8250 and successors on i386. 88119815Smarcel */ 89168281Smarcel di->ops = uart_getops(class); 90120452Smarcel di->bas.chan = 0; 91127215Smarcel di->bas.bst = uart_bus_space_io; 92168281Smarcel if (bus_space_map(di->bas.bst, ivar, uart_getrange(class), 0, 93168281Smarcel &di->bas.bsh) != 0) 94120381Snyan continue; 95119815Smarcel di->bas.regshft = 0; 96119815Smarcel di->bas.rclk = 0; 97119815Smarcel if (resource_int_value("uart", i, "baud", &ivar) != 0) 98119815Smarcel ivar = 0; 99119815Smarcel di->baudrate = ivar; 100119815Smarcel di->databits = 8; 101119815Smarcel di->stopbits = 1; 102119815Smarcel di->parity = UART_PARITY_NONE; 103119815Smarcel return (0); 104119815Smarcel } 105119815Smarcel 106119815Smarcel return (ENXIO); 107119815Smarcel} 108