uart_cpu_amd64.c revision 216592
116359Sasami/*- 216359Sasami * Copyright (c) 2003, 2004 Marcel Moolenaar 316359Sasami * All rights reserved. 416359Sasami * 516359Sasami * Redistribution and use in source and binary forms, with or without 637152Skato * modification, are permitted provided that the following conditions 716359Sasami * are met: 816359Sasami * 916359Sasami * 1. Redistributions of source code must retain the above copyright 1016359Sasami * notice, this list of conditions and the following disclaimer. 1116359Sasami * 2. Redistributions in binary form must reproduce the above copyright 1216359Sasami * notice, this list of conditions and the following disclaimer in the 1316359Sasami * documentation and/or other materials provided with the distribution. 1416359Sasami * 1516359Sasami * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1616359Sasami * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1716359Sasami * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1816359Sasami * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1916359Sasami * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2016359Sasami * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2130665Skato * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2237040Skato * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2330665Skato * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2425088Skato * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2525571Skato */ 2625088Skato 2725088Skato#include <sys/cdefs.h> 2827690Skato__FBSDID("$FreeBSD: head/sys/dev/uart/uart_cpu_amd64.c 216592 2010-12-20 16:39:43Z tijl $"); 2927690Skato 3016359Sasami#include <sys/param.h> 3116359Sasami#include <sys/systm.h> 3216359Sasami#include <sys/bus.h> 3316359Sasami 3416359Sasami#include <machine/bus.h> 3516359Sasami 3616359Sasami#include <dev/uart/uart.h> 3716359Sasami#include <dev/uart/uart_cpu.h> 3816359Sasami 3918846Sasamibus_space_tag_t uart_bus_space_io = X86_BUS_SPACE_IO; 4016359Sasamibus_space_tag_t uart_bus_space_mem = X86_BUS_SPACE_MEM; 4116359Sasami 4216359Sasamiint 4316359Sasamiuart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) 4416359Sasami{ 4516359Sasami 4625256Skato return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0); 4716359Sasami} 4816359Sasami 4927101Skatoint 5020494Skatouart_cpu_getdev(int devtype, struct uart_devinfo *di) 5127101Skato{ 5220494Skato struct uart_class *class; 5320494Skato unsigned int i, ivar; 5420494Skato 5520494Skato class = &uart_ns8250_class; 5620494Skato if (class == NULL) 5716359Sasami return (ENXIO); 5816359Sasami 5916359Sasami /* Check the environment. */ 6016359Sasami if (uart_getenv(devtype, di, class) == 0) 6116359Sasami return (0); 6216359Sasami 6316359Sasami /* 6416359Sasami * Scan the hints. We only try units 0 to 3 (inclusive). This 6516359Sasami * covers the ISA legacy where 4 UARTs had their resources 6616359Sasami * predefined. 6726058Skato */ 6826058Skato for (i = 0; i < 4; i++) { 6926058Skato if (resource_int_value("uart", i, "flags", &ivar)) 7026058Skato continue; 7126058Skato if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar)) 7224112Skato continue; 7316359Sasami if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar)) 7416359Sasami continue; 7516359Sasami /* 7616359Sasami * We have a possible device. Make sure it's enabled and 7735514Simp * that we have an I/O port. 7825088Skato */ 7926058Skato if (resource_int_value("uart", i, "disabled", &ivar) == 0 && 8035514Simp ivar != 0) 8116359Sasami continue; 8236367Skato if (resource_int_value("uart", i, "port", &ivar) != 0 || 8335514Simp ivar == 0) 8425088Skato continue; 8525571Skato /* 8626058Skato * Got it. Fill in the instance and return it. We only have 8735514Simp * ns8250 and successors on i386. 8825571Skato */ 8935514Simp di->ops = uart_getops(class); 9035514Simp di->bas.chan = 0; 9125571Skato di->bas.bst = uart_bus_space_io; 9225088Skato if (bus_space_map(di->bas.bst, ivar, uart_getrange(class), 0, 9326058Skato &di->bas.bsh) != 0) 9426058Skato continue; 9526058Skato di->bas.regshft = 0; 9635514Simp di->bas.rclk = 0; 9736367Skato if (resource_int_value("uart", i, "baud", &ivar) != 0) 9825088Skato ivar = 0; 9916359Sasami di->baudrate = ivar; 10016359Sasami di->databits = 8; 10116359Sasami di->stopbits = 1; 10216359Sasami di->parity = UART_PARITY_NONE; 10316359Sasami return (0); 10416359Sasami } 10516359Sasami 10616359Sasami return (ENXIO); 10716359Sasami} 10816359Sasami