uart_cpu_amd64.c revision 127215
1119815Smarcel/*
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: head/sys/dev/uart/uart_cpu_amd64.c 127215 2004-03-20 02:14:02Z marcel $");
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
39127215Smarcelbus_space_tag_t uart_bus_space_io = AMD64_BUS_SPACE_IO;
40127215Smarcelbus_space_tag_t uart_bus_space_mem = AMD64_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{
52119815Smarcel	unsigned int i, ivar;
53119815Smarcel
54127215Smarcel	/* Check the environment. */
55127215Smarcel	if (uart_getenv(devtype, di) == 0)
56127215Smarcel		return (0);
57127215Smarcel
58119815Smarcel	/*
59119815Smarcel	 * Scan the hints. We only try units 0 to 3 (inclusive). This
60119815Smarcel	 * covers the ISA legacy where 4 UARTs had their resources
61119815Smarcel	 * predefined.
62119815Smarcel	 */
63119815Smarcel	for (i = 0; i < 4; i++) {
64119815Smarcel		if (resource_int_value("uart", i, "flags", &ivar))
65119815Smarcel			continue;
66119815Smarcel		if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar))
67119815Smarcel			continue;
68119815Smarcel		if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar))
69119815Smarcel			continue;
70119815Smarcel		/*
71119815Smarcel		 * We have a possible device. Make sure it's enabled and
72119815Smarcel		 * that we have an I/O port.
73119815Smarcel		 */
74119815Smarcel		if (resource_int_value("uart", i, "disabled", &ivar) == 0 &&
75119815Smarcel		    ivar != 0)
76119815Smarcel			continue;
77119815Smarcel		if (resource_int_value("uart", i, "port", &ivar) != 0 ||
78119815Smarcel		    ivar == 0)
79119815Smarcel			continue;
80119815Smarcel		/*
81119815Smarcel		 * Got it. Fill in the instance and return it. We only have
82119815Smarcel		 * ns8250 and successors on i386.
83119815Smarcel		 */
84119815Smarcel		di->ops = uart_ns8250_ops;
85120452Smarcel		di->bas.chan = 0;
86127215Smarcel		di->bas.bst = uart_bus_space_io;
87120376Snyan		if (bus_space_map(di->bas.bst, ivar, 8, 0, &di->bas.bsh) != 0)
88120381Snyan			continue;
89119815Smarcel		di->bas.regshft = 0;
90119815Smarcel		di->bas.rclk = 0;
91119815Smarcel		if (resource_int_value("uart", i, "baud", &ivar) != 0)
92119815Smarcel			ivar = 0;
93119815Smarcel		di->baudrate = ivar;
94119815Smarcel		di->databits = 8;
95119815Smarcel		di->stopbits = 1;
96119815Smarcel		di->parity = UART_PARITY_NONE;
97119815Smarcel		return (0);
98119815Smarcel	}
99119815Smarcel
100119815Smarcel	return (ENXIO);
101119815Smarcel}
102