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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/* $OpenBSD: kauaiata.c,v 1.8 2007/02/05 06:46:56 drahn Exp $ */
/*
* Copyright (c) 2003 Dale Rahn
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
*
*/
/*
* Glue to to attach kauai ata to the macobio_wdc
* which it heavily resembles.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/bus.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
#include <dev/ofw/openfirm.h>
#include <machine/autoconf.h>
struct kauaiata_softc {
struct device sc_dev;
struct ppc_bus_space sc_membus_space;
/* XXX */
};
int kauaiatamatch(struct device *parent, void *match, void *aux);
void kauaiataattach(struct device *parent, struct device *self, void *aux);
int kauaiata_print(void *aux, const char *dev);
struct cfattach kauaiata_ca = {
sizeof(struct kauaiata_softc), kauaiatamatch, kauaiataattach,
};
struct cfdriver kauaiata_cd = {
NULL, "kauaiata", DV_DULL,
};
int
kauaiatamatch(struct device *parent, void *match, void *aux)
{
struct pci_attach_args *pa = aux;
/*
* Match the adapter
* XXX match routine??
*/
switch(PCI_VENDOR(pa->pa_id)) {
case PCI_VENDOR_APPLE:
switch (PCI_PRODUCT(pa->pa_id)) {
case PCI_PRODUCT_APPLE_UNINORTH_ATA:
case PCI_PRODUCT_APPLE_INTREPID_ATA:
case PCI_PRODUCT_APPLE_INTREPID2_ATA:
case PCI_PRODUCT_APPLE_K2_ATA:
case PCI_PRODUCT_APPLE_SHASTA_ATA:
return (1);
}
break;
}
return 0;
}
void
kauaiataattach(struct device *parent, struct device *self, void *aux)
{
int node;
struct confargs ca;
int namelen;
u_int32_t reg[20];
char name[32];
int32_t intr[8];
struct kauaiata_softc *sc = (struct kauaiata_softc *)self;
struct pci_attach_args *pa = aux;
pci_chipset_tag_t pc = pa->pa_pc;
/* XXX not neccessarily the right device */
node = OF_finddevice("uata");
if (node == -1)
node = OF_finddevice("/pci@f4000000/ata-6");
/*
* XXX - need to compare node and PCI id to verify this is the
* correct device.
*/
ca.ca_nreg = OF_getprop(node, "reg", reg, sizeof(reg));
/*
* The PCI Interrupt Configuration Registers seems to be
* hardwired to 0. Get the interrupt line from OpenFirmware.
*/
/* XXX */
if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_ATA) {
ca.ca_nintr = OF_getprop(node, "interrupts",
intr, sizeof intr);
} else {
ca.ca_nintr = 4;
intr[0] = 0x27;
}
namelen = OF_getprop(node, "name", name, sizeof(name));
if ((namelen < 0) || (namelen >= sizeof(name))) {
printf(" bad name prop len %x\n", namelen);
return;
}
name[namelen] = 0; /* name property may not be null terminated */
/* config read */
sc->sc_membus_space.bus_base =
pci_conf_read(pc, pa->pa_tag, PCI_MAPREG_START);
/* make sure device memory access is enabled */
{
bus_space_tag_t iot;
bus_space_handle_t ioh;
bus_size_t size;
if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM, 0,
&iot, &ioh, NULL, &size, 0)) {
printf(": mapping memory failed\n");
return;
}
bus_space_unmap(iot, ioh, size);
}
#if 0
pci_conf_write(pc, pa->pa_tag, PCI_MAPREG_START, 0xffffffff);
size = ~(pci_conf_read(pc, pa->pa_tag, PCI_MAPREG_START));
pci_conf_write(pc, pa->pa_tag, PCI_MAPREG_START,
sc->sc_membus_space.bus_base);
#endif
ca.ca_baseaddr = sc->sc_membus_space.bus_base;
ca.ca_name = name;
ca.ca_iot = &sc->sc_membus_space;
ca.ca_dmat = pa->pa_dmat;
ca.ca_reg = reg;
reg[0] = 0x2000; /* offset to wdc registers */
reg[1] = reg[9] - 0x2000; /* map size of wdc registers */
reg[2] = 0x1000; /* offset to dbdma registers */
reg[3] = 0x1000; /* map size of dbdma registers */
ca.ca_intr = intr;
printf("\n");
config_found(self, &ca, kauaiata_print);
}
int
kauaiata_print(void *aux, const char *dev)
{
return QUIET;
}
|