nfsd4: typo logical vs bitwise negate for want_mask
[linux-btrfs-devel.git] / arch / arm / mach-ixp2000 / pci.c
blobf5098b306fd39693df59f974e17648a8e0cc8a02
1 /*
2 * arch/arm/mach-ixp2000/pci.c
4 * PCI routines for IXDP2400/IXDP2800 boards
6 * Original Author: Naeem Afzal <naeem.m.afzal@intel.com>
7 * Maintained by: Deepak Saxena <dsaxena@plexity.net>
9 * Copyright 2002 Intel Corp.
10 * Copyright (C) 2003-2004 MontaVista Software, Inc.
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/pci.h>
21 #include <linux/interrupt.h>
22 #include <linux/mm.h>
23 #include <linux/init.h>
24 #include <linux/ioport.h>
25 #include <linux/delay.h>
26 #include <linux/io.h>
28 #include <asm/irq.h>
29 #include <asm/system.h>
30 #include <mach/hardware.h>
32 #include <asm/mach/pci.h>
34 static volatile int pci_master_aborts = 0;
36 static int clear_master_aborts(void);
38 u32 *
39 ixp2000_pci_config_addr(unsigned int bus_nr, unsigned int devfn, int where)
41 u32 *paddress;
43 if (PCI_SLOT(devfn) > 7)
44 return 0;
46 /* Must be dword aligned */
47 where &= ~3;
50 * For top bus, generate type 0, else type 1
52 if (!bus_nr) {
53 /* only bits[23:16] are used for IDSEL */
54 paddress = (u32 *) (IXP2000_PCI_CFG0_VIRT_BASE
55 | (1 << (PCI_SLOT(devfn) + 16))
56 | (PCI_FUNC(devfn) << 8) | where);
57 } else {
58 paddress = (u32 *) (IXP2000_PCI_CFG1_VIRT_BASE
59 | (bus_nr << 16)
60 | (PCI_SLOT(devfn) << 11)
61 | (PCI_FUNC(devfn) << 8) | where);
64 return paddress;
68 * Mask table, bits to mask for quantity of size 1, 2 or 4 bytes.
69 * 0 and 3 are not valid indexes...
71 static u32 bytemask[] = {
72 /*0*/ 0,
73 /*1*/ 0xff,
74 /*2*/ 0xffff,
75 /*3*/ 0,
76 /*4*/ 0xffffffff,
80 int ixp2000_pci_read_config(struct pci_bus *bus, unsigned int devfn, int where,
81 int size, u32 *value)
83 u32 n;
84 u32 *addr;
86 n = where % 4;
88 addr = ixp2000_pci_config_addr(bus->number, devfn, where);
89 if (!addr)
90 return PCIBIOS_DEVICE_NOT_FOUND;
92 pci_master_aborts = 0;
93 *value = (*addr >> (8*n)) & bytemask[size];
94 if (pci_master_aborts) {
95 pci_master_aborts = 0;
96 *value = 0xffffffff;
97 return PCIBIOS_DEVICE_NOT_FOUND;
100 return PCIBIOS_SUCCESSFUL;
104 * We don't do error checks by calling clear_master_aborts() b/c the
105 * assumption is that the caller did a read first to make sure a device
106 * exists.
108 int ixp2000_pci_write_config(struct pci_bus *bus, unsigned int devfn, int where,
109 int size, u32 value)
111 u32 mask;
112 u32 *addr;
113 u32 temp;
115 mask = ~(bytemask[size] << ((where % 0x4) * 8));
116 addr = ixp2000_pci_config_addr(bus->number, devfn, where);
117 if (!addr)
118 return PCIBIOS_DEVICE_NOT_FOUND;
119 temp = (u32) (value) << ((where % 0x4) * 8);
120 *addr = (*addr & mask) | temp;
122 clear_master_aborts();
124 return PCIBIOS_SUCCESSFUL;
128 static struct pci_ops ixp2000_pci_ops = {
129 .read = ixp2000_pci_read_config,
130 .write = ixp2000_pci_write_config
133 struct pci_bus *ixp2000_pci_scan_bus(int nr, struct pci_sys_data *sysdata)
135 return pci_scan_bus(sysdata->busnr, &ixp2000_pci_ops, sysdata);
139 int ixp2000_pci_abort_handler(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
142 volatile u32 temp;
143 unsigned long flags;
145 pci_master_aborts = 1;
147 local_irq_save(flags);
148 temp = *(IXP2000_PCI_CONTROL);
149 if (temp & ((1 << 8) | (1 << 5))) {
150 ixp2000_reg_wrb(IXP2000_PCI_CONTROL, temp);
153 temp = *(IXP2000_PCI_CMDSTAT);
154 if (temp & (1 << 29)) {
155 while (temp & (1 << 29)) {
156 ixp2000_reg_write(IXP2000_PCI_CMDSTAT, temp);
157 temp = *(IXP2000_PCI_CMDSTAT);
160 local_irq_restore(flags);
163 * If it was an imprecise abort, then we need to correct the
164 * return address to be _after_ the instruction.
166 if (fsr & (1 << 10))
167 regs->ARM_pc += 4;
169 return 0;
173 clear_master_aborts(void)
175 volatile u32 temp;
176 unsigned long flags;
178 local_irq_save(flags);
179 temp = *(IXP2000_PCI_CONTROL);
180 if (temp & ((1 << 8) | (1 << 5))) {
181 ixp2000_reg_wrb(IXP2000_PCI_CONTROL, temp);
184 temp = *(IXP2000_PCI_CMDSTAT);
185 if (temp & (1 << 29)) {
186 while (temp & (1 << 29)) {
187 ixp2000_reg_write(IXP2000_PCI_CMDSTAT, temp);
188 temp = *(IXP2000_PCI_CMDSTAT);
191 local_irq_restore(flags);
193 return 0;
196 void __init
197 ixp2000_pci_preinit(void)
199 pci_set_flags(0);
201 pcibios_min_io = 0;
202 pcibios_min_mem = 0;
204 #ifndef CONFIG_IXP2000_SUPPORT_BROKEN_PCI_IO
206 * Configure the PCI unit to properly byteswap I/O transactions,
207 * and verify that it worked.
209 ixp2000_reg_write(IXP2000_PCI_CONTROL,
210 (*IXP2000_PCI_CONTROL | PCI_CONTROL_IEE));
212 if ((*IXP2000_PCI_CONTROL & PCI_CONTROL_IEE) == 0)
213 panic("IXP2000: PCI I/O is broken on this ixp model, and "
214 "the needed workaround has not been configured in");
215 #endif
217 hook_fault_code(16+6, ixp2000_pci_abort_handler, SIGBUS, 0,
218 "PCI config cycle to non-existent device");
223 * IXP2000 systems often have large resource requirements, so we just
224 * use our own resource space.
226 static struct resource ixp2000_pci_mem_space = {
227 .start = 0xe0000000,
228 .end = 0xffffffff,
229 .flags = IORESOURCE_MEM,
230 .name = "PCI Mem Space"
233 static struct resource ixp2000_pci_io_space = {
234 .start = 0x00010000,
235 .end = 0x0001ffff,
236 .flags = IORESOURCE_IO,
237 .name = "PCI I/O Space"
240 int ixp2000_pci_setup(int nr, struct pci_sys_data *sys)
242 if (nr >= 1)
243 return 0;
245 sys->resource[0] = &ixp2000_pci_io_space;
246 sys->resource[1] = &ixp2000_pci_mem_space;
247 sys->resource[2] = NULL;
249 return 1;