uart_cpu_ia64.c revision 120376
1/*
2 * Copyright (c) 2003 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/uart/uart_cpu_ia64.c 120376 2003-09-23 08:38:49Z nyan $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33
34#include <machine/bootinfo.h>
35#include <machine/bus.h>
36#include <machine/dig64.h>
37#include <machine/vmparam.h>
38
39#include <dev/uart/uart.h>
40#include <dev/uart/uart_cpu.h>
41
42static int dig64_to_uart_parity[] = {
43	UART_PARITY_NONE, UART_PARITY_NONE, UART_PARITY_EVEN,
44	UART_PARITY_ODD, UART_PARITY_MARK, UART_PARITY_SPACE
45};
46
47bus_addr_t
48uart_cpu_busaddr(struct uart_bas *bas)
49{
50
51	return (bas->bsh);
52}
53
54int
55uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
56{
57
58	return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0);
59}
60
61int
62uart_cpu_getdev(int devtype, struct uart_devinfo *di)
63{
64	struct dig64_hcdp_table *tbl;
65	struct dig64_hcdp_entry *ent;
66	unsigned int i, ivar;
67
68	/*
69	 * Use the DIG64 HCDP table if present.
70	 */
71	if (bootinfo.bi_hcdp != 0) {
72		tbl = (void*)IA64_PHYS_TO_RR7(bootinfo.bi_hcdp);
73		for (i = 0; i < tbl->entries; i++) {
74			ent = tbl->entry + i;
75
76			if (devtype == UART_DEV_CONSOLE &&
77			    ent->type != DIG64_HCDP_CONSOLE)
78				continue;
79
80			if (devtype == UART_DEV_DBGPORT &&
81			    ent->type != DIG64_HCDP_DBGPORT)
82				continue;
83
84			di->ops = uart_ns8250_ops;
85			di->bas.bst = IA64_BUS_SPACE_IO;
86			di->bas.bst = (ent->address.addr_space == 0)
87			    ? IA64_BUS_SPACE_MEM : IA64_BUS_SPACE_IO;
88			if (bus_space_map(di->bas.bst,
89					  (ent->address.addr_high << 32) +
90					  ent->address.addr_low,
91					  8, 0, &di->bas.bsh) != 0)
92				return (ENXIO);
93			di->bas.regshft = 0;
94			di->bas.rclk = ent->pclock << 4;
95			/* We don't deal with 64-bit baud rates. */
96			di->baudrate = ent->baud_low;
97			di->databits = ent->databits;
98			di->stopbits = ent->stopbits;
99			di->parity = (ent->parity >= 6) ? UART_PARITY_NONE
100			    : dig64_to_uart_parity[ent->parity];
101			return (0);
102		}
103
104		/* FALLTHROUGH */
105	}
106
107	/*
108	 * Scan the hints for backward compatibility. We only try units
109	 * 0 to 3 (inclusive). This covers the ISA legacy where 4 UARTs
110	 * had their resources predefined.
111	 */
112	for (i = 0; i < 4; i++) {
113		if (resource_int_value("uart", i, "flags", &ivar))
114			continue;
115		if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar))
116			continue;
117		if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar))
118			continue;
119		/*
120		 * We have a possible device. Make sure it's enabled and
121		 * that we have an I/O port.
122		 */
123		if (resource_int_value("uart", i, "disabled", &ivar) == 0 &&
124		    ivar != 0)
125			continue;
126		if (resource_int_value("uart", i, "port", &ivar) != 0 ||
127		    ivar == 0)
128			continue;
129		/*
130		 * Got it. Fill in the instance and return it. We only have
131		 * ns8250 and successors on i386.
132		 */
133		di->ops = uart_ns8250_ops;
134		di->bas.bst = IA64_BUS_SPACE_IO;
135		if (bus_space_map(di->bas.bst, ivar, 8, 0, &di->bas.bsh) != 0)
136			return (ENXIO);
137		di->bas.regshft = 0;
138		di->bas.rclk = 0;
139		if (resource_int_value("uart", i, "baud", &ivar) != 0)
140			ivar = 0;
141		di->baudrate = ivar;
142		di->databits = 8;
143		di->stopbits = 1;
144		di->parity = UART_PARITY_NONE;
145		return (0);
146	}
147
148	return (ENXIO);
149}
150