1 /* $Id: pci.c,v 1.6 1999/09/08 03:40:41 davem Exp $
2 * pci.c: UltraSparc PCI controller support.
4 * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com)
5 * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
9 #include <linux/config.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/sched.h>
13 #include <linux/capability.h>
14 #include <linux/errno.h>
15 #include <linux/smp_lock.h>
16 #include <linux/init.h>
18 #include <asm/uaccess.h>
23 unsigned long pci_dvma_v2p_hash
[PCI_DVMA_HASHSZ
];
24 unsigned long pci_dvma_p2v_hash
[PCI_DVMA_HASHSZ
];
25 unsigned long pci_memspace_mask
= 0xffffffffUL
;
28 /* A "nop" PCI implementation. */
29 int pcibios_present(void) { return 0; }
30 asmlinkage
int sys_pciconfig_read(unsigned long bus
, unsigned long dfn
,
31 unsigned long off
, unsigned long len
,
36 asmlinkage
int sys_pciconfig_write(unsigned long bus
, unsigned long dfn
,
37 unsigned long off
, unsigned long len
,
44 /* List of all PCI controllers found in the system. */
45 spinlock_t pci_controller_lock
= SPIN_LOCK_UNLOCKED
;
46 struct pci_controller_info
*pci_controller_root
= NULL
;
48 /* Each PCI controller found gets a unique index. */
49 int pci_num_controllers
= 0;
51 /* Given an 8-bit PCI bus number, this yields the
52 * controlling PBM module info.
54 * Some explanation is in order here. The Linux APIs for
55 * the PCI subsystem require that the configuration space
56 * types are enough to signify PCI configuration space
57 * accesses correctly. This gives us 8-bits for the bus
58 * number, however we have multiple PCI controllers on
61 * So what we do is give the PCI busses under each controller
62 * a unique portion of the 8-bit PCI bus number space.
63 * Therefore one can obtain the controller from the bus
64 * number. For example, say PSYCHO PBM-A a subordinate bus
65 * space of 0 to 4, and PBM-B has a space of 0 to 2. PBM-A
66 * will use 0 to 4, and PBM-B will use 5 to 7.
68 struct pci_pbm_info
*pci_bus2pbm
[256];
69 unsigned char pci_highest_busnum
= 0;
71 /* At boot time the user can give the kernel a command
72 * line option which controls if and how PCI devices
73 * are reordered at PCI bus probing time.
75 int pci_device_reorder
= 0;
77 spinlock_t pci_poke_lock
= SPIN_LOCK_UNLOCKED
;
78 volatile int pci_poke_in_progress
;
79 volatile int pci_poke_faulted
;
81 /* Probe for all PCI controllers in the system. */
82 extern void sabre_init(int);
83 extern void psycho_init(int);
88 } pci_controller_table
[] = {
89 { "SUNW,sabre", sabre_init
},
90 { "pci108e,a000", sabre_init
},
91 { "SUNW,psycho", psycho_init
},
92 { "pci108e,8000", psycho_init
}
94 #define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \
95 sizeof(pci_controller_table[0]))
97 static void pci_controller_init(char *model_name
, int namelen
, int node
)
101 for (i
= 0; i
< PCI_NUM_CONTROLLER_TYPES
; i
++) {
102 if (!strncmp(model_name
,
103 pci_controller_table
[i
].model_name
,
105 pci_controller_table
[i
].init(node
);
109 printk("PCI: Warning unknown controller, model name [%s]\n",
111 printk("PCI: Ignoring controller...\n");
114 /* Find each controller in the system, attach and initialize
115 * software state structure for each and link into the
116 * pci_controller_root. Setup the controller enough such
117 * that bus scanning can be done.
119 static void pci_controller_probe(void)
124 printk("PCI: Probing for controllers.\n");
125 node
= prom_getchild(prom_root_node
);
126 while ((node
= prom_searchsiblings(node
, "pci")) != 0) {
129 len
= prom_getproperty(node
, "model",
130 namebuf
, sizeof(namebuf
));
132 pci_controller_init(namebuf
, len
, node
);
134 len
= prom_getproperty(node
, "compatible",
135 namebuf
, sizeof(namebuf
));
137 pci_controller_init(namebuf
, len
, node
);
139 node
= prom_getsibling(node
);
145 static void pci_scan_each_controller_bus(void)
147 struct pci_controller_info
*p
;
150 spin_lock_irqsave(&pci_controller_lock
, flags
);
151 for (p
= pci_controller_root
; p
; p
= p
->next
)
153 spin_unlock_irqrestore(&pci_controller_lock
, flags
);
156 /* Reorder the pci_dev chain, so that onboard devices come first
157 * and then come the pluggable cards.
159 static void __init
pci_reorder_devs(void)
161 struct pci_dev
**pci_onboard
= &pci_devices
;
162 struct pci_dev
**pci_tail
= &pci_devices
;
163 struct pci_dev
*pdev
= pci_devices
, *pci_other
= NULL
;
166 if (pdev
->irq
&& (__irq_ino(pdev
->irq
) & 0x20)) {
169 pci_onboard
= &pdev
->next
;
171 *pci_onboard
= pci_other
;
175 pci_onboard
= &pdev
->next
;
176 } else if (!pci_other
)
178 pci_tail
= &pdev
->next
;
183 void __init
pcibios_init(void)
185 pci_controller_probe();
186 if (pci_controller_root
== NULL
)
189 pci_scan_each_controller_bus();
191 if (pci_device_reorder
)
197 struct pci_fixup pcibios_fixups
[] = {
201 void pcibios_fixup_bus(struct pci_bus
*pbus
)
205 int pcibios_assign_resource(struct pci_dev
*pdev
, int resource
)
210 char * __init
pcibios_setup(char *str
)
212 if (!strcmp(str
, "onboardfirst")) {
213 pci_device_reorder
= 1;
216 if (!strcmp(str
, "noreorder")) {
217 pci_device_reorder
= 0;
223 asmlinkage
int sys_pciconfig_read(unsigned long bus
,
235 if(!capable(CAP_SYS_ADMIN
))
238 dev
= pci_find_slot(bus
, dfn
);
240 /* Xfree86 is such a turd, it does not check the
241 * return value and just relies on the buffer being
242 * set to all 1's to mean "device not present".
246 put_user(0xff, (unsigned char *)buf
);
249 put_user(0xffff, (unsigned short *)buf
);
252 put_user(0xffffffff, (unsigned int *)buf
);
264 pci_read_config_byte(dev
, off
, &byte
);
265 put_user(byte
, (unsigned char *)buf
);
268 pci_read_config_word(dev
, off
, &word
);
269 put_user(word
, (unsigned short *)buf
);
272 pci_read_config_dword(dev
, off
, &dword
);
273 put_user(dword
, (unsigned int *)buf
);
285 asmlinkage
int sys_pciconfig_write(unsigned long bus
,
297 if(!capable(CAP_SYS_ADMIN
))
299 dev
= pci_find_slot(bus
, dfn
);
301 /* See commentary above about Xfree86 */
308 err
= get_user(byte
, (u8
*)buf
);
311 pci_write_config_byte(dev
, off
, byte
);
315 err
= get_user(word
, (u16
*)buf
);
318 pci_write_config_byte(dev
, off
, word
);
322 err
= get_user(dword
, (u32
*)buf
);
325 pci_write_config_byte(dev
, off
, dword
);
339 #endif /* !(CONFIG_PCI) */