cy_pci.c revision 46335
1/* 2 * Copyright (c) 1996, David Greenman 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 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * 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 AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $Id: cy_pci.c,v 1.12 1999/04/24 20:13:58 peter Exp $ 28 */ 29 30/* 31 * Cyclades Y PCI serial interface driver 32 */ 33 34#include "pci.h" 35#if NPCI > 0 36 37#include "opt_cy_pci_fastintr.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#include <vm/vm.h> 43#include <vm/pmap.h> 44 45#include <pci/pcivar.h> 46 47#include <pci/cy_pcireg.h> 48 49#ifdef CY_PCI_FASTINTR 50#include <i386/isa/intr_machdep.h> 51#endif 52 53static const char *cy_probe __P((pcici_t, pcidi_t)); 54static void cy_attach __P((pcici_t, int)); 55 56extern int cyattach_common(void *, int); /* Not exactly correct */ 57extern void cyintr(int); 58 59static u_long cy_count; 60 61static struct pci_device cy_device = { 62 "cy", 63 cy_probe, 64 cy_attach, 65 &cy_count, 66 NULL 67}; 68#ifdef COMPAT_PCI_DRIVER 69COMPAT_PCI_DRIVER(cy_pci, cy_device); 70#else 71DATA_SET(pcidevice_set, cy_device); 72#endif /* COMPAT_PCI_DRIVER */ 73 74static const char * 75cy_probe(config_id, device_id) 76 pcici_t config_id; 77 pcidi_t device_id; 78{ 79 if ((device_id & 0xffff) == CY_VENDORID_CYCLADES && 80 ((device_id >> 16) == CY_DEVICEID_CYCLOM_Y_1 || 81 (device_id >> 16) == CY_DEVICEID_CYCLOM_Y_2)) 82 return ("Cyclades Cyclom-Y Serial Adapter"); 83 return NULL; 84} 85 86static void 87cy_attach(config_id, unit) 88 pcici_t config_id; 89 int unit; 90{ 91 vm_offset_t paddr; 92 void *vaddr; 93 u_int32_t ioport; 94 int adapter; 95 u_char plx_ver; 96 97 ioport = (u_int32_t) pci_conf_read(config_id, CY_PCI_BASE_ADDR1) & ~0x3; 98 paddr = pci_conf_read(config_id, CY_PCI_BASE_ADDR2) & ~0xf; 99#if 0 100 if (!pci_map_mem(config_id, CY_PCI_BASE_ADDR2, &vaddr, &paddr)) { 101 printf("cy%d: couldn't map shared memory\n", unit); 102 return; 103 }; 104#endif 105 vaddr = pmap_mapdev(paddr, 0x4000); 106 107 adapter = cyattach_common(vaddr, 1); 108 if (adapter < 0) { 109 /* 110 * No ports found. Release resources and punt. 111 */ 112 printf("cy%d: no ports found!\n", unit); 113 goto fail; 114 } 115 116 /* 117 * Allocate our interrupt. 118 * XXX Using the ISA interrupt handler directly is a bit of a violation 119 * since it doesn't actually take the same argument. For PCI, the 120 * argument is a void * token, but for ISA it is a unit. Since 121 * there is no overlap in PCI/ISA unit numbers for this driver, and 122 * since the ISA driver must handle the interrupt anyway, we use 123 * the unit number as the token even for PCI. 124 */ 125 if ( 126#ifdef CY_PCI_FASTINTR 127 !pci_map_int_right(config_id, (pci_inthand_t *)cyintr, 128 (void *)adapter, &tty_imask, 129 INTR_EXCL | INTR_FAST) && 130#endif 131 !pci_map_int_right(config_id, (pci_inthand_t *)cyintr, 132 (void *)adapter, &tty_imask, 0)) { 133 printf("cy%d: couldn't map interrupt\n", unit); 134 goto fail; 135 } 136 137 /* 138 * Enable the "local" interrupt input to generate a 139 * PCI interrupt. 140 */ 141 plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f; 142 switch (plx_ver) { 143 case PLX_9050: 144 outw(ioport + CY_PLX_9050_ICS, 145 inw(ioport + CY_PLX_9050_ICS) | CY_PLX_9050_ICS_IENABLE | 146 CY_PLX_9050_ICS_LOCAL_IENABLE); 147 break; 148 case PLX_9060: 149 case PLX_9080: 150 default: /* Old board, use PLX_9060 values. */ 151 outw(ioport + CY_PLX_9060_ICS, 152 inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE | 153 CY_PLX_9060_ICS_LOCAL_IENABLE); 154 break; 155 } 156 157 return; 158 159fail: 160 /* XXX should release any allocated virtual memory */ 161 return; 162} 163 164#endif /* NPCI > 0 */ 165