summaryrefslogtreecommitdiffstats
path: root/sys/pci/if_ar_p.c
blob: ad2bfa0bc0eb1e6baced51727ed11405e2ab404c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * Copyright (c) 1999 - 2001 John Hay.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the author nor the names of any co-contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <machine/bus_pio.h>
#include <machine/bus_memio.h>
#include <sys/rman.h>

#include <pci/pcireg.h>
#include <pci/pcivar.h>

#include <i386/isa/ic/hd64570.h>
#include <i386/isa/if_arregs.h>

#ifdef TRACE
#define TRC(x)               x
#else
#define TRC(x)
#endif

#define TRCL(x)              x

static int	ar_pci_probe(device_t);
static int	ar_pci_attach(device_t);

static device_method_t ar_pci_methods[] = {
	/* Device interface */
	DEVMETHOD(device_probe,		ar_pci_probe),
	DEVMETHOD(device_attach,	ar_pci_attach),
	DEVMETHOD(device_detach,	ar_detach),
	{ 0, 0 }
};

static driver_t ar_pci_driver = {
	"ar",
	ar_pci_methods,
	sizeof(struct ar_hardc),
};

DRIVER_MODULE(if_ar, pci, ar_pci_driver, ar_devclass, 0, 0);

static int
ar_pci_probe(device_t device)
{
	u_int32_t	type = pci_get_devid(device);

	switch(type) {
	case 0x5012114f:
		device_set_desc(device, "Digi SYNC/570i-PCI 2 port");
		return (0);
		break;
	case 0x5010114f:
		printf("Digi SYNC/570i-PCI 2 port (mapped below 1M)\n");
		printf("Please change the jumper to select linear mode.\n");
		break;
	case 0x5013114f:
		device_set_desc(device, "Digi SYNC/570i-PCI 4 port");
		return (0);
		break;
	case 0x5011114f:
		printf("Digi SYNC/570i-PCI 4 port (mapped below 1M)\n");
		printf("Please change the jumper to select linear mode.\n");
		break;
	default:
		break;
	}
	return (ENXIO);
}

static int
ar_pci_attach(device_t device)
{
	int error;
	u_int i, tmp;
	u_char *inten;
	struct ar_hardc *hc;

	hc = (struct ar_hardc *)device_get_softc(device);
	bzero(hc, sizeof(struct ar_hardc));

	error = ar_allocate_plx_memory(device, 0x10, 1);
	if(error)
		goto errexit;

	error = ar_allocate_memory(device, 0x18, 1);
	if(error)
		goto errexit;

	error = ar_allocate_irq(device, 0, 1);
	if(error)
		goto errexit;

	hc->plx_mem = rman_get_virtual(hc->res_plx_memory);
	hc->mem_start = rman_get_virtual(hc->res_memory);

	hc->cunit = device_get_unit(device);
	hc->sca[0] = (sca_regs *)(hc->mem_start + AR_PCI_SCA_1_OFFSET);
	hc->sca[1] = (sca_regs *)(hc->mem_start + AR_PCI_SCA_2_OFFSET);
	hc->iobase = 0;
	hc->orbase = (u_char *)(hc->mem_start + AR_PCI_ORBASE_OFFSET);

	tmp = hc->orbase[AR_BMI * 4];
	hc->bustype = tmp & AR_BUS_MSK;
	hc->memsize = (tmp & AR_MEM_MSK) >> AR_MEM_SHFT;
	hc->memsize = 1 << hc->memsize;
	hc->memsize <<= 16;
	hc->interface[0] = (tmp & AR_IFACE_MSK);
	tmp = hc->orbase[AR_REV * 4];
	hc->revision = tmp & AR_REV_MSK;
	hc->winsize = (1 << ((tmp & AR_WSIZ_MSK) >> AR_WSIZ_SHFT)) * 16 * 1024;
	hc->mem_end = (caddr_t)(hc->mem_start + hc->winsize);
	hc->winmsk = hc->winsize - 1;
	hc->numports = hc->orbase[AR_PNUM * 4];
	hc->handshake = hc->orbase[AR_HNDSH * 4];

	for(i = 1; i < hc->numports; i++)
		hc->interface[i] = hc->interface[0];

	TRC(printf("arp%d: bus %x, rev %d, memstart %p, winsize %d, "
	    "winmsk %x, interface %x\n",
	    unit, hc->bustype, hc->revision, hc->mem_start, hc->winsize,
	    hc->winmsk, hc->interface[0]));

	ar_attach(device);

	/* Magic to enable the card to generate interrupts. */
	inten = (u_char *)hc->plx_mem;
	inten[0x69] = 0x09;

	return (0);

errexit:
	ar_deallocate_resources(device);
	return (ENXIO);
}

OpenPOWER on IntegriCloud