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