uart_cpu_x86.c revision 133735
1100978Srwatson/*
2126097Srwatson * Copyright (c) 2003, 2004 Marcel Moolenaar
3145167Srwatson * All rights reserved.
4163606Srwatson *
5100978Srwatson * Redistribution and use in source and binary forms, with or without
6100978Srwatson * modification, are permitted provided that the following conditions
7100978Srwatson * are met:
8100978Srwatson *
9106392Srwatson * 1. Redistributions of source code must retain the above copyright
10106392Srwatson *    notice, this list of conditions and the following disclaimer.
11106392Srwatson * 2. Redistributions in binary form must reproduce the above copyright
12106392Srwatson *    notice, this list of conditions and the following disclaimer in the
13100978Srwatson *    documentation and/or other materials provided with the distribution.
14147784Srwatson *
15147784Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16147784Srwatson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17100978Srwatson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18100978Srwatson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19100978Srwatson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20100978Srwatson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21100978Srwatson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22100978Srwatson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23100978Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24100978Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25100978Srwatson */
26100978Srwatson
27100978Srwatson#include <sys/cdefs.h>
28100978Srwatson__FBSDID("$FreeBSD: head/sys/dev/uart/uart_cpu_amd64.c 133735 2004-08-14 23:54:27Z marius $");
29100978Srwatson
30100978Srwatson#include <sys/param.h>
31100978Srwatson#include <sys/systm.h>
32100978Srwatson#include <sys/bus.h>
33100978Srwatson
34100978Srwatson#include <machine/bus.h>
35100978Srwatson
36100978Srwatson#include <dev/uart/uart.h>
37100978Srwatson#include <dev/uart/uart_cpu.h>
38100978Srwatson
39100978Srwatsonbus_space_tag_t uart_bus_space_io = AMD64_BUS_SPACE_IO;
40145167Srwatsonbus_space_tag_t uart_bus_space_mem = AMD64_BUS_SPACE_MEM;
41100978Srwatson
42163606Srwatsonint
43163606Srwatsonuart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
44102123Srwatson{
45102123Srwatson
46163606Srwatson	return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0);
47163686Srwatson}
48105693Srwatson
49105693Srwatsonint
50163606Srwatsonuart_cpu_getdev(int devtype, struct uart_devinfo *di)
51163606Srwatson{
52105693Srwatson	unsigned int i, ivar;
53168933Srwatson
54171047Srwatson	/* Check the environment. */
55100978Srwatson	if (uart_getenv(devtype, di) == 0)
56130585Sphk		return (0);
57100978Srwatson
58100978Srwatson	/*
59100978Srwatson	 * Scan the hints. We only try units 0 to 3 (inclusive). This
60100978Srwatson	 * covers the ISA legacy where 4 UARTs had their resources
61106468Srwatson	 * predefined.
62122875Srwatson	 */
63100978Srwatson	for (i = 0; i < 4; i++) {
64145855Srwatson		if (resource_int_value("uart", i, "flags", &ivar))
65166533Srwatson			continue;
66113487Srwatson		if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar))
67163606Srwatson			continue;
68100978Srwatson		if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar))
69100978Srwatson			continue;
70137815Srwatson		/*
71137815Srwatson		 * We have a possible device. Make sure it's enabled and
72100978Srwatson		 * that we have an I/O port.
73137815Srwatson		 */
74137815Srwatson		if (resource_int_value("uart", i, "disabled", &ivar) == 0 &&
75100978Srwatson		    ivar != 0)
76100978Srwatson			continue;
77126121Spjd		if (resource_int_value("uart", i, "port", &ivar) != 0 ||
78126121Spjd		    ivar == 0)
79125293Srwatson			continue;
80104338Srwatson		/*
81100978Srwatson		 * Got it. Fill in the instance and return it. We only have
82100978Srwatson		 * ns8250 and successors on i386.
83100978Srwatson		 */
84100978Srwatson		di->ops = uart_ns8250_ops;
85100978Srwatson		di->bas.chan = 0;
86163606Srwatson		di->bas.bst = uart_bus_space_io;
87100978Srwatson		if (bus_space_map(di->bas.bst, ivar, 8, 0, &di->bas.bsh) != 0)
88100978Srwatson			continue;
89100978Srwatson		di->bas.regshft = 0;
90100978Srwatson		di->bas.rclk = 0;
91163606Srwatson		if (resource_int_value("uart", i, "baud", &ivar) != 0)
92100978Srwatson			ivar = 0;
93172990Srwatson		di->baudrate = ivar;
94172990Srwatson		di->databits = 8;
95172990Srwatson		di->stopbits = 1;
96172990Srwatson		di->parity = UART_PARITY_NONE;
97172930Srwatson		return (0);
98172990Srwatson	}
99172990Srwatson
100172990Srwatson	return (ENXIO);
101172990Srwatson}
102172930Srwatson
103100978Srwatsonvoid
104172930Srwatsonuart_cpu_identify(driver_t *driver, device_t parent)
105147982Srwatson{
106172930Srwatson
107107698Srwatson}
108172930Srwatson