cy_pci.c revision 42691
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.9 1999/01/11 23:43:54 bde 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/interrupt.h> 42#include <sys/kernel.h> 43#include <vm/vm.h> 44#include <vm/pmap.h> 45 46#include <pci/pcivar.h> 47 48#include <pci/cy_pcireg.h> 49 50static const char *cy_probe __P((pcici_t, pcidi_t)); 51static void cy_attach __P((pcici_t, int)); 52 53extern int cyattach_common(void *, int); /* Not exactly correct */ 54extern void cyintr(int); 55 56static u_long cy_count; 57 58static struct pci_device cy_device = { 59 "cy", 60 cy_probe, 61 cy_attach, 62 &cy_count, 63 NULL 64}; 65DATA_SET(pcidevice_set, cy_device); 66 67static const char * 68cy_probe(config_id, device_id) 69 pcici_t config_id; 70 pcidi_t device_id; 71{ 72 if ((device_id & 0xffff) == CY_VENDORID_CYCLADES && 73 ((device_id >> 16) == CY_DEVICEID_CYCLOM_Y_1 || 74 (device_id >> 16) == CY_DEVICEID_CYCLOM_Y_2)) 75 return ("Cyclades Cyclom-Y Serial Adapter"); 76 return NULL; 77} 78 79static void 80cy_attach(config_id, unit) 81 pcici_t config_id; 82 int unit; 83{ 84 vm_offset_t paddr; 85 void *vaddr; 86 u_int32_t ioport; 87 int adapter; 88 u_char plx_ver; 89 90 ioport = (u_int32_t) pci_conf_read(config_id, CY_PCI_BASE_ADDR1) & ~0x3; 91 paddr = pci_conf_read(config_id, CY_PCI_BASE_ADDR2) & ~0xf; 92#if 0 93 if (!pci_map_mem(config_id, CY_PCI_BASE_ADDR2, &vaddr, &paddr)) { 94 printf("cy%d: couldn't map shared memory\n", unit); 95 return; 96 }; 97#endif 98 vaddr = pmap_mapdev(paddr, 0x4000); 99 100 adapter = cyattach_common(vaddr, 1); 101 if (adapter < 0) { 102 /* 103 * No ports found. Release resources and punt. 104 */ 105 printf("cy%d: no ports found!", unit); 106 goto fail; 107 } 108 109 /* 110 * Allocate our interrupt. 111 * XXX Using the ISA interrupt handler directly is a bit of a violation 112 * since it doesn't actually take the same argument. For PCI, the 113 * argument is a void * token, but for ISA it is a unit. Since 114 * there is no overlap in PCI/ISA unit numbers for this driver, and 115 * since the ISA driver must handle the interrupt anyway, we use 116 * the unit number as the token even for PCI. 117 */ 118 if ( 119#ifdef CY_PCI_FASTINTR 120 !pci_map_int_right(config_id, (pci_inthand_t *)cyintr, 121 (void *)adapter, &tty_imask, 122 INTR_EXCL | INTR_FAST) && 123#endif 124 !pci_map_int_right(config_id, (pci_inthand_t *)cyintr, 125 (void *)adapter, &tty_imask, 0)) { 126 printf("cy%d: couldn't map interrupt\n", unit); 127 goto fail; 128 } 129 130 /* 131 * Enable the "local" interrupt input to generate a 132 * PCI interrupt. 133 */ 134 plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f; 135 switch (plx_ver) { 136 case PLX_9050: 137 outw(ioport + CY_PLX_9050_ICS, 138 inw(ioport + CY_PLX_9050_ICS) | CY_PLX_9050_ICS_IENABLE | 139 CY_PLX_9050_ICS_LOCAL_IENABLE); 140 break; 141 case PLX_9060: 142 case PLX_9080: 143 default: /* Old board, use PLX_9060 values. */ 144 outw(ioport + CY_PLX_9060_ICS, 145 inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE | 146 CY_PLX_9060_ICS_LOCAL_IENABLE); 147 break; 148 } 149 150 return; 151 152fail: 153 /* XXX should release any allocated virtual memory */ 154 return; 155} 156 157#endif /* NPCI > 0 */ 158