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