uart_cpu_ia64.c revision 120378
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 120378 2003-09-23 09:25:38Z 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 47int 48uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) 49{ 50 51 return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0); 52} 53 54int 55uart_cpu_getdev(int devtype, struct uart_devinfo *di) 56{ 57 struct dig64_hcdp_table *tbl; 58 struct dig64_hcdp_entry *ent; 59 unsigned int i, ivar; 60 61 /* 62 * Use the DIG64 HCDP table if present. 63 */ 64 if (bootinfo.bi_hcdp != 0) { 65 tbl = (void*)IA64_PHYS_TO_RR7(bootinfo.bi_hcdp); 66 for (i = 0; i < tbl->entries; i++) { 67 ent = tbl->entry + i; 68 69 if (devtype == UART_DEV_CONSOLE && 70 ent->type != DIG64_HCDP_CONSOLE) 71 continue; 72 73 if (devtype == UART_DEV_DBGPORT && 74 ent->type != DIG64_HCDP_DBGPORT) 75 continue; 76 77 di->ops = uart_ns8250_ops; 78 di->bas.iobase = (ent->address.addr_high << 32) + 79 ent->address.addr_low; 80 di->bas.bst = IA64_BUS_SPACE_IO; 81 di->bas.bst = (ent->address.addr_space == 0) 82 ? IA64_BUS_SPACE_MEM : IA64_BUS_SPACE_IO; 83 if (bus_space_map(di->bas.bst, di->bas.iobase, 8, 0, 84 &di->bas.bsh) != 0) 85 return (ENXIO); 86 di->bas.regshft = 0; 87 di->bas.rclk = ent->pclock << 4; 88 /* We don't deal with 64-bit baud rates. */ 89 di->baudrate = ent->baud_low; 90 di->databits = ent->databits; 91 di->stopbits = ent->stopbits; 92 di->parity = (ent->parity >= 6) ? UART_PARITY_NONE 93 : dig64_to_uart_parity[ent->parity]; 94 return (0); 95 } 96 97 /* FALLTHROUGH */ 98 } 99 100 /* 101 * Scan the hints for backward compatibility. We only try units 102 * 0 to 3 (inclusive). This covers the ISA legacy where 4 UARTs 103 * had their resources predefined. 104 */ 105 for (i = 0; i < 4; i++) { 106 if (resource_int_value("uart", i, "flags", &ivar)) 107 continue; 108 if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar)) 109 continue; 110 if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar)) 111 continue; 112 /* 113 * We have a possible device. Make sure it's enabled and 114 * that we have an I/O port. 115 */ 116 if (resource_int_value("uart", i, "disabled", &ivar) == 0 && 117 ivar != 0) 118 continue; 119 if (resource_int_value("uart", i, "port", &ivar) != 0 || 120 ivar == 0) 121 continue; 122 /* 123 * Got it. Fill in the instance and return it. We only have 124 * ns8250 and successors on i386. 125 */ 126 di->ops = uart_ns8250_ops; 127 di->bas.iobase = ivar; 128 di->bas.bst = IA64_BUS_SPACE_IO; 129 if (bus_space_map(di->bas.bst, ivar, 8, 0, &di->bas.bsh) != 0) 130 return (ENXIO); 131 di->bas.regshft = 0; 132 di->bas.rclk = 0; 133 if (resource_int_value("uart", i, "baud", &ivar) != 0) 134 ivar = 0; 135 di->baudrate = ivar; 136 di->databits = 8; 137 di->stopbits = 1; 138 di->parity = UART_PARITY_NONE; 139 return (0); 140 } 141 142 return (ENXIO); 143} 144