1 #include <linux/types.h>
3 #include <linux/kernel.h>
4 #include <linux/init.h>
5 #include <linux/delay.h>
7 #include <asm/ifxmips/ifxmips.h>
8 #include <asm/ifxmips/ifxmips_irq.h>
9 #include <asm/addrspace.h>
10 #include <linux/vmalloc.h>
12 #define IFXMIPS_PCI_CFG_BUSNUM_SHF 16
13 #define IFXMIPS_PCI_CFG_DEVNUM_SHF 11
14 #define IFXMIPS_PCI_CFG_FUNNUM_SHF 8
16 #define PCI_ACCESS_READ 0
17 #define PCI_ACCESS_WRITE 1
19 extern u32 ifxmips_pci_mapped_cfg
;
22 ifxmips_pci_config_access(unsigned char access_type
,
23 struct pci_bus
*bus
, unsigned int devfn
, unsigned int where
, u32
*data
)
25 unsigned long cfg_base
;
30 /* IFXMips support slot from 0 to 15 */
31 /* dev_fn 0&0x68 (AD29) is ifxmips itself */
32 if ((bus
->number
!= 0) || ((devfn
& 0xf8) > 0x78)
33 || ((devfn
& 0xf8) == 0) || ((devfn
& 0xf8) == 0x68))
36 local_irq_save(flags
);
38 cfg_base
= ifxmips_pci_mapped_cfg
;
39 cfg_base
|= (bus
->number
<< IFXMIPS_PCI_CFG_BUSNUM_SHF
) | (devfn
<<
40 IFXMIPS_PCI_CFG_FUNNUM_SHF
) | (where
& ~0x3);
43 if (access_type
== PCI_ACCESS_WRITE
)
45 #ifdef CONFIG_SWAP_IO_SPACE
46 ifxmips_w32(swab32(*data
), ((u32
*)cfg_base
));
48 ifxmips_w32(*data
, ((u32
*)cfg_base
));
51 *data
= ifxmips_r32(((u32
*)(cfg_base
)));
52 #ifdef CONFIG_SWAP_IO_SPACE
53 *data
= swab32(*data
);
58 /* clean possible Master abort */
59 cfg_base
= (ifxmips_pci_mapped_cfg
| (0x0 << IFXMIPS_PCI_CFG_FUNNUM_SHF
)) + 4;
60 temp
= ifxmips_r32(((u32
*)(cfg_base
)));
61 #ifdef CONFIG_SWAP_IO_SPACE
64 cfg_base
= (ifxmips_pci_mapped_cfg
| (0x68 << IFXMIPS_PCI_CFG_FUNNUM_SHF
)) + 4;
65 ifxmips_w32(temp
, ((u32
*)cfg_base
));
67 local_irq_restore(flags
);
69 if (((*data
) == 0xffffffff) && (access_type
== PCI_ACCESS_READ
))
76 ifxmips_pci_read_config_dword(struct pci_bus
*bus
, unsigned int devfn
,
77 int where
, int size
, u32
* val
)
81 if (ifxmips_pci_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
))
82 return PCIBIOS_DEVICE_NOT_FOUND
;
85 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
87 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
91 return PCIBIOS_SUCCESSFUL
;
95 ifxmips_pci_write_config_dword(struct pci_bus
*bus
, unsigned int devfn
,
96 int where
, int size
, u32 val
)
104 if (ifxmips_pci_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
))
105 return PCIBIOS_DEVICE_NOT_FOUND
;
108 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
109 (val
<< ((where
& 3) << 3));
111 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
112 (val
<< ((where
& 3) << 3));
115 if (ifxmips_pci_config_access(PCI_ACCESS_WRITE
, bus
, devfn
, where
, &data
))
116 return PCIBIOS_DEVICE_NOT_FOUND
;
118 return PCIBIOS_SUCCESSFUL
;