📄 pmac_pci.c
字号:
/* * Support for PCI bridges found on Power Macintoshes. * At present the "bandit" and "chaos" bridges are supported. * Fortunately you access configuration space in the same * way with either bridge. * * Copyright (C) 2003 Benjamin Herrenschmuidt (benh@kernel.crashing.org) * Copyright (C) 1997 Paul Mackerras (paulus@samba.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */#include <linux/kernel.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/string.h>#include <linux/init.h>#include <linux/bootmem.h>#include <asm/sections.h>#include <asm/io.h>#include <asm/prom.h>#include <asm/pci-bridge.h>#include <asm/machdep.h>#include <asm/pmac_feature.h>#include <asm/iommu.h>#include "pci.h"#include "pmac.h"#define DEBUG#ifdef DEBUG#define DBG(x...) printk(x)#else#define DBG(x...)#endifextern int pci_probe_only;extern int pci_read_irq_line(struct pci_dev *pci_dev);/* XXX Could be per-controller, but I don't think we risk anything by * assuming we won't have both UniNorth and Bandit */static int has_uninorth;static struct pci_controller *u3_agp;u8 pci_cache_line_size;struct pci_dev *k2_skiplist[2];static int __init fixup_one_level_bus_range(struct device_node *node, int higher){ for (; node != 0;node = node->sibling) { int * bus_range; unsigned int *class_code; int len; /* For PCI<->PCI bridges or CardBus bridges, we go down */ class_code = (unsigned int *) get_property(node, "class-code", NULL); if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI && (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) continue; bus_range = (int *) get_property(node, "bus-range", &len); if (bus_range != NULL && len > 2 * sizeof(int)) { if (bus_range[1] > higher) higher = bus_range[1]; } higher = fixup_one_level_bus_range(node->child, higher); } return higher;}/* This routine fixes the "bus-range" property of all bridges in the * system since they tend to have their "last" member wrong on macs * * Note that the bus numbers manipulated here are OF bus numbers, they * are not Linux bus numbers. */static void __init fixup_bus_range(struct device_node *bridge){ int * bus_range; int len; /* Lookup the "bus-range" property for the hose */ bus_range = (int *) get_property(bridge, "bus-range", &len); if (bus_range == NULL || len < 2 * sizeof(int)) { printk(KERN_WARNING "Can't get bus-range for %s\n", bridge->full_name); return; } bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]);}/* * Apple MacRISC (U3, UniNorth, Bandit, Chaos) PCI controllers. * * The "Bandit" version is present in all early PCI PowerMacs, * and up to the first ones using Grackle. Some machines may * have 2 bandit controllers (2 PCI busses). * * "Chaos" is used in some "Bandit"-type machines as a bridge * for the separate display bus. It is accessed the same * way as bandit, but cannot be probed for devices. It therefore * has its own config access functions. * * The "UniNorth" version is present in all Core99 machines * (iBook, G4, new IMacs, and all the recent Apple machines). * It contains 3 controllers in one ASIC. * * The U3 is the bridge used on G5 machines. It contains on * AGP bus which is dealt with the old UniNorth access routines * and an HyperTransport bus which uses its own set of access * functions. */#define MACRISC_CFA0(devfn, off) \ ((1 << (unsigned long)PCI_SLOT(dev_fn)) \ | (((unsigned long)PCI_FUNC(dev_fn)) << 8) \ | (((unsigned long)(off)) & 0xFCUL))#define MACRISC_CFA1(bus, devfn, off) \ ((((unsigned long)(bus)) << 16) \ |(((unsigned long)(devfn)) << 8) \ |(((unsigned long)(off)) & 0xFCUL) \ |1UL)static unsigned long __pmac macrisc_cfg_access(struct pci_controller* hose, u8 bus, u8 dev_fn, u8 offset){ unsigned int caddr; if (bus == hose->first_busno) { if (dev_fn < (11 << 3)) return 0; caddr = MACRISC_CFA0(dev_fn, offset); } else caddr = MACRISC_CFA1(bus, dev_fn, offset); /* Uninorth will return garbage if we don't read back the value ! */ do { out_le32(hose->cfg_addr, caddr); } while (in_le32(hose->cfg_addr) != caddr); offset &= has_uninorth ? 0x07 : 0x03; return ((unsigned long)hose->cfg_data) + offset;}static int __pmac macrisc_read_config(struct pci_bus *bus, unsigned int devfn, int offset, int len, u32 *val){ struct pci_controller *hose; struct device_node *busdn; unsigned long addr; if (bus->self) busdn = pci_device_to_OF_node(bus->self); else busdn = bus->sysdata; /* must be a phb */ if (busdn == NULL) return PCIBIOS_DEVICE_NOT_FOUND; hose = busdn->phb; if (hose == NULL) return PCIBIOS_DEVICE_NOT_FOUND; addr = macrisc_cfg_access(hose, bus->number, devfn, offset); if (!addr) return PCIBIOS_DEVICE_NOT_FOUND; /* * Note: the caller has already checked that offset is * suitably aligned and that len is 1, 2 or 4. */ switch (len) { case 1: *val = in_8((u8 *)addr); break; case 2: *val = in_le16((u16 *)addr); break; default: *val = in_le32((u32 *)addr); break; } return PCIBIOS_SUCCESSFUL;}static int __pmac macrisc_write_config(struct pci_bus *bus, unsigned int devfn, int offset, int len, u32 val){ struct pci_controller *hose; struct device_node *busdn; unsigned long addr; if (bus->self) busdn = pci_device_to_OF_node(bus->self); else busdn = bus->sysdata; /* must be a phb */ if (busdn == NULL) return PCIBIOS_DEVICE_NOT_FOUND; hose = busdn->phb; if (hose == NULL) return PCIBIOS_DEVICE_NOT_FOUND; addr = macrisc_cfg_access(hose, bus->number, devfn, offset); if (!addr) return PCIBIOS_DEVICE_NOT_FOUND; /* * Note: the caller has already checked that offset is * suitably aligned and that len is 1, 2 or 4. */ switch (len) { case 1: out_8((u8 *)addr, val); (void) in_8((u8 *)addr); break; case 2: out_le16((u16 *)addr, val); (void) in_le16((u16 *)addr); break; default: out_le32((u32 *)addr, val); (void) in_le32((u32 *)addr); break; } return PCIBIOS_SUCCESSFUL;}static struct pci_ops macrisc_pci_ops ={ macrisc_read_config, macrisc_write_config};/* * These versions of U3 HyperTransport config space access ops do not * implement self-view of the HT host yet */static int skip_k2_device(struct pci_bus *bus, unsigned int devfn){ int i; for (i=0; i<2; i++) if (k2_skiplist[i] && k2_skiplist[i]->bus == bus && k2_skiplist[i]->devfn == devfn) return 1; return 0;}#define U3_HT_CFA0(devfn, off) \ ((((unsigned long)devfn) << 8) | offset)#define U3_HT_CFA1(bus, devfn, off) \ (U3_HT_CFA0(devfn, off) \ + (((unsigned long)bus) << 16) \ + 0x01000000UL)static unsigned long __pmac u3_ht_cfg_access(struct pci_controller* hose, u8 bus, u8 devfn, u8 offset){ if (bus == hose->first_busno) { /* For now, we don't self probe U3 HT bridge */ if (PCI_FUNC(devfn) != 0 || PCI_SLOT(devfn) > 7 || PCI_SLOT(devfn) < 1) return 0; return ((unsigned long)hose->cfg_data) + U3_HT_CFA0(devfn, offset); } else return ((unsigned long)hose->cfg_data) + U3_HT_CFA1(bus, devfn, offset);}static int __pmac u3_ht_read_config(struct pci_bus *bus, unsigned int devfn, int offset, int len, u32 *val){ struct pci_controller *hose; struct device_node *busdn; unsigned long addr; if (bus->self) busdn = pci_device_to_OF_node(bus->self); else busdn = bus->sysdata; /* must be a phb */ if (busdn == NULL) return PCIBIOS_DEVICE_NOT_FOUND; hose = busdn->phb; if (hose == NULL) return PCIBIOS_DEVICE_NOT_FOUND; addr = u3_ht_cfg_access(hose, bus->number, devfn, offset); if (!addr) return PCIBIOS_DEVICE_NOT_FOUND; /* * When a device in K2 is powered down, we die on config * cycle accesses. Fix that here. We may ultimately want * to cache the config space for those instead of returning * 0xffffffff's to make life easier to HW detection tools */ if (skip_k2_device(bus, devfn)) { switch (len) { case 1: *val = 0xff; break; case 2: *val = 0xffff; break; default: *val = 0xfffffffful; break; } return PCIBIOS_SUCCESSFUL; } /* * Note: the caller has already checked that offset is * suitably aligned and that len is 1, 2 or 4. */ switch (len) { case 1: *val = in_8((u8 *)addr); break; case 2: *val = in_le16((u16 *)addr); break; default: *val = in_le32((u32 *)addr); break; } return PCIBIOS_SUCCESSFUL;}static int __pmac u3_ht_write_config(struct pci_bus *bus, unsigned int devfn, int offset, int len, u32 val){ struct pci_controller *hose; struct device_node *busdn; unsigned long addr; if (bus->self) busdn = pci_device_to_OF_node(bus->self); else busdn = bus->sysdata; /* must be a phb */ if (busdn == NULL) return PCIBIOS_DEVICE_NOT_FOUND; hose = busdn->phb; if (hose == NULL) return PCIBIOS_DEVICE_NOT_FOUND; addr = u3_ht_cfg_access(hose, bus->number, devfn, offset); if (!addr) return PCIBIOS_DEVICE_NOT_FOUND; /* * When a device in K2 is powered down, we die on config * cycle accesses. Fix that here. */ if (skip_k2_device(bus, devfn)) return PCIBIOS_SUCCESSFUL; /* * Note: the caller has already checked that offset is * suitably aligned and that len is 1, 2 or 4. */ switch (len) { case 1: out_8((u8 *)addr, val); (void) in_8((u8 *)addr); break; case 2: out_le16((u16 *)addr, val); (void) in_le16((u16 *)addr); break; default: out_le32((u32 *)addr, val); (void) in_le32((u32 *)addr); break; } return PCIBIOS_SUCCESSFUL;}static struct pci_ops u3_ht_pci_ops ={ u3_ht_read_config, u3_ht_write_config};static void __init setup_u3_agp(struct pci_controller* hose){ /* On G5, we move AGP up to high bus number so we don't need * to reassign bus numbers for HT. If we ever have P2P bridges * on AGP, we'll have to move pci_assign_all_busses to the * pci_controller structure so we enable it for AGP and not for * HT childs. * We hard code the address because of the different size of * the reg address cell, we shall fix that by killing struct * reg_property and using some accessor functions instead */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -