📄 pci.c
字号:
/* $Id: pci.c,v 1.39 2002/01/05 01:13:43 davem Exp $ * pci.c: UltraSparc PCI controller support. * * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com) * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be) * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz) */#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/sched.h>#include <linux/capability.h>#include <linux/errno.h>#include <linux/smp_lock.h>#include <linux/init.h>#include <asm/uaccess.h>#include <asm/pbm.h>#include <asm/pgtable.h>#include <asm/irq.h>#include <asm/ebus.h>#include <asm/isa.h>unsigned long pci_memspace_mask = 0xffffffffUL;#ifndef CONFIG_PCI/* A "nop" PCI implementation. */asmlinkage int sys_pciconfig_read(unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len, unsigned char *buf){ return 0;}asmlinkage int sys_pciconfig_write(unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len, unsigned char *buf){ return 0;}#else/* List of all PCI controllers found in the system. */struct pci_controller_info *pci_controller_root = NULL;/* Each PCI controller found gets a unique index. */int pci_num_controllers = 0;/* At boot time the user can give the kernel a command * line option which controls if and how PCI devices * are reordered at PCI bus probing time. */int pci_device_reorder = 0;volatile int pci_poke_in_progress;volatile int pci_poke_cpu = -1;volatile int pci_poke_faulted;static DEFINE_SPINLOCK(pci_poke_lock);void pci_config_read8(u8 *addr, u8 *ret){ unsigned long flags; u8 byte; spin_lock_irqsave(&pci_poke_lock, flags); pci_poke_cpu = smp_processor_id(); pci_poke_in_progress = 1; pci_poke_faulted = 0; __asm__ __volatile__("membar #Sync\n\t" "lduba [%1] %2, %0\n\t" "membar #Sync" : "=r" (byte) : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) : "memory"); pci_poke_in_progress = 0; pci_poke_cpu = -1; if (!pci_poke_faulted) *ret = byte; spin_unlock_irqrestore(&pci_poke_lock, flags);}void pci_config_read16(u16 *addr, u16 *ret){ unsigned long flags; u16 word; spin_lock_irqsave(&pci_poke_lock, flags); pci_poke_cpu = smp_processor_id(); pci_poke_in_progress = 1; pci_poke_faulted = 0; __asm__ __volatile__("membar #Sync\n\t" "lduha [%1] %2, %0\n\t" "membar #Sync" : "=r" (word) : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) : "memory"); pci_poke_in_progress = 0; pci_poke_cpu = -1; if (!pci_poke_faulted) *ret = word; spin_unlock_irqrestore(&pci_poke_lock, flags);}void pci_config_read32(u32 *addr, u32 *ret){ unsigned long flags; u32 dword; spin_lock_irqsave(&pci_poke_lock, flags); pci_poke_cpu = smp_processor_id(); pci_poke_in_progress = 1; pci_poke_faulted = 0; __asm__ __volatile__("membar #Sync\n\t" "lduwa [%1] %2, %0\n\t" "membar #Sync" : "=r" (dword) : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) : "memory"); pci_poke_in_progress = 0; pci_poke_cpu = -1; if (!pci_poke_faulted) *ret = dword; spin_unlock_irqrestore(&pci_poke_lock, flags);}void pci_config_write8(u8 *addr, u8 val){ unsigned long flags; spin_lock_irqsave(&pci_poke_lock, flags); pci_poke_cpu = smp_processor_id(); pci_poke_in_progress = 1; pci_poke_faulted = 0; __asm__ __volatile__("membar #Sync\n\t" "stba %0, [%1] %2\n\t" "membar #Sync" : /* no outputs */ : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) : "memory"); pci_poke_in_progress = 0; pci_poke_cpu = -1; spin_unlock_irqrestore(&pci_poke_lock, flags);}void pci_config_write16(u16 *addr, u16 val){ unsigned long flags; spin_lock_irqsave(&pci_poke_lock, flags); pci_poke_cpu = smp_processor_id(); pci_poke_in_progress = 1; pci_poke_faulted = 0; __asm__ __volatile__("membar #Sync\n\t" "stha %0, [%1] %2\n\t" "membar #Sync" : /* no outputs */ : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) : "memory"); pci_poke_in_progress = 0; pci_poke_cpu = -1; spin_unlock_irqrestore(&pci_poke_lock, flags);}void pci_config_write32(u32 *addr, u32 val){ unsigned long flags; spin_lock_irqsave(&pci_poke_lock, flags); pci_poke_cpu = smp_processor_id(); pci_poke_in_progress = 1; pci_poke_faulted = 0; __asm__ __volatile__("membar #Sync\n\t" "stwa %0, [%1] %2\n\t" "membar #Sync" : /* no outputs */ : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) : "memory"); pci_poke_in_progress = 0; pci_poke_cpu = -1; spin_unlock_irqrestore(&pci_poke_lock, flags);}/* Probe for all PCI controllers in the system. */extern void sabre_init(int, char *);extern void psycho_init(int, char *);extern void schizo_init(int, char *);extern void schizo_plus_init(int, char *);extern void tomatillo_init(int, char *);static struct { char *model_name; void (*init)(int, char *);} pci_controller_table[] __initdata = { { "SUNW,sabre", sabre_init }, { "pci108e,a000", sabre_init }, { "pci108e,a001", sabre_init }, { "SUNW,psycho", psycho_init }, { "pci108e,8000", psycho_init }, { "SUNW,schizo", schizo_init }, { "pci108e,8001", schizo_init }, { "SUNW,schizo+", schizo_plus_init }, { "pci108e,8002", schizo_plus_init }, { "SUNW,tomatillo", tomatillo_init }, { "pci108e,a801", tomatillo_init },};#define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \ sizeof(pci_controller_table[0]))static int __init pci_controller_init(char *model_name, int namelen, int node){ int i; for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) { if (!strncmp(model_name, pci_controller_table[i].model_name, namelen)) { pci_controller_table[i].init(node, model_name); return 1; } } printk("PCI: Warning unknown controller, model name [%s]\n", model_name); printk("PCI: Ignoring controller...\n"); return 0;}static int __init pci_is_controller(char *model_name, int namelen, int node){ int i; for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) { if (!strncmp(model_name, pci_controller_table[i].model_name, namelen)) { return 1; } } return 0;}static int __init pci_controller_scan(int (*handler)(char *, int, int)){ char namebuf[64]; int node; int count = 0; node = prom_getchild(prom_root_node); while ((node = prom_searchsiblings(node, "pci")) != 0) { int len; if ((len = prom_getproperty(node, "model", namebuf, sizeof(namebuf))) > 0 || (len = prom_getproperty(node, "compatible", namebuf, sizeof(namebuf))) > 0) { int item_len = 0; /* Our value may be a multi-valued string in the * case of some compatible properties. For sanity, * only try the first one. */ while (namebuf[item_len] && len) { len--; item_len++; } if (handler(namebuf, item_len, node)) count++; } node = prom_getsibling(node); if (!node) break; } return count;}/* Is there some PCI controller in the system? */int __init pcic_present(void){ return pci_controller_scan(pci_is_controller);}/* Find each controller in the system, attach and initialize * software state structure for each and link into the * pci_controller_root. Setup the controller enough such * that bus scanning can be done. */static void __init pci_controller_probe(void){ printk("PCI: Probing for controllers.\n"); pci_controller_scan(pci_controller_init);}static void __init pci_scan_each_controller_bus(void){ struct pci_controller_info *p; for (p = pci_controller_root; p; p = p->next) p->scan_bus(p);}/* Reorder the pci_dev chain, so that onboard devices come first * and then come the pluggable cards. */static void __init pci_reorder_devs(void){ struct list_head *pci_onboard = &pci_devices; struct list_head *walk = pci_onboard->next; while (walk != pci_onboard) { struct pci_dev *pdev = pci_dev_g(walk); struct list_head *walk_next = walk->next; if (pdev->irq && (__irq_ino(pdev->irq) & 0x20)) { list_del(walk); list_add(walk, pci_onboard); } walk = walk_next; }}extern void clock_probe(void);extern void power_init(void);static int __init pcibios_init(void){ pci_controller_probe(); if (pci_controller_root == NULL) return 0; pci_scan_each_controller_bus(); if (pci_device_reorder) pci_reorder_devs(); isa_init(); ebus_init(); clock_probe(); power_init();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -