cy_pci.c revision 41771
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.6 1997/09/02 20:06:24 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 <sys/param.h> 38#include <sys/systm.h> 39#include <sys/kernel.h> 40#include <vm/vm.h> 41#include <vm/pmap.h> 42 43#include <pci/pcivar.h> 44 45#include <pci/cy_pcireg.h> 46 47static const char *cy_probe __P((pcici_t, pcidi_t)); 48static void cy_attach __P((pcici_t, int)); 49 50extern int cyattach_common(void *, int); /* Not exactly correct */ 51extern void cyintr(int); 52 53static u_long cy_count; 54 55static struct pci_device cy_device = { 56 "cy", 57 cy_probe, 58 cy_attach, 59 &cy_count, 60 NULL 61}; 62DATA_SET(pcidevice_set, cy_device); 63 64static const char * 65cy_probe(config_id, device_id) 66 pcici_t config_id; 67 pcidi_t device_id; 68{ 69 if ((device_id & 0xffff) == CY_VENDORID_CYCLADES && 70 ((device_id >> 16) == CY_DEVICEID_CYCLOM_Y_1 || 71 (device_id >> 16) == CY_DEVICEID_CYCLOM_Y_2)) 72 return ("Cyclades Cyclom-Y Serial Adapter"); 73 return NULL; 74} 75 76static void 77cy_attach(config_id, unit) 78 pcici_t config_id; 79 int unit; 80{ 81 vm_offset_t paddr; 82 void *vaddr; 83 u_int32_t ioport; 84 int adapter; 85 86 ioport = (u_int32_t) pci_conf_read(config_id, CY_PCI_BASE_ADDR1) & ~0x3; 87 paddr = pci_conf_read(config_id, CY_PCI_BASE_ADDR2) & ~0xf; 88#if 0 89 if (!pci_map_mem(config_id, CY_PCI_BASE_ADDR2, &vaddr, &paddr)) { 90 printf("cy%d: couldn't map shared memory\n", unit); 91 return; 92 }; 93#endif 94 vaddr = pmap_mapdev(paddr, 0x4000); 95 96 adapter = cyattach_common(vaddr, 1); 97 if (adapter < 0) { 98 /* 99 * No ports found. Release resources and punt. 100 */ 101 printf("cy%d: no ports found!", unit); 102 goto fail; 103 } 104 105 /* 106 * Allocate our interrupt. 107 * XXX Using the ISA interrupt handler directly is a bit of a violation 108 * since it doesn't actually take the same argument. For PCI, the 109 * argument is a void * token, but for ISA it is a unit. Since 110 * there is no overlap in PCI/ISA unit numbers for this driver, and 111 * since the ISA driver must handle the interrupt anyway, we use 112 * the unit number as the token even for PCI. 113 */ 114 if (!pci_map_int(config_id, (pci_inthand_t *)cyintr, (void *)adapter, &tty_imask)) { 115 printf("cy%d: couldn't map interrupt\n", unit); 116 goto fail; 117 } 118 /* 119 * Enable the "local" interrupt input to generate a 120 * PCI interrupt. 121 */ 122 outw(ioport + CY_PLX_ICS, inw(ioport + CY_PLX_ICS) | 123 CY_PLX_ICS_IENABLE | CY_PLX_ICS_LOCAL_IENABLE); 124 125 return; 126 127fail: 128 /* XXX should release any allocated virtual memory */ 129 return; 130} 131 132#endif /* NPCI > 0 */ 133