[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / mips / pci / ops-tx3927.c
blob0e0daadc303d547d2fc9241a322f26db6717d8f6
1 /*
2 * Copyright 2001 MontaVista Software Inc.
3 * Author: MontaVista Software, Inc.
4 * ahennessy@mvista.com
6 * Copyright (C) 2000-2001 Toshiba Corporation
7 * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
9 * Based on arch/mips/ddb5xxx/ddb5477/pci_ops.c
11 * Define the pci_ops for JMR3927.
13 * Much of the code is derived from the original DDB5074 port by
14 * Geert Uytterhoeven <geert@sonycom.com>
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at your
19 * option) any later version.
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
24 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * You should have received a copy of the GNU General Public License along
33 * with this program; if not, write to the Free Software Foundation, Inc.,
34 * 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <linux/types.h>
37 #include <linux/pci.h>
38 #include <linux/kernel.h>
39 #include <linux/init.h>
41 #include <asm/addrspace.h>
42 #include <asm/jmr3927/jmr3927.h>
43 #include <asm/debug.h>
45 static inline int mkaddr(unsigned char bus, unsigned char dev_fn,
46 unsigned char where)
48 if (bus == 0 && dev_fn >= PCI_DEVFN(TX3927_PCIC_MAX_DEVNU, 0))
49 return PCIBIOS_DEVICE_NOT_FOUND;
51 tx3927_pcicptr->ica = ((bus & 0xff) << 0x10) |
52 ((dev_fn & 0xff) << 0x08) |
53 (where & 0xfc);
55 /* clear M_ABORT and Disable M_ABORT Int. */
56 tx3927_pcicptr->pcistat |= PCI_STATUS_REC_MASTER_ABORT;
57 tx3927_pcicptr->pcistatim &= ~PCI_STATUS_REC_MASTER_ABORT;
59 return PCIBIOS_SUCCESSFUL;
62 static inline int check_abort(void)
64 if (tx3927_pcicptr->pcistat & PCI_STATUS_REC_MASTER_ABORT)
65 tx3927_pcicptr->pcistat |= PCI_STATUS_REC_MASTER_ABORT;
66 tx3927_pcicptr->pcistatim |= PCI_STATUS_REC_MASTER_ABORT;
67 return PCIBIOS_DEVICE_NOT_FOUND;
69 return PCIBIOS_SUCCESSFUL;
72 static int jmr3927_pci_read_config(struct pci_bus *bus, unsigned int devfn,
73 int where, int size, u32 * val)
75 int ret, busno;
77 /* check if the bus is top-level */
78 if (bus->parent != NULL)
79 busno = bus->number;
81 ret = mkaddr(busno, devfn, where);
82 if (ret)
83 return ret;
85 switch (size) {
86 case 1:
87 *val = *(volatile u8 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3));
88 break;
90 case 2:
91 *val = le16_to_cpu(*(volatile u16 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3)));
92 break;
94 case 4:
95 *val = le32_to_cpu(tx3927_pcicptr->icd);
96 break;
99 return check_abort();
102 static int jmr3927_pci_write_config(struct pci_bus *bus, unsigned int devfn,
103 int where, int size, u32 val)
105 int ret, busno;
107 /* check if the bus is top-level */
108 if (bus->parent != NULL)
109 bus = bus->number;
110 else
111 bus = 0;
113 ret = mkaddr(busno, devfn, where);
114 if (ret)
115 return ret;
117 switch (size) {
118 case 1:
119 *(volatile u8 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3)) = val;
120 break;
122 case 2:
123 *(volatile u16 *) (unsigned longulong) & tx3927_pcicptr->icd | (where & 2)) =
124 cpu_to_le16(val);
125 break;
127 case 4:
128 tx3927_pcicptr->icd = cpu_to_le32(val);
131 if (tx3927_pcicptr->pcistat & PCI_STATUS_REC_MASTER_ABORT)
132 tx3927_pcicptr->pcistat |= PCI_STATUS_REC_MASTER_ABORT;
133 tx3927_pcicptr->pcistatim |= PCI_STATUS_REC_MASTER_ABORT;
134 return PCIBIOS_DEVICE_NOT_FOUND;
136 return check_abort();
139 struct pci_ops jmr3927_pci_ops = {
140 jmr3927_pcibios_read_config,
141 jmr3927_pcibios_write_config,
145 #ifndef JMR3927_INIT_INDIRECT_PCI
147 inline unsigned long tc_readl(volatile __u32 * addr)
149 return readl(addr);
152 inline void tc_writel(unsigned long data, volatile __u32 * addr)
154 writel(data, addr);
156 #else
158 unsigned long tc_readl(volatile __u32 * addr)
160 unsigned long val;
162 addr = PHYSADDR(addr);
163 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipciaddr =
164 (unsigned long) addr;
165 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcibe =
166 (PCI_IPCIBE_ICMD_MEMREAD << PCI_IPCIBE_ICMD_SHIFT) |
167 PCI_IPCIBE_IBE_LONG;
168 while (!(tx3927_pcicptr->istat & PCI_ISTAT_IDICC));
169 val =
170 le32_to_cpu(*(volatile u32 *) (ulong) & tx3927_pcicptr->
171 ipcidata);
172 /* clear by setting */
173 tx3927_pcicptr->istat |= PCI_ISTAT_IDICC;
174 return val;
177 void tc_writel(unsigned long data, volatile __u32 * addr)
179 addr = PHYSADDR(addr);
180 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcidata =
181 cpu_to_le32(data);
182 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipciaddr =
183 (unsigned long) addr;
184 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcibe =
185 (PCI_IPCIBE_ICMD_MEMWRITE << PCI_IPCIBE_ICMD_SHIFT) |
186 PCI_IPCIBE_IBE_LONG;
187 while (!(tx3927_pcicptr->istat & PCI_ISTAT_IDICC));
188 /* clear by setting */
189 tx3927_pcicptr->istat |= PCI_ISTAT_IDICC;
192 unsigned char tx_ioinb(unsigned char *addr)
194 unsigned long val;
195 __u32 ioaddr;
196 int offset;
197 int byte;
199 ioaddr = (unsigned long) addr;
200 offset = ioaddr & 0x3;
201 if (offset == 0)
202 byte = 0x7;
203 else if (offset == 1)
204 byte = 0xb;
205 else if (offset == 2)
206 byte = 0xd;
207 else if (offset == 3)
208 byte = 0xe;
209 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipciaddr =
210 (unsigned long) ioaddr;
211 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcibe =
212 (PCI_IPCIBE_ICMD_IOREAD << PCI_IPCIBE_ICMD_SHIFT) | byte;
213 while (!(tx3927_pcicptr->istat & PCI_ISTAT_IDICC));
214 val =
215 le32_to_cpu(*(volatile u32 *) (ulong) & tx3927_pcicptr->
216 ipcidata);
217 val = val & 0xff;
218 /* clear by setting */
219 tx3927_pcicptr->istat |= PCI_ISTAT_IDICC;
220 return val;
223 void tx_iooutb(unsigned long data, unsigned char *addr)
225 __u32 ioaddr;
226 int offset;
227 int byte;
229 data = data | (data << 8) | (data << 16) | (data << 24);
230 ioaddr = (unsigned long) addr;
231 offset = ioaddr & 0x3;
232 if (offset == 0)
233 byte = 0x7;
234 else if (offset == 1)
235 byte = 0xb;
236 else if (offset == 2)
237 byte = 0xd;
238 else if (offset == 3)
239 byte = 0xe;
240 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcidata = data;
241 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipciaddr =
242 (unsigned long) ioaddr;
243 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcibe =
244 (PCI_IPCIBE_ICMD_IOWRITE << PCI_IPCIBE_ICMD_SHIFT) | byte;
245 while (!(tx3927_pcicptr->istat & PCI_ISTAT_IDICC));
246 /* clear by setting */
247 tx3927_pcicptr->istat |= PCI_ISTAT_IDICC;
250 unsigned short tx_ioinw(unsigned short *addr)
252 unsigned long val;
253 __u32 ioaddr;
254 int offset;
255 int byte;
257 ioaddr = (unsigned long) addr;
258 offset = ioaddr & 0x3;
259 if (offset == 0)
260 byte = 0x3;
261 else if (offset == 2)
262 byte = 0xc;
263 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipciaddr =
264 (unsigned long) ioaddr;
265 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcibe =
266 (PCI_IPCIBE_ICMD_IOREAD << PCI_IPCIBE_ICMD_SHIFT) | byte;
267 while (!(tx3927_pcicptr->istat & PCI_ISTAT_IDICC));
268 val =
269 le32_to_cpu(*(volatile u32 *) (ulong) & tx3927_pcicptr->
270 ipcidata);
271 val = val & 0xffff;
272 /* clear by setting */
273 tx3927_pcicptr->istat |= PCI_ISTAT_IDICC;
274 return val;
278 void tx_iooutw(unsigned long data, unsigned short *addr)
280 __u32 ioaddr;
281 int offset;
282 int byte;
284 data = data | (data << 16);
285 ioaddr = (unsigned long) addr;
286 offset = ioaddr & 0x3;
287 if (offset == 0)
288 byte = 0x3;
289 else if (offset == 2)
290 byte = 0xc;
291 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcidata = data;
292 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipciaddr =
293 (unsigned long) ioaddr;
294 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcibe =
295 (PCI_IPCIBE_ICMD_IOWRITE << PCI_IPCIBE_ICMD_SHIFT) | byte;
296 while (!(tx3927_pcicptr->istat & PCI_ISTAT_IDICC));
297 /* clear by setting */
298 tx3927_pcicptr->istat |= PCI_ISTAT_IDICC;
301 unsigned long tx_ioinl(unsigned int *addr)
303 unsigned long val;
304 __u32 ioaddr;
306 ioaddr = (unsigned long) addr;
307 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipciaddr =
308 (unsigned long) ioaddr;
309 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcibe =
310 (PCI_IPCIBE_ICMD_IOREAD << PCI_IPCIBE_ICMD_SHIFT) |
311 PCI_IPCIBE_IBE_LONG;
312 while (!(tx3927_pcicptr->istat & PCI_ISTAT_IDICC));
313 val =
314 le32_to_cpu(*(volatile u32 *) (ulong) & tx3927_pcicptr->
315 ipcidata);
316 /* clear by setting */
317 tx3927_pcicptr->istat |= PCI_ISTAT_IDICC;
318 return val;
321 void tx_iooutl(unsigned long data, unsigned int *addr)
323 __u32 ioaddr;
325 ioaddr = (unsigned long) addr;
326 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcidata =
327 cpu_to_le32(data);
328 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipciaddr =
329 (unsigned long) ioaddr;
330 *(volatile u32 *) (ulong) & tx3927_pcicptr->ipcibe =
331 (PCI_IPCIBE_ICMD_IOWRITE << PCI_IPCIBE_ICMD_SHIFT) |
332 PCI_IPCIBE_IBE_LONG;
333 while (!(tx3927_pcicptr->istat & PCI_ISTAT_IDICC));
334 /* clear by setting */
335 tx3927_pcicptr->istat |= PCI_ISTAT_IDICC;
338 void tx_insbyte(unsigned char *addr, void *buffer, unsigned int count)
340 unsigned char *ptr = (unsigned char *) buffer;
342 while (count--) {
343 *ptr++ = tx_ioinb(addr);
347 void tx_insword(unsigned short *addr, void *buffer, unsigned int count)
349 unsigned short *ptr = (unsigned short *) buffer;
351 while (count--) {
352 *ptr++ = tx_ioinw(addr);
356 void tx_inslong(unsigned int *addr, void *buffer, unsigned int count)
358 unsigned long *ptr = (unsigned long *) buffer;
360 while (count--) {
361 *ptr++ = tx_ioinl(addr);
365 void tx_outsbyte(unsigned char *addr, void *buffer, unsigned int count)
367 unsigned char *ptr = (unsigned char *) buffer;
369 while (count--) {
370 tx_iooutb(*ptr++, addr);
374 void tx_outsword(unsigned short *addr, void *buffer, unsigned int count)
376 unsigned short *ptr = (unsigned short *) buffer;
378 while (count--) {
379 tx_iooutw(*ptr++, addr);
383 void tx_outslong(unsigned int *addr, void *buffer, unsigned int count)
385 unsigned long *ptr = (unsigned long *) buffer;
387 while (count--) {
388 tx_iooutl(*ptr++, addr);
391 #endif