uart_cpu_amd64.c revision 120381
1119815Smarcel/* 2119815Smarcel * Copyright (c) 2003 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: head/sys/dev/uart/uart_cpu_amd64.c 120381 2003-09-23 13:03:22Z nyan $"); 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 39119815Smarcelint 40119866Smarceluart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) 41119866Smarcel{ 42119866Smarcel 43119866Smarcel return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0); 44119866Smarcel} 45119866Smarcel 46119866Smarcelint 47119815Smarceluart_cpu_getdev(int devtype, struct uart_devinfo *di) 48119815Smarcel{ 49119815Smarcel unsigned int i, ivar; 50119815Smarcel 51119815Smarcel /* 52119815Smarcel * Scan the hints. We only try units 0 to 3 (inclusive). This 53119815Smarcel * covers the ISA legacy where 4 UARTs had their resources 54119815Smarcel * predefined. 55119815Smarcel */ 56119815Smarcel for (i = 0; i < 4; i++) { 57119815Smarcel if (resource_int_value("uart", i, "flags", &ivar)) 58119815Smarcel continue; 59119815Smarcel if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar)) 60119815Smarcel continue; 61119815Smarcel if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar)) 62119815Smarcel continue; 63119815Smarcel /* 64119815Smarcel * We have a possible device. Make sure it's enabled and 65119815Smarcel * that we have an I/O port. 66119815Smarcel */ 67119815Smarcel if (resource_int_value("uart", i, "disabled", &ivar) == 0 && 68119815Smarcel ivar != 0) 69119815Smarcel continue; 70119815Smarcel if (resource_int_value("uart", i, "port", &ivar) != 0 || 71119815Smarcel ivar == 0) 72119815Smarcel continue; 73119815Smarcel /* 74119815Smarcel * Got it. Fill in the instance and return it. We only have 75119815Smarcel * ns8250 and successors on i386. 76119815Smarcel */ 77119815Smarcel di->ops = uart_ns8250_ops; 78120378Snyan di->bas.iobase = ivar; 79119815Smarcel di->bas.bst = AMD64_BUS_SPACE_IO; 80120376Snyan if (bus_space_map(di->bas.bst, ivar, 8, 0, &di->bas.bsh) != 0) 81120381Snyan continue; 82119815Smarcel di->bas.regshft = 0; 83119815Smarcel di->bas.rclk = 0; 84119815Smarcel if (resource_int_value("uart", i, "baud", &ivar) != 0) 85119815Smarcel ivar = 0; 86119815Smarcel di->baudrate = ivar; 87119815Smarcel di->databits = 8; 88119815Smarcel di->stopbits = 1; 89119815Smarcel di->parity = UART_PARITY_NONE; 90119815Smarcel return (0); 91119815Smarcel } 92119815Smarcel 93119815Smarcel return (ENXIO); 94119815Smarcel} 95