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#include <common.h>
29#include <asm/io.h>
30#include <pci.h>
31
32#define cfg_read(val, addr, op) *val = op((int)(addr))
33#define cfg_write(val, addr, op) op((val), (int)(addr))
34
35#define TYPE1_PCI_OP(rw, size, type, op, mask) \
36static int \
37type1_##rw##_config_##size(struct pci_controller *hose, \
38 pci_dev_t dev, int offset, type val) \
39{ \
40 outl(dev | (offset & 0xfc) | 0x80000000, (int)hose->cfg_addr); \
41 cfg_##rw(val, hose->cfg_data + (offset & mask), op); \
42 return 0; \
43}
44
45
46TYPE1_PCI_OP(read, byte, u8 *, inb, 3)
47TYPE1_PCI_OP(read, word, u16 *, inw, 2)
48TYPE1_PCI_OP(read, dword, u32 *, inl, 0)
49
50TYPE1_PCI_OP(write, byte, u8, outb, 3)
51TYPE1_PCI_OP(write, word, u16, outw, 2)
52TYPE1_PCI_OP(write, dword, u32, outl, 0)
53
54void pci_setup_type1(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
55{
56 pci_set_ops(hose,
57 type1_read_config_byte,
58 type1_read_config_word,
59 type1_read_config_dword,
60 type1_write_config_byte,
61 type1_write_config_word,
62 type1_write_config_dword);
63
64 hose->cfg_addr = (unsigned int *) cfg_addr;
65 hose->cfg_data = (unsigned char *) cfg_data;
66}
67