2 * Support for indirect PCI bridges.
4 * Copyright (C) 1998 Gabriel Paubert.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/pci.h>
14 #include <asm/system.h>
16 unsigned int * pci_config_address
;
17 unsigned char * pci_config_data
;
19 int indirect_pcibios_read_config_byte(unsigned char bus
, unsigned char dev_fn
,
20 unsigned char offset
, unsigned char *val
)
24 save_flags(flags
); cli();
26 out_be32(pci_config_address
,
27 ((offset
&0xfc)<<24) | (dev_fn
<<16) | (bus
<<8) | 0x80);
29 *val
= in_8(pci_config_data
+ (offset
&3));
32 return PCIBIOS_SUCCESSFUL
;
35 int indirect_pcibios_read_config_word(unsigned char bus
, unsigned char dev_fn
,
36 unsigned char offset
, unsigned short *val
)
40 if (offset
&1) return PCIBIOS_BAD_REGISTER_NUMBER
;
42 save_flags(flags
); cli();
44 out_be32(pci_config_address
,
45 ((offset
&0xfc)<<24) | (dev_fn
<<16) | (bus
<<8) | 0x80);
47 *val
= in_le16((unsigned short *)(pci_config_data
+ (offset
&3)));
50 return PCIBIOS_SUCCESSFUL
;
53 int indirect_pcibios_read_config_dword(unsigned char bus
, unsigned char dev_fn
,
54 unsigned char offset
, unsigned int *val
)
58 if (offset
&3) return PCIBIOS_BAD_REGISTER_NUMBER
;
60 save_flags(flags
); cli();
62 out_be32(pci_config_address
,
63 ((offset
&0xfc)<<24) | (dev_fn
<<16) | (bus
<<8) | 0x80);
65 *val
= in_le32((unsigned *)pci_config_data
);
68 return PCIBIOS_SUCCESSFUL
;
71 int indirect_pcibios_write_config_byte(unsigned char bus
, unsigned char dev_fn
,
72 unsigned char offset
, unsigned char val
)
76 save_flags(flags
); cli();
78 out_be32(pci_config_address
,
79 ((offset
&0xfc)<<24) | (dev_fn
<<16) | (bus
<<8) | 0x80);
81 out_8(pci_config_data
+ (offset
&3), val
);
84 return PCIBIOS_SUCCESSFUL
;
87 int indirect_pcibios_write_config_word(unsigned char bus
, unsigned char dev_fn
,
88 unsigned char offset
, unsigned short val
)
92 if (offset
&1) return PCIBIOS_BAD_REGISTER_NUMBER
;
94 save_flags(flags
); cli();
96 out_be32(pci_config_address
,
97 ((offset
&0xfc)<<24) | (dev_fn
<<16) | (bus
<<8) | 0x80);
99 out_le16((unsigned short *)(pci_config_data
+ (offset
&3)), val
);
101 restore_flags(flags
);
102 return PCIBIOS_SUCCESSFUL
;
105 int indirect_pcibios_write_config_dword(unsigned char bus
, unsigned char dev_fn
,
106 unsigned char offset
, unsigned int val
)
110 if (offset
&3) return PCIBIOS_BAD_REGISTER_NUMBER
;
112 save_flags(flags
); cli();
114 out_be32(pci_config_address
,
115 ((offset
&0xfc)<<24) | (dev_fn
<<16) | (bus
<<8) | 0x80);
117 out_le32((unsigned *)pci_config_data
, val
);
119 restore_flags(flags
);
120 return PCIBIOS_SUCCESSFUL
;