File: /usr/src/linux/arch/ppc/kernel/indirect_pci.c

1     /*
2      * BK Id: SCCS/s.indirect_pci.c 1.10 09/08/01 15:47:42 paulus
3      */
4     /*
5      * Support for indirect PCI bridges.
6      *
7      * Copyright (C) 1998 Gabriel Paubert.
8      *
9      * This program is free software; you can redistribute it and/or
10      * modify it under the terms of the GNU General Public License
11      * as published by the Free Software Foundation; either version
12      * 2 of the License, or (at your option) any later version.
13      */
14     
15     #include <linux/kernel.h>
16     #include <linux/pci.h>
17     #include <linux/delay.h>
18     #include <linux/string.h>
19     #include <linux/init.h>
20     #include <linux/bootmem.h>
21     
22     #include <asm/io.h>
23     #include <asm/prom.h>
24     #include <asm/pci-bridge.h>
25     #include <asm/machdep.h>
26     
27     #include "pci.h"
28     
29     #define cfg_read(val, addr, type, op)	*val = op((type)(addr))
30     #define cfg_write(val, addr, type, op)	op((type *)(addr), (val))
31     
32     #define INDIRECT_PCI_OP(rw, size, type, op, mask)			 \
33     static int								 \
34     indirect_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
35     {									 \
36     	struct pci_controller *hose = dev->sysdata;			 \
37     									 \
38     	out_be32(hose->cfg_addr, 					 \
39     		 ((offset & 0xfc) << 24) | (dev->devfn << 16)		 \
40     		 | (dev->bus->number << 8) | 0x80);			 \
41     	cfg_##rw(val, hose->cfg_data + (offset & mask), type, op);	 \
42     	return PCIBIOS_SUCCESSFUL;    					 \
43     }
44     
45     INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
46     INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
47     INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
48     INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
49     INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
50     INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
51     
52     static struct pci_ops indirect_pci_ops =
53     {
54     	indirect_read_config_byte,
55     	indirect_read_config_word,
56     	indirect_read_config_dword,
57     	indirect_write_config_byte,
58     	indirect_write_config_word,
59     	indirect_write_config_dword
60     };
61     
62     void __init
63     setup_indirect_pci(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
64     {
65     	hose->ops = &indirect_pci_ops;
66     	hose->cfg_addr = (unsigned int *) ioremap(cfg_addr, 4);
67     	hose->cfg_data = (unsigned char *) ioremap(cfg_data, 4);
68     }
69     
70