ia64/linux-2.6.18-xen.hg

annotate arch/sparc64/kernel/pci_sabre.c @ 897:329ea0ccb344

balloon: try harder to balloon up under memory pressure.

Currently if the balloon driver is unable to increase the guest's
reservation it assumes the failure was due to reaching its full
allocation, gives up on the ballooning operation and records the limit
it reached as the "hard limit". The driver will not try again until
the target is set again (even to the same value).

However it is possible that ballooning has in fact failed due to
memory pressure in the host and therefore it is desirable to keep
attempting to reach the target in case memory becomes available. The
most likely scenario is that some guests are ballooning down while
others are ballooning up and therefore there is temporary memory
pressure while things stabilise. You would not expect a well behaved
toolstack to ask a domain to balloon to more than its allocation nor
would you expect it to deliberately over-commit memory by setting
balloon targets which exceed the total host memory.

This patch drops the concept of a hard limit and causes the balloon
driver to retry increasing the reservation on a timer in the same
manner as when decreasing the reservation.

Also if we partially succeed in increasing the reservation
(i.e. receive less pages than we asked for) then we may as well keep
those pages rather than returning them to Xen.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 14:01:20 2009 +0100 (2009-06-05)
parents 3e8752eb6d9c
children
rev   line source
ian@0 1 /* $Id: pci_sabre.c,v 1.42 2002/01/23 11:27:32 davem Exp $
ian@0 2 * pci_sabre.c: Sabre specific PCI controller support.
ian@0 3 *
ian@0 4 * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@caipfs.rutgers.edu)
ian@0 5 * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
ian@0 6 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
ian@0 7 */
ian@0 8
ian@0 9 #include <linux/kernel.h>
ian@0 10 #include <linux/types.h>
ian@0 11 #include <linux/pci.h>
ian@0 12 #include <linux/init.h>
ian@0 13 #include <linux/slab.h>
ian@0 14 #include <linux/interrupt.h>
ian@0 15
ian@0 16 #include <asm/apb.h>
ian@0 17 #include <asm/pbm.h>
ian@0 18 #include <asm/iommu.h>
ian@0 19 #include <asm/irq.h>
ian@0 20 #include <asm/smp.h>
ian@0 21 #include <asm/oplib.h>
ian@0 22 #include <asm/prom.h>
ian@0 23
ian@0 24 #include "pci_impl.h"
ian@0 25 #include "iommu_common.h"
ian@0 26
ian@0 27 /* All SABRE registers are 64-bits. The following accessor
ian@0 28 * routines are how they are accessed. The REG parameter
ian@0 29 * is a physical address.
ian@0 30 */
ian@0 31 #define sabre_read(__reg) \
ian@0 32 ({ u64 __ret; \
ian@0 33 __asm__ __volatile__("ldxa [%1] %2, %0" \
ian@0 34 : "=r" (__ret) \
ian@0 35 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
ian@0 36 : "memory"); \
ian@0 37 __ret; \
ian@0 38 })
ian@0 39 #define sabre_write(__reg, __val) \
ian@0 40 __asm__ __volatile__("stxa %0, [%1] %2" \
ian@0 41 : /* no outputs */ \
ian@0 42 : "r" (__val), "r" (__reg), \
ian@0 43 "i" (ASI_PHYS_BYPASS_EC_E) \
ian@0 44 : "memory")
ian@0 45
ian@0 46 /* SABRE PCI controller register offsets and definitions. */
ian@0 47 #define SABRE_UE_AFSR 0x0030UL
ian@0 48 #define SABRE_UEAFSR_PDRD 0x4000000000000000UL /* Primary PCI DMA Read */
ian@0 49 #define SABRE_UEAFSR_PDWR 0x2000000000000000UL /* Primary PCI DMA Write */
ian@0 50 #define SABRE_UEAFSR_SDRD 0x0800000000000000UL /* Secondary PCI DMA Read */
ian@0 51 #define SABRE_UEAFSR_SDWR 0x0400000000000000UL /* Secondary PCI DMA Write */
ian@0 52 #define SABRE_UEAFSR_SDTE 0x0200000000000000UL /* Secondary DMA Translation Error */
ian@0 53 #define SABRE_UEAFSR_PDTE 0x0100000000000000UL /* Primary DMA Translation Error */
ian@0 54 #define SABRE_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask */
ian@0 55 #define SABRE_UEAFSR_OFF 0x00000000e0000000UL /* Offset (AFAR bits [5:3] */
ian@0 56 #define SABRE_UEAFSR_BLK 0x0000000000800000UL /* Was block operation */
ian@0 57 #define SABRE_UECE_AFAR 0x0038UL
ian@0 58 #define SABRE_CE_AFSR 0x0040UL
ian@0 59 #define SABRE_CEAFSR_PDRD 0x4000000000000000UL /* Primary PCI DMA Read */
ian@0 60 #define SABRE_CEAFSR_PDWR 0x2000000000000000UL /* Primary PCI DMA Write */
ian@0 61 #define SABRE_CEAFSR_SDRD 0x0800000000000000UL /* Secondary PCI DMA Read */
ian@0 62 #define SABRE_CEAFSR_SDWR 0x0400000000000000UL /* Secondary PCI DMA Write */
ian@0 63 #define SABRE_CEAFSR_ESYND 0x00ff000000000000UL /* ECC Syndrome */
ian@0 64 #define SABRE_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask */
ian@0 65 #define SABRE_CEAFSR_OFF 0x00000000e0000000UL /* Offset */
ian@0 66 #define SABRE_CEAFSR_BLK 0x0000000000800000UL /* Was block operation */
ian@0 67 #define SABRE_UECE_AFAR_ALIAS 0x0048UL /* Aliases to 0x0038 */
ian@0 68 #define SABRE_IOMMU_CONTROL 0x0200UL
ian@0 69 #define SABRE_IOMMUCTRL_ERRSTS 0x0000000006000000UL /* Error status bits */
ian@0 70 #define SABRE_IOMMUCTRL_ERR 0x0000000001000000UL /* Error present in IOTLB */
ian@0 71 #define SABRE_IOMMUCTRL_LCKEN 0x0000000000800000UL /* IOTLB lock enable */
ian@0 72 #define SABRE_IOMMUCTRL_LCKPTR 0x0000000000780000UL /* IOTLB lock pointer */
ian@0 73 #define SABRE_IOMMUCTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
ian@0 74 #define SABRE_IOMMU_TSBSZ_1K 0x0000000000000000
ian@0 75 #define SABRE_IOMMU_TSBSZ_2K 0x0000000000010000
ian@0 76 #define SABRE_IOMMU_TSBSZ_4K 0x0000000000020000
ian@0 77 #define SABRE_IOMMU_TSBSZ_8K 0x0000000000030000
ian@0 78 #define SABRE_IOMMU_TSBSZ_16K 0x0000000000040000
ian@0 79 #define SABRE_IOMMU_TSBSZ_32K 0x0000000000050000
ian@0 80 #define SABRE_IOMMU_TSBSZ_64K 0x0000000000060000
ian@0 81 #define SABRE_IOMMU_TSBSZ_128K 0x0000000000070000
ian@0 82 #define SABRE_IOMMUCTRL_TBWSZ 0x0000000000000004UL /* TSB assumed page size */
ian@0 83 #define SABRE_IOMMUCTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
ian@0 84 #define SABRE_IOMMUCTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
ian@0 85 #define SABRE_IOMMU_TSBBASE 0x0208UL
ian@0 86 #define SABRE_IOMMU_FLUSH 0x0210UL
ian@0 87 #define SABRE_IMAP_A_SLOT0 0x0c00UL
ian@0 88 #define SABRE_IMAP_B_SLOT0 0x0c20UL
ian@0 89 #define SABRE_IMAP_SCSI 0x1000UL
ian@0 90 #define SABRE_IMAP_ETH 0x1008UL
ian@0 91 #define SABRE_IMAP_BPP 0x1010UL
ian@0 92 #define SABRE_IMAP_AU_REC 0x1018UL
ian@0 93 #define SABRE_IMAP_AU_PLAY 0x1020UL
ian@0 94 #define SABRE_IMAP_PFAIL 0x1028UL
ian@0 95 #define SABRE_IMAP_KMS 0x1030UL
ian@0 96 #define SABRE_IMAP_FLPY 0x1038UL
ian@0 97 #define SABRE_IMAP_SHW 0x1040UL
ian@0 98 #define SABRE_IMAP_KBD 0x1048UL
ian@0 99 #define SABRE_IMAP_MS 0x1050UL
ian@0 100 #define SABRE_IMAP_SER 0x1058UL
ian@0 101 #define SABRE_IMAP_UE 0x1070UL
ian@0 102 #define SABRE_IMAP_CE 0x1078UL
ian@0 103 #define SABRE_IMAP_PCIERR 0x1080UL
ian@0 104 #define SABRE_IMAP_GFX 0x1098UL
ian@0 105 #define SABRE_IMAP_EUPA 0x10a0UL
ian@0 106 #define SABRE_ICLR_A_SLOT0 0x1400UL
ian@0 107 #define SABRE_ICLR_B_SLOT0 0x1480UL
ian@0 108 #define SABRE_ICLR_SCSI 0x1800UL
ian@0 109 #define SABRE_ICLR_ETH 0x1808UL
ian@0 110 #define SABRE_ICLR_BPP 0x1810UL
ian@0 111 #define SABRE_ICLR_AU_REC 0x1818UL
ian@0 112 #define SABRE_ICLR_AU_PLAY 0x1820UL
ian@0 113 #define SABRE_ICLR_PFAIL 0x1828UL
ian@0 114 #define SABRE_ICLR_KMS 0x1830UL
ian@0 115 #define SABRE_ICLR_FLPY 0x1838UL
ian@0 116 #define SABRE_ICLR_SHW 0x1840UL
ian@0 117 #define SABRE_ICLR_KBD 0x1848UL
ian@0 118 #define SABRE_ICLR_MS 0x1850UL
ian@0 119 #define SABRE_ICLR_SER 0x1858UL
ian@0 120 #define SABRE_ICLR_UE 0x1870UL
ian@0 121 #define SABRE_ICLR_CE 0x1878UL
ian@0 122 #define SABRE_ICLR_PCIERR 0x1880UL
ian@0 123 #define SABRE_WRSYNC 0x1c20UL
ian@0 124 #define SABRE_PCICTRL 0x2000UL
ian@0 125 #define SABRE_PCICTRL_MRLEN 0x0000001000000000UL /* Use MemoryReadLine for block loads/stores */
ian@0 126 #define SABRE_PCICTRL_SERR 0x0000000400000000UL /* Set when SERR asserted on PCI bus */
ian@0 127 #define SABRE_PCICTRL_ARBPARK 0x0000000000200000UL /* Bus Parking 0=Ultra-IIi 1=prev-bus-owner */
ian@0 128 #define SABRE_PCICTRL_CPUPRIO 0x0000000000100000UL /* Ultra-IIi granted every other bus cycle */
ian@0 129 #define SABRE_PCICTRL_ARBPRIO 0x00000000000f0000UL /* Slot which is granted every other bus cycle */
ian@0 130 #define SABRE_PCICTRL_ERREN 0x0000000000000100UL /* PCI Error Interrupt Enable */
ian@0 131 #define SABRE_PCICTRL_RTRYWE 0x0000000000000080UL /* DMA Flow Control 0=wait-if-possible 1=retry */
ian@0 132 #define SABRE_PCICTRL_AEN 0x000000000000000fUL /* Slot PCI arbitration enables */
ian@0 133 #define SABRE_PIOAFSR 0x2010UL
ian@0 134 #define SABRE_PIOAFSR_PMA 0x8000000000000000UL /* Primary Master Abort */
ian@0 135 #define SABRE_PIOAFSR_PTA 0x4000000000000000UL /* Primary Target Abort */
ian@0 136 #define SABRE_PIOAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
ian@0 137 #define SABRE_PIOAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
ian@0 138 #define SABRE_PIOAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort */
ian@0 139 #define SABRE_PIOAFSR_STA 0x0400000000000000UL /* Secondary Target Abort */
ian@0 140 #define SABRE_PIOAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
ian@0 141 #define SABRE_PIOAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
ian@0 142 #define SABRE_PIOAFSR_BMSK 0x0000ffff00000000UL /* Byte Mask */
ian@0 143 #define SABRE_PIOAFSR_BLK 0x0000000080000000UL /* Was Block Operation */
ian@0 144 #define SABRE_PIOAFAR 0x2018UL
ian@0 145 #define SABRE_PCIDIAG 0x2020UL
ian@0 146 #define SABRE_PCIDIAG_DRTRY 0x0000000000000040UL /* Disable PIO Retry Limit */
ian@0 147 #define SABRE_PCIDIAG_IPAPAR 0x0000000000000008UL /* Invert PIO Address Parity */
ian@0 148 #define SABRE_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO Data Parity */
ian@0 149 #define SABRE_PCIDIAG_IDDPAR 0x0000000000000002UL /* Invert DMA Data Parity */
ian@0 150 #define SABRE_PCIDIAG_ELPBK 0x0000000000000001UL /* Loopback Enable - not supported */
ian@0 151 #define SABRE_PCITASR 0x2028UL
ian@0 152 #define SABRE_PCITASR_EF 0x0000000000000080UL /* Respond to 0xe0000000-0xffffffff */
ian@0 153 #define SABRE_PCITASR_CD 0x0000000000000040UL /* Respond to 0xc0000000-0xdfffffff */
ian@0 154 #define SABRE_PCITASR_AB 0x0000000000000020UL /* Respond to 0xa0000000-0xbfffffff */
ian@0 155 #define SABRE_PCITASR_89 0x0000000000000010UL /* Respond to 0x80000000-0x9fffffff */
ian@0 156 #define SABRE_PCITASR_67 0x0000000000000008UL /* Respond to 0x60000000-0x7fffffff */
ian@0 157 #define SABRE_PCITASR_45 0x0000000000000004UL /* Respond to 0x40000000-0x5fffffff */
ian@0 158 #define SABRE_PCITASR_23 0x0000000000000002UL /* Respond to 0x20000000-0x3fffffff */
ian@0 159 #define SABRE_PCITASR_01 0x0000000000000001UL /* Respond to 0x00000000-0x1fffffff */
ian@0 160 #define SABRE_PIOBUF_DIAG 0x5000UL
ian@0 161 #define SABRE_DMABUF_DIAGLO 0x5100UL
ian@0 162 #define SABRE_DMABUF_DIAGHI 0x51c0UL
ian@0 163 #define SABRE_IMAP_GFX_ALIAS 0x6000UL /* Aliases to 0x1098 */
ian@0 164 #define SABRE_IMAP_EUPA_ALIAS 0x8000UL /* Aliases to 0x10a0 */
ian@0 165 #define SABRE_IOMMU_VADIAG 0xa400UL
ian@0 166 #define SABRE_IOMMU_TCDIAG 0xa408UL
ian@0 167 #define SABRE_IOMMU_TAG 0xa580UL
ian@0 168 #define SABRE_IOMMUTAG_ERRSTS 0x0000000001800000UL /* Error status bits */
ian@0 169 #define SABRE_IOMMUTAG_ERR 0x0000000000400000UL /* Error present */
ian@0 170 #define SABRE_IOMMUTAG_WRITE 0x0000000000200000UL /* Page is writable */
ian@0 171 #define SABRE_IOMMUTAG_STREAM 0x0000000000100000UL /* Streamable bit - unused */
ian@0 172 #define SABRE_IOMMUTAG_SIZE 0x0000000000080000UL /* 0=8k 1=16k */
ian@0 173 #define SABRE_IOMMUTAG_VPN 0x000000000007ffffUL /* Virtual Page Number [31:13] */
ian@0 174 #define SABRE_IOMMU_DATA 0xa600UL
ian@0 175 #define SABRE_IOMMUDATA_VALID 0x0000000040000000UL /* Valid */
ian@0 176 #define SABRE_IOMMUDATA_USED 0x0000000020000000UL /* Used (for LRU algorithm) */
ian@0 177 #define SABRE_IOMMUDATA_CACHE 0x0000000010000000UL /* Cacheable */
ian@0 178 #define SABRE_IOMMUDATA_PPN 0x00000000001fffffUL /* Physical Page Number [33:13] */
ian@0 179 #define SABRE_PCI_IRQSTATE 0xa800UL
ian@0 180 #define SABRE_OBIO_IRQSTATE 0xa808UL
ian@0 181 #define SABRE_FFBCFG 0xf000UL
ian@0 182 #define SABRE_FFBCFG_SPRQS 0x000000000f000000 /* Slave P_RQST queue size */
ian@0 183 #define SABRE_FFBCFG_ONEREAD 0x0000000000004000 /* Slave supports one outstanding read */
ian@0 184 #define SABRE_MCCTRL0 0xf010UL
ian@0 185 #define SABRE_MCCTRL0_RENAB 0x0000000080000000 /* Refresh Enable */
ian@0 186 #define SABRE_MCCTRL0_EENAB 0x0000000010000000 /* Enable all ECC functions */
ian@0 187 #define SABRE_MCCTRL0_11BIT 0x0000000000001000 /* Enable 11-bit column addressing */
ian@0 188 #define SABRE_MCCTRL0_DPP 0x0000000000000f00 /* DIMM Pair Present Bits */
ian@0 189 #define SABRE_MCCTRL0_RINTVL 0x00000000000000ff /* Refresh Interval */
ian@0 190 #define SABRE_MCCTRL1 0xf018UL
ian@0 191 #define SABRE_MCCTRL1_AMDC 0x0000000038000000 /* Advance Memdata Clock */
ian@0 192 #define SABRE_MCCTRL1_ARDC 0x0000000007000000 /* Advance DRAM Read Data Clock */
ian@0 193 #define SABRE_MCCTRL1_CSR 0x0000000000e00000 /* CAS to RAS delay for CBR refresh */
ian@0 194 #define SABRE_MCCTRL1_CASRW 0x00000000001c0000 /* CAS length for read/write */
ian@0 195 #define SABRE_MCCTRL1_RCD 0x0000000000038000 /* RAS to CAS delay */
ian@0 196 #define SABRE_MCCTRL1_CP 0x0000000000007000 /* CAS Precharge */
ian@0 197 #define SABRE_MCCTRL1_RP 0x0000000000000e00 /* RAS Precharge */
ian@0 198 #define SABRE_MCCTRL1_RAS 0x00000000000001c0 /* Length of RAS for refresh */
ian@0 199 #define SABRE_MCCTRL1_CASRW2 0x0000000000000038 /* Must be same as CASRW */
ian@0 200 #define SABRE_MCCTRL1_RSC 0x0000000000000007 /* RAS after CAS hold time */
ian@0 201 #define SABRE_RESETCTRL 0xf020UL
ian@0 202
ian@0 203 #define SABRE_CONFIGSPACE 0x001000000UL
ian@0 204 #define SABRE_IOSPACE 0x002000000UL
ian@0 205 #define SABRE_IOSPACE_SIZE 0x000ffffffUL
ian@0 206 #define SABRE_MEMSPACE 0x100000000UL
ian@0 207 #define SABRE_MEMSPACE_SIZE 0x07fffffffUL
ian@0 208
ian@0 209 /* UltraSparc-IIi Programmer's Manual, page 325, PCI
ian@0 210 * configuration space address format:
ian@0 211 *
ian@0 212 * 32 24 23 16 15 11 10 8 7 2 1 0
ian@0 213 * ---------------------------------------------------------
ian@0 214 * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
ian@0 215 * ---------------------------------------------------------
ian@0 216 */
ian@0 217 #define SABRE_CONFIG_BASE(PBM) \
ian@0 218 ((PBM)->config_space | (1UL << 24))
ian@0 219 #define SABRE_CONFIG_ENCODE(BUS, DEVFN, REG) \
ian@0 220 (((unsigned long)(BUS) << 16) | \
ian@0 221 ((unsigned long)(DEVFN) << 8) | \
ian@0 222 ((unsigned long)(REG)))
ian@0 223
ian@0 224 static int hummingbird_p;
ian@0 225 static struct pci_bus *sabre_root_bus;
ian@0 226
ian@0 227 static void *sabre_pci_config_mkaddr(struct pci_pbm_info *pbm,
ian@0 228 unsigned char bus,
ian@0 229 unsigned int devfn,
ian@0 230 int where)
ian@0 231 {
ian@0 232 if (!pbm)
ian@0 233 return NULL;
ian@0 234 return (void *)
ian@0 235 (SABRE_CONFIG_BASE(pbm) |
ian@0 236 SABRE_CONFIG_ENCODE(bus, devfn, where));
ian@0 237 }
ian@0 238
ian@0 239 static int sabre_out_of_range(unsigned char devfn)
ian@0 240 {
ian@0 241 if (hummingbird_p)
ian@0 242 return 0;
ian@0 243
ian@0 244 return (((PCI_SLOT(devfn) == 0) && (PCI_FUNC(devfn) > 0)) ||
ian@0 245 ((PCI_SLOT(devfn) == 1) && (PCI_FUNC(devfn) > 1)) ||
ian@0 246 (PCI_SLOT(devfn) > 1));
ian@0 247 }
ian@0 248
ian@0 249 static int __sabre_out_of_range(struct pci_pbm_info *pbm,
ian@0 250 unsigned char bus,
ian@0 251 unsigned char devfn)
ian@0 252 {
ian@0 253 if (hummingbird_p)
ian@0 254 return 0;
ian@0 255
ian@0 256 return ((pbm->parent == 0) ||
ian@0 257 ((pbm == &pbm->parent->pbm_B) &&
ian@0 258 (bus == pbm->pci_first_busno) &&
ian@0 259 PCI_SLOT(devfn) > 8) ||
ian@0 260 ((pbm == &pbm->parent->pbm_A) &&
ian@0 261 (bus == pbm->pci_first_busno) &&
ian@0 262 PCI_SLOT(devfn) > 8));
ian@0 263 }
ian@0 264
ian@0 265 static int __sabre_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
ian@0 266 int where, int size, u32 *value)
ian@0 267 {
ian@0 268 struct pci_pbm_info *pbm = bus_dev->sysdata;
ian@0 269 unsigned char bus = bus_dev->number;
ian@0 270 u32 *addr;
ian@0 271 u16 tmp16;
ian@0 272 u8 tmp8;
ian@0 273
ian@0 274 switch (size) {
ian@0 275 case 1:
ian@0 276 *value = 0xff;
ian@0 277 break;
ian@0 278 case 2:
ian@0 279 *value = 0xffff;
ian@0 280 break;
ian@0 281 case 4:
ian@0 282 *value = 0xffffffff;
ian@0 283 break;
ian@0 284 }
ian@0 285
ian@0 286 addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
ian@0 287 if (!addr)
ian@0 288 return PCIBIOS_SUCCESSFUL;
ian@0 289
ian@0 290 if (__sabre_out_of_range(pbm, bus, devfn))
ian@0 291 return PCIBIOS_SUCCESSFUL;
ian@0 292
ian@0 293 switch (size) {
ian@0 294 case 1:
ian@0 295 pci_config_read8((u8 *) addr, &tmp8);
ian@0 296 *value = tmp8;
ian@0 297 break;
ian@0 298
ian@0 299 case 2:
ian@0 300 if (where & 0x01) {
ian@0 301 printk("pci_read_config_word: misaligned reg [%x]\n",
ian@0 302 where);
ian@0 303 return PCIBIOS_SUCCESSFUL;
ian@0 304 }
ian@0 305 pci_config_read16((u16 *) addr, &tmp16);
ian@0 306 *value = tmp16;
ian@0 307 break;
ian@0 308
ian@0 309 case 4:
ian@0 310 if (where & 0x03) {
ian@0 311 printk("pci_read_config_dword: misaligned reg [%x]\n",
ian@0 312 where);
ian@0 313 return PCIBIOS_SUCCESSFUL;
ian@0 314 }
ian@0 315 pci_config_read32(addr, value);
ian@0 316 break;
ian@0 317 }
ian@0 318
ian@0 319 return PCIBIOS_SUCCESSFUL;
ian@0 320 }
ian@0 321
ian@0 322 static int sabre_read_pci_cfg(struct pci_bus *bus, unsigned int devfn,
ian@0 323 int where, int size, u32 *value)
ian@0 324 {
ian@0 325 if (!bus->number && sabre_out_of_range(devfn)) {
ian@0 326 switch (size) {
ian@0 327 case 1:
ian@0 328 *value = 0xff;
ian@0 329 break;
ian@0 330 case 2:
ian@0 331 *value = 0xffff;
ian@0 332 break;
ian@0 333 case 4:
ian@0 334 *value = 0xffffffff;
ian@0 335 break;
ian@0 336 }
ian@0 337 return PCIBIOS_SUCCESSFUL;
ian@0 338 }
ian@0 339
ian@0 340 if (bus->number || PCI_SLOT(devfn))
ian@0 341 return __sabre_read_pci_cfg(bus, devfn, where, size, value);
ian@0 342
ian@0 343 /* When accessing PCI config space of the PCI controller itself (bus
ian@0 344 * 0, device slot 0, function 0) there are restrictions. Each
ian@0 345 * register must be accessed as it's natural size. Thus, for example
ian@0 346 * the Vendor ID must be accessed as a 16-bit quantity.
ian@0 347 */
ian@0 348
ian@0 349 switch (size) {
ian@0 350 case 1:
ian@0 351 if (where < 8) {
ian@0 352 u32 tmp32;
ian@0 353 u16 tmp16;
ian@0 354
ian@0 355 __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
ian@0 356 tmp16 = (u16) tmp32;
ian@0 357 if (where & 1)
ian@0 358 *value = tmp16 >> 8;
ian@0 359 else
ian@0 360 *value = tmp16 & 0xff;
ian@0 361 } else
ian@0 362 return __sabre_read_pci_cfg(bus, devfn, where, 1, value);
ian@0 363 break;
ian@0 364
ian@0 365 case 2:
ian@0 366 if (where < 8)
ian@0 367 return __sabre_read_pci_cfg(bus, devfn, where, 2, value);
ian@0 368 else {
ian@0 369 u32 tmp32;
ian@0 370 u8 tmp8;
ian@0 371
ian@0 372 __sabre_read_pci_cfg(bus, devfn, where, 1, &tmp32);
ian@0 373 tmp8 = (u8) tmp32;
ian@0 374 *value = tmp8;
ian@0 375 __sabre_read_pci_cfg(bus, devfn, where + 1, 1, &tmp32);
ian@0 376 tmp8 = (u8) tmp32;
ian@0 377 *value |= tmp8 << 8;
ian@0 378 }
ian@0 379 break;
ian@0 380
ian@0 381 case 4: {
ian@0 382 u32 tmp32;
ian@0 383 u16 tmp16;
ian@0 384
ian@0 385 sabre_read_pci_cfg(bus, devfn, where, 2, &tmp32);
ian@0 386 tmp16 = (u16) tmp32;
ian@0 387 *value = tmp16;
ian@0 388 sabre_read_pci_cfg(bus, devfn, where + 2, 2, &tmp32);
ian@0 389 tmp16 = (u16) tmp32;
ian@0 390 *value |= tmp16 << 16;
ian@0 391 break;
ian@0 392 }
ian@0 393 }
ian@0 394 return PCIBIOS_SUCCESSFUL;
ian@0 395 }
ian@0 396
ian@0 397 static int __sabre_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
ian@0 398 int where, int size, u32 value)
ian@0 399 {
ian@0 400 struct pci_pbm_info *pbm = bus_dev->sysdata;
ian@0 401 unsigned char bus = bus_dev->number;
ian@0 402 u32 *addr;
ian@0 403
ian@0 404 addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
ian@0 405 if (!addr)
ian@0 406 return PCIBIOS_SUCCESSFUL;
ian@0 407
ian@0 408 if (__sabre_out_of_range(pbm, bus, devfn))
ian@0 409 return PCIBIOS_SUCCESSFUL;
ian@0 410
ian@0 411 switch (size) {
ian@0 412 case 1:
ian@0 413 pci_config_write8((u8 *) addr, value);
ian@0 414 break;
ian@0 415
ian@0 416 case 2:
ian@0 417 if (where & 0x01) {
ian@0 418 printk("pci_write_config_word: misaligned reg [%x]\n",
ian@0 419 where);
ian@0 420 return PCIBIOS_SUCCESSFUL;
ian@0 421 }
ian@0 422 pci_config_write16((u16 *) addr, value);
ian@0 423 break;
ian@0 424
ian@0 425 case 4:
ian@0 426 if (where & 0x03) {
ian@0 427 printk("pci_write_config_dword: misaligned reg [%x]\n",
ian@0 428 where);
ian@0 429 return PCIBIOS_SUCCESSFUL;
ian@0 430 }
ian@0 431 pci_config_write32(addr, value);
ian@0 432 break;
ian@0 433 }
ian@0 434
ian@0 435 return PCIBIOS_SUCCESSFUL;
ian@0 436 }
ian@0 437
ian@0 438 static int sabre_write_pci_cfg(struct pci_bus *bus, unsigned int devfn,
ian@0 439 int where, int size, u32 value)
ian@0 440 {
ian@0 441 if (bus->number)
ian@0 442 return __sabre_write_pci_cfg(bus, devfn, where, size, value);
ian@0 443
ian@0 444 if (sabre_out_of_range(devfn))
ian@0 445 return PCIBIOS_SUCCESSFUL;
ian@0 446
ian@0 447 switch (size) {
ian@0 448 case 1:
ian@0 449 if (where < 8) {
ian@0 450 u32 tmp32;
ian@0 451 u16 tmp16;
ian@0 452
ian@0 453 __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
ian@0 454 tmp16 = (u16) tmp32;
ian@0 455 if (where & 1) {
ian@0 456 value &= 0x00ff;
ian@0 457 value |= tmp16 << 8;
ian@0 458 } else {
ian@0 459 value &= 0xff00;
ian@0 460 value |= tmp16;
ian@0 461 }
ian@0 462 tmp32 = (u32) tmp16;
ian@0 463 return __sabre_write_pci_cfg(bus, devfn, where & ~1, 2, tmp32);
ian@0 464 } else
ian@0 465 return __sabre_write_pci_cfg(bus, devfn, where, 1, value);
ian@0 466 break;
ian@0 467 case 2:
ian@0 468 if (where < 8)
ian@0 469 return __sabre_write_pci_cfg(bus, devfn, where, 2, value);
ian@0 470 else {
ian@0 471 __sabre_write_pci_cfg(bus, devfn, where, 1, value & 0xff);
ian@0 472 __sabre_write_pci_cfg(bus, devfn, where + 1, 1, value >> 8);
ian@0 473 }
ian@0 474 break;
ian@0 475 case 4:
ian@0 476 sabre_write_pci_cfg(bus, devfn, where, 2, value & 0xffff);
ian@0 477 sabre_write_pci_cfg(bus, devfn, where + 2, 2, value >> 16);
ian@0 478 break;
ian@0 479 }
ian@0 480 return PCIBIOS_SUCCESSFUL;
ian@0 481 }
ian@0 482
ian@0 483 static struct pci_ops sabre_ops = {
ian@0 484 .read = sabre_read_pci_cfg,
ian@0 485 .write = sabre_write_pci_cfg,
ian@0 486 };
ian@0 487
ian@0 488 /* SABRE error handling support. */
ian@0 489 static void sabre_check_iommu_error(struct pci_controller_info *p,
ian@0 490 unsigned long afsr,
ian@0 491 unsigned long afar)
ian@0 492 {
ian@0 493 struct pci_iommu *iommu = p->pbm_A.iommu;
ian@0 494 unsigned long iommu_tag[16];
ian@0 495 unsigned long iommu_data[16];
ian@0 496 unsigned long flags;
ian@0 497 u64 control;
ian@0 498 int i;
ian@0 499
ian@0 500 spin_lock_irqsave(&iommu->lock, flags);
ian@0 501 control = sabre_read(iommu->iommu_control);
ian@0 502 if (control & SABRE_IOMMUCTRL_ERR) {
ian@0 503 char *type_string;
ian@0 504
ian@0 505 /* Clear the error encountered bit.
ian@0 506 * NOTE: On Sabre this is write 1 to clear,
ian@0 507 * which is different from Psycho.
ian@0 508 */
ian@0 509 sabre_write(iommu->iommu_control, control);
ian@0 510 switch((control & SABRE_IOMMUCTRL_ERRSTS) >> 25UL) {
ian@0 511 case 1:
ian@0 512 type_string = "Invalid Error";
ian@0 513 break;
ian@0 514 case 3:
ian@0 515 type_string = "ECC Error";
ian@0 516 break;
ian@0 517 default:
ian@0 518 type_string = "Unknown";
ian@0 519 break;
ian@0 520 };
ian@0 521 printk("SABRE%d: IOMMU Error, type[%s]\n",
ian@0 522 p->index, type_string);
ian@0 523
ian@0 524 /* Enter diagnostic mode and probe for error'd
ian@0 525 * entries in the IOTLB.
ian@0 526 */
ian@0 527 control &= ~(SABRE_IOMMUCTRL_ERRSTS | SABRE_IOMMUCTRL_ERR);
ian@0 528 sabre_write(iommu->iommu_control,
ian@0 529 (control | SABRE_IOMMUCTRL_DENAB));
ian@0 530 for (i = 0; i < 16; i++) {
ian@0 531 unsigned long base = p->pbm_A.controller_regs;
ian@0 532
ian@0 533 iommu_tag[i] =
ian@0 534 sabre_read(base + SABRE_IOMMU_TAG + (i * 8UL));
ian@0 535 iommu_data[i] =
ian@0 536 sabre_read(base + SABRE_IOMMU_DATA + (i * 8UL));
ian@0 537 sabre_write(base + SABRE_IOMMU_TAG + (i * 8UL), 0);
ian@0 538 sabre_write(base + SABRE_IOMMU_DATA + (i * 8UL), 0);
ian@0 539 }
ian@0 540 sabre_write(iommu->iommu_control, control);
ian@0 541
ian@0 542 for (i = 0; i < 16; i++) {
ian@0 543 unsigned long tag, data;
ian@0 544
ian@0 545 tag = iommu_tag[i];
ian@0 546 if (!(tag & SABRE_IOMMUTAG_ERR))
ian@0 547 continue;
ian@0 548
ian@0 549 data = iommu_data[i];
ian@0 550 switch((tag & SABRE_IOMMUTAG_ERRSTS) >> 23UL) {
ian@0 551 case 1:
ian@0 552 type_string = "Invalid Error";
ian@0 553 break;
ian@0 554 case 3:
ian@0 555 type_string = "ECC Error";
ian@0 556 break;
ian@0 557 default:
ian@0 558 type_string = "Unknown";
ian@0 559 break;
ian@0 560 };
ian@0 561 printk("SABRE%d: IOMMU TAG(%d)[RAW(%016lx)error(%s)wr(%d)sz(%dK)vpg(%08lx)]\n",
ian@0 562 p->index, i, tag, type_string,
ian@0 563 ((tag & SABRE_IOMMUTAG_WRITE) ? 1 : 0),
ian@0 564 ((tag & SABRE_IOMMUTAG_SIZE) ? 64 : 8),
ian@0 565 ((tag & SABRE_IOMMUTAG_VPN) << IOMMU_PAGE_SHIFT));
ian@0 566 printk("SABRE%d: IOMMU DATA(%d)[RAW(%016lx)valid(%d)used(%d)cache(%d)ppg(%016lx)\n",
ian@0 567 p->index, i, data,
ian@0 568 ((data & SABRE_IOMMUDATA_VALID) ? 1 : 0),
ian@0 569 ((data & SABRE_IOMMUDATA_USED) ? 1 : 0),
ian@0 570 ((data & SABRE_IOMMUDATA_CACHE) ? 1 : 0),
ian@0 571 ((data & SABRE_IOMMUDATA_PPN) << IOMMU_PAGE_SHIFT));
ian@0 572 }
ian@0 573 }
ian@0 574 spin_unlock_irqrestore(&iommu->lock, flags);
ian@0 575 }
ian@0 576
ian@0 577 static irqreturn_t sabre_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
ian@0 578 {
ian@0 579 struct pci_controller_info *p = dev_id;
ian@0 580 unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_UE_AFSR;
ian@0 581 unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
ian@0 582 unsigned long afsr, afar, error_bits;
ian@0 583 int reported;
ian@0 584
ian@0 585 /* Latch uncorrectable error status. */
ian@0 586 afar = sabre_read(afar_reg);
ian@0 587 afsr = sabre_read(afsr_reg);
ian@0 588
ian@0 589 /* Clear the primary/secondary error status bits. */
ian@0 590 error_bits = afsr &
ian@0 591 (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
ian@0 592 SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
ian@0 593 SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE);
ian@0 594 if (!error_bits)
ian@0 595 return IRQ_NONE;
ian@0 596 sabre_write(afsr_reg, error_bits);
ian@0 597
ian@0 598 /* Log the error. */
ian@0 599 printk("SABRE%d: Uncorrectable Error, primary error type[%s%s]\n",
ian@0 600 p->index,
ian@0 601 ((error_bits & SABRE_UEAFSR_PDRD) ?
ian@0 602 "DMA Read" :
ian@0 603 ((error_bits & SABRE_UEAFSR_PDWR) ?
ian@0 604 "DMA Write" : "???")),
ian@0 605 ((error_bits & SABRE_UEAFSR_PDTE) ?
ian@0 606 ":Translation Error" : ""));
ian@0 607 printk("SABRE%d: bytemask[%04lx] dword_offset[%lx] was_block(%d)\n",
ian@0 608 p->index,
ian@0 609 (afsr & SABRE_UEAFSR_BMSK) >> 32UL,
ian@0 610 (afsr & SABRE_UEAFSR_OFF) >> 29UL,
ian@0 611 ((afsr & SABRE_UEAFSR_BLK) ? 1 : 0));
ian@0 612 printk("SABRE%d: UE AFAR [%016lx]\n", p->index, afar);
ian@0 613 printk("SABRE%d: UE Secondary errors [", p->index);
ian@0 614 reported = 0;
ian@0 615 if (afsr & SABRE_UEAFSR_SDRD) {
ian@0 616 reported++;
ian@0 617 printk("(DMA Read)");
ian@0 618 }
ian@0 619 if (afsr & SABRE_UEAFSR_SDWR) {
ian@0 620 reported++;
ian@0 621 printk("(DMA Write)");
ian@0 622 }
ian@0 623 if (afsr & SABRE_UEAFSR_SDTE) {
ian@0 624 reported++;
ian@0 625 printk("(Translation Error)");
ian@0 626 }
ian@0 627 if (!reported)
ian@0 628 printk("(none)");
ian@0 629 printk("]\n");
ian@0 630
ian@0 631 /* Interrogate IOMMU for error status. */
ian@0 632 sabre_check_iommu_error(p, afsr, afar);
ian@0 633
ian@0 634 return IRQ_HANDLED;
ian@0 635 }
ian@0 636
ian@0 637 static irqreturn_t sabre_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
ian@0 638 {
ian@0 639 struct pci_controller_info *p = dev_id;
ian@0 640 unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_CE_AFSR;
ian@0 641 unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
ian@0 642 unsigned long afsr, afar, error_bits;
ian@0 643 int reported;
ian@0 644
ian@0 645 /* Latch error status. */
ian@0 646 afar = sabre_read(afar_reg);
ian@0 647 afsr = sabre_read(afsr_reg);
ian@0 648
ian@0 649 /* Clear primary/secondary error status bits. */
ian@0 650 error_bits = afsr &
ian@0 651 (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
ian@0 652 SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR);
ian@0 653 if (!error_bits)
ian@0 654 return IRQ_NONE;
ian@0 655 sabre_write(afsr_reg, error_bits);
ian@0 656
ian@0 657 /* Log the error. */
ian@0 658 printk("SABRE%d: Correctable Error, primary error type[%s]\n",
ian@0 659 p->index,
ian@0 660 ((error_bits & SABRE_CEAFSR_PDRD) ?
ian@0 661 "DMA Read" :
ian@0 662 ((error_bits & SABRE_CEAFSR_PDWR) ?
ian@0 663 "DMA Write" : "???")));
ian@0 664
ian@0 665 /* XXX Use syndrome and afar to print out module string just like
ian@0 666 * XXX UDB CE trap handler does... -DaveM
ian@0 667 */
ian@0 668 printk("SABRE%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
ian@0 669 "was_block(%d)\n",
ian@0 670 p->index,
ian@0 671 (afsr & SABRE_CEAFSR_ESYND) >> 48UL,
ian@0 672 (afsr & SABRE_CEAFSR_BMSK) >> 32UL,
ian@0 673 (afsr & SABRE_CEAFSR_OFF) >> 29UL,
ian@0 674 ((afsr & SABRE_CEAFSR_BLK) ? 1 : 0));
ian@0 675 printk("SABRE%d: CE AFAR [%016lx]\n", p->index, afar);
ian@0 676 printk("SABRE%d: CE Secondary errors [", p->index);
ian@0 677 reported = 0;
ian@0 678 if (afsr & SABRE_CEAFSR_SDRD) {
ian@0 679 reported++;
ian@0 680 printk("(DMA Read)");
ian@0 681 }
ian@0 682 if (afsr & SABRE_CEAFSR_SDWR) {
ian@0 683 reported++;
ian@0 684 printk("(DMA Write)");
ian@0 685 }
ian@0 686 if (!reported)
ian@0 687 printk("(none)");
ian@0 688 printk("]\n");
ian@0 689
ian@0 690 return IRQ_HANDLED;
ian@0 691 }
ian@0 692
ian@0 693 static irqreturn_t sabre_pcierr_intr_other(struct pci_controller_info *p)
ian@0 694 {
ian@0 695 unsigned long csr_reg, csr, csr_error_bits;
ian@0 696 irqreturn_t ret = IRQ_NONE;
ian@0 697 u16 stat;
ian@0 698
ian@0 699 csr_reg = p->pbm_A.controller_regs + SABRE_PCICTRL;
ian@0 700 csr = sabre_read(csr_reg);
ian@0 701 csr_error_bits =
ian@0 702 csr & SABRE_PCICTRL_SERR;
ian@0 703 if (csr_error_bits) {
ian@0 704 /* Clear the errors. */
ian@0 705 sabre_write(csr_reg, csr);
ian@0 706
ian@0 707 /* Log 'em. */
ian@0 708 if (csr_error_bits & SABRE_PCICTRL_SERR)
ian@0 709 printk("SABRE%d: PCI SERR signal asserted.\n",
ian@0 710 p->index);
ian@0 711 ret = IRQ_HANDLED;
ian@0 712 }
ian@0 713 pci_read_config_word(sabre_root_bus->self,
ian@0 714 PCI_STATUS, &stat);
ian@0 715 if (stat & (PCI_STATUS_PARITY |
ian@0 716 PCI_STATUS_SIG_TARGET_ABORT |
ian@0 717 PCI_STATUS_REC_TARGET_ABORT |
ian@0 718 PCI_STATUS_REC_MASTER_ABORT |
ian@0 719 PCI_STATUS_SIG_SYSTEM_ERROR)) {
ian@0 720 printk("SABRE%d: PCI bus error, PCI_STATUS[%04x]\n",
ian@0 721 p->index, stat);
ian@0 722 pci_write_config_word(sabre_root_bus->self,
ian@0 723 PCI_STATUS, 0xffff);
ian@0 724 ret = IRQ_HANDLED;
ian@0 725 }
ian@0 726 return ret;
ian@0 727 }
ian@0 728
ian@0 729 static irqreturn_t sabre_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
ian@0 730 {
ian@0 731 struct pci_controller_info *p = dev_id;
ian@0 732 unsigned long afsr_reg, afar_reg;
ian@0 733 unsigned long afsr, afar, error_bits;
ian@0 734 int reported;
ian@0 735
ian@0 736 afsr_reg = p->pbm_A.controller_regs + SABRE_PIOAFSR;
ian@0 737 afar_reg = p->pbm_A.controller_regs + SABRE_PIOAFAR;
ian@0 738
ian@0 739 /* Latch error status. */
ian@0 740 afar = sabre_read(afar_reg);
ian@0 741 afsr = sabre_read(afsr_reg);
ian@0 742
ian@0 743 /* Clear primary/secondary error status bits. */
ian@0 744 error_bits = afsr &
ian@0 745 (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_PTA |
ian@0 746 SABRE_PIOAFSR_PRTRY | SABRE_PIOAFSR_PPERR |
ian@0 747 SABRE_PIOAFSR_SMA | SABRE_PIOAFSR_STA |
ian@0 748 SABRE_PIOAFSR_SRTRY | SABRE_PIOAFSR_SPERR);
ian@0 749 if (!error_bits)
ian@0 750 return sabre_pcierr_intr_other(p);
ian@0 751 sabre_write(afsr_reg, error_bits);
ian@0 752
ian@0 753 /* Log the error. */
ian@0 754 printk("SABRE%d: PCI Error, primary error type[%s]\n",
ian@0 755 p->index,
ian@0 756 (((error_bits & SABRE_PIOAFSR_PMA) ?
ian@0 757 "Master Abort" :
ian@0 758 ((error_bits & SABRE_PIOAFSR_PTA) ?
ian@0 759 "Target Abort" :
ian@0 760 ((error_bits & SABRE_PIOAFSR_PRTRY) ?
ian@0 761 "Excessive Retries" :
ian@0 762 ((error_bits & SABRE_PIOAFSR_PPERR) ?
ian@0 763 "Parity Error" : "???"))))));
ian@0 764 printk("SABRE%d: bytemask[%04lx] was_block(%d)\n",
ian@0 765 p->index,
ian@0 766 (afsr & SABRE_PIOAFSR_BMSK) >> 32UL,
ian@0 767 (afsr & SABRE_PIOAFSR_BLK) ? 1 : 0);
ian@0 768 printk("SABRE%d: PCI AFAR [%016lx]\n", p->index, afar);
ian@0 769 printk("SABRE%d: PCI Secondary errors [", p->index);
ian@0 770 reported = 0;
ian@0 771 if (afsr & SABRE_PIOAFSR_SMA) {
ian@0 772 reported++;
ian@0 773 printk("(Master Abort)");
ian@0 774 }
ian@0 775 if (afsr & SABRE_PIOAFSR_STA) {
ian@0 776 reported++;
ian@0 777 printk("(Target Abort)");
ian@0 778 }
ian@0 779 if (afsr & SABRE_PIOAFSR_SRTRY) {
ian@0 780 reported++;
ian@0 781 printk("(Excessive Retries)");
ian@0 782 }
ian@0 783 if (afsr & SABRE_PIOAFSR_SPERR) {
ian@0 784 reported++;
ian@0 785 printk("(Parity Error)");
ian@0 786 }
ian@0 787 if (!reported)
ian@0 788 printk("(none)");
ian@0 789 printk("]\n");
ian@0 790
ian@0 791 /* For the error types shown, scan both PCI buses for devices
ian@0 792 * which have logged that error type.
ian@0 793 */
ian@0 794
ian@0 795 /* If we see a Target Abort, this could be the result of an
ian@0 796 * IOMMU translation error of some sort. It is extremely
ian@0 797 * useful to log this information as usually it indicates
ian@0 798 * a bug in the IOMMU support code or a PCI device driver.
ian@0 799 */
ian@0 800 if (error_bits & (SABRE_PIOAFSR_PTA | SABRE_PIOAFSR_STA)) {
ian@0 801 sabre_check_iommu_error(p, afsr, afar);
ian@0 802 pci_scan_for_target_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
ian@0 803 pci_scan_for_target_abort(p, &p->pbm_B, p->pbm_B.pci_bus);
ian@0 804 }
ian@0 805 if (error_bits & (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_SMA)) {
ian@0 806 pci_scan_for_master_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
ian@0 807 pci_scan_for_master_abort(p, &p->pbm_B, p->pbm_B.pci_bus);
ian@0 808 }
ian@0 809 /* For excessive retries, SABRE/PBM will abort the device
ian@0 810 * and there is no way to specifically check for excessive
ian@0 811 * retries in the config space status registers. So what
ian@0 812 * we hope is that we'll catch it via the master/target
ian@0 813 * abort events.
ian@0 814 */
ian@0 815
ian@0 816 if (error_bits & (SABRE_PIOAFSR_PPERR | SABRE_PIOAFSR_SPERR)) {
ian@0 817 pci_scan_for_parity_error(p, &p->pbm_A, p->pbm_A.pci_bus);
ian@0 818 pci_scan_for_parity_error(p, &p->pbm_B, p->pbm_B.pci_bus);
ian@0 819 }
ian@0 820
ian@0 821 return IRQ_HANDLED;
ian@0 822 }
ian@0 823
ian@0 824 static void sabre_register_error_handlers(struct pci_controller_info *p)
ian@0 825 {
ian@0 826 struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
ian@0 827 struct device_node *dp = pbm->prom_node;
ian@0 828 struct of_device *op;
ian@0 829 unsigned long base = pbm->controller_regs;
ian@0 830 u64 tmp;
ian@0 831
ian@0 832 if (pbm->chip_type == PBM_CHIP_TYPE_SABRE)
ian@0 833 dp = dp->parent;
ian@0 834
ian@0 835 op = of_find_device_by_node(dp);
ian@0 836 if (!op)
ian@0 837 return;
ian@0 838
ian@0 839 /* Sabre/Hummingbird IRQ property layout is:
ian@0 840 * 0: PCI ERR
ian@0 841 * 1: UE ERR
ian@0 842 * 2: CE ERR
ian@0 843 * 3: POWER FAIL
ian@0 844 */
ian@0 845 if (op->num_irqs < 4)
ian@0 846 return;
ian@0 847
ian@0 848 /* We clear the error bits in the appropriate AFSR before
ian@0 849 * registering the handler so that we don't get spurious
ian@0 850 * interrupts.
ian@0 851 */
ian@0 852 sabre_write(base + SABRE_UE_AFSR,
ian@0 853 (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
ian@0 854 SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
ian@0 855 SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE));
ian@0 856
ian@0 857 request_irq(op->irqs[1], sabre_ue_intr, IRQF_SHARED, "SABRE UE", p);
ian@0 858
ian@0 859 sabre_write(base + SABRE_CE_AFSR,
ian@0 860 (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
ian@0 861 SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR));
ian@0 862
ian@0 863 request_irq(op->irqs[2], sabre_ce_intr, IRQF_SHARED, "SABRE CE", p);
ian@0 864 request_irq(op->irqs[0], sabre_pcierr_intr, IRQF_SHARED,
ian@0 865 "SABRE PCIERR", p);
ian@0 866
ian@0 867 tmp = sabre_read(base + SABRE_PCICTRL);
ian@0 868 tmp |= SABRE_PCICTRL_ERREN;
ian@0 869 sabre_write(base + SABRE_PCICTRL, tmp);
ian@0 870 }
ian@0 871
ian@0 872 static void sabre_resource_adjust(struct pci_dev *pdev,
ian@0 873 struct resource *res,
ian@0 874 struct resource *root)
ian@0 875 {
ian@0 876 struct pci_pbm_info *pbm = pdev->bus->sysdata;
ian@0 877 unsigned long base;
ian@0 878
ian@0 879 if (res->flags & IORESOURCE_IO)
ian@0 880 base = pbm->controller_regs + SABRE_IOSPACE;
ian@0 881 else
ian@0 882 base = pbm->controller_regs + SABRE_MEMSPACE;
ian@0 883
ian@0 884 res->start += base;
ian@0 885 res->end += base;
ian@0 886 }
ian@0 887
ian@0 888 static void sabre_base_address_update(struct pci_dev *pdev, int resource)
ian@0 889 {
ian@0 890 struct pcidev_cookie *pcp = pdev->sysdata;
ian@0 891 struct pci_pbm_info *pbm = pcp->pbm;
ian@0 892 struct resource *res;
ian@0 893 unsigned long base;
ian@0 894 u32 reg;
ian@0 895 int where, size, is_64bit;
ian@0 896
ian@0 897 res = &pdev->resource[resource];
ian@0 898 if (resource < 6) {
ian@0 899 where = PCI_BASE_ADDRESS_0 + (resource * 4);
ian@0 900 } else if (resource == PCI_ROM_RESOURCE) {
ian@0 901 where = pdev->rom_base_reg;
ian@0 902 } else {
ian@0 903 /* Somebody might have asked allocation of a non-standard resource */
ian@0 904 return;
ian@0 905 }
ian@0 906
ian@0 907 is_64bit = 0;
ian@0 908 if (res->flags & IORESOURCE_IO)
ian@0 909 base = pbm->controller_regs + SABRE_IOSPACE;
ian@0 910 else {
ian@0 911 base = pbm->controller_regs + SABRE_MEMSPACE;
ian@0 912 if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
ian@0 913 == PCI_BASE_ADDRESS_MEM_TYPE_64)
ian@0 914 is_64bit = 1;
ian@0 915 }
ian@0 916
ian@0 917 size = res->end - res->start;
ian@0 918 pci_read_config_dword(pdev, where, &reg);
ian@0 919 reg = ((reg & size) |
ian@0 920 (((u32)(res->start - base)) & ~size));
ian@0 921 if (resource == PCI_ROM_RESOURCE) {
ian@0 922 reg |= PCI_ROM_ADDRESS_ENABLE;
ian@0 923 res->flags |= IORESOURCE_ROM_ENABLE;
ian@0 924 }
ian@0 925 pci_write_config_dword(pdev, where, reg);
ian@0 926
ian@0 927 /* This knows that the upper 32-bits of the address
ian@0 928 * must be zero. Our PCI common layer enforces this.
ian@0 929 */
ian@0 930 if (is_64bit)
ian@0 931 pci_write_config_dword(pdev, where + 4, 0);
ian@0 932 }
ian@0 933
ian@0 934 static void apb_init(struct pci_controller_info *p, struct pci_bus *sabre_bus)
ian@0 935 {
ian@0 936 struct pci_dev *pdev;
ian@0 937
ian@0 938 list_for_each_entry(pdev, &sabre_bus->devices, bus_list) {
ian@0 939
ian@0 940 if (pdev->vendor == PCI_VENDOR_ID_SUN &&
ian@0 941 pdev->device == PCI_DEVICE_ID_SUN_SIMBA) {
ian@0 942 u32 word32;
ian@0 943 u16 word16;
ian@0 944
ian@0 945 sabre_read_pci_cfg(pdev->bus, pdev->devfn,
ian@0 946 PCI_COMMAND, 2, &word32);
ian@0 947 word16 = (u16) word32;
ian@0 948 word16 |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
ian@0 949 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
ian@0 950 PCI_COMMAND_IO;
ian@0 951 word32 = (u32) word16;
ian@0 952 sabre_write_pci_cfg(pdev->bus, pdev->devfn,
ian@0 953 PCI_COMMAND, 2, word32);
ian@0 954
ian@0 955 /* Status register bits are "write 1 to clear". */
ian@0 956 sabre_write_pci_cfg(pdev->bus, pdev->devfn,
ian@0 957 PCI_STATUS, 2, 0xffff);
ian@0 958 sabre_write_pci_cfg(pdev->bus, pdev->devfn,
ian@0 959 PCI_SEC_STATUS, 2, 0xffff);
ian@0 960
ian@0 961 /* Use a primary/seconday latency timer value
ian@0 962 * of 64.
ian@0 963 */
ian@0 964 sabre_write_pci_cfg(pdev->bus, pdev->devfn,
ian@0 965 PCI_LATENCY_TIMER, 1, 64);
ian@0 966 sabre_write_pci_cfg(pdev->bus, pdev->devfn,
ian@0 967 PCI_SEC_LATENCY_TIMER, 1, 64);
ian@0 968
ian@0 969 /* Enable reporting/forwarding of master aborts,
ian@0 970 * parity, and SERR.
ian@0 971 */
ian@0 972 sabre_write_pci_cfg(pdev->bus, pdev->devfn,
ian@0 973 PCI_BRIDGE_CONTROL, 1,
ian@0 974 (PCI_BRIDGE_CTL_PARITY |
ian@0 975 PCI_BRIDGE_CTL_SERR |
ian@0 976 PCI_BRIDGE_CTL_MASTER_ABORT));
ian@0 977 }
ian@0 978 }
ian@0 979 }
ian@0 980
ian@0 981 static struct pcidev_cookie *alloc_bridge_cookie(struct pci_pbm_info *pbm)
ian@0 982 {
ian@0 983 struct pcidev_cookie *cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
ian@0 984
ian@0 985 if (!cookie) {
ian@0 986 prom_printf("SABRE: Critical allocation failure.\n");
ian@0 987 prom_halt();
ian@0 988 }
ian@0 989
ian@0 990 /* All we care about is the PBM. */
ian@0 991 cookie->pbm = pbm;
ian@0 992
ian@0 993 return cookie;
ian@0 994 }
ian@0 995
ian@0 996 static void sabre_scan_bus(struct pci_controller_info *p)
ian@0 997 {
ian@0 998 static int once;
ian@0 999 struct pci_bus *sabre_bus, *pbus;
ian@0 1000 struct pci_pbm_info *pbm;
ian@0 1001 struct pcidev_cookie *cookie;
ian@0 1002 int sabres_scanned;
ian@0 1003
ian@0 1004 /* The APB bridge speaks to the Sabre host PCI bridge
ian@0 1005 * at 66Mhz, but the front side of APB runs at 33Mhz
ian@0 1006 * for both segments.
ian@0 1007 */
ian@0 1008 p->pbm_A.is_66mhz_capable = 0;
ian@0 1009 p->pbm_B.is_66mhz_capable = 0;
ian@0 1010
ian@0 1011 /* This driver has not been verified to handle
ian@0 1012 * multiple SABREs yet, so trap this.
ian@0 1013 *
ian@0 1014 * Also note that the SABRE host bridge is hardwired
ian@0 1015 * to live at bus 0.
ian@0 1016 */
ian@0 1017 if (once != 0) {
ian@0 1018 prom_printf("SABRE: Multiple controllers unsupported.\n");
ian@0 1019 prom_halt();
ian@0 1020 }
ian@0 1021 once++;
ian@0 1022
ian@0 1023 cookie = alloc_bridge_cookie(&p->pbm_A);
ian@0 1024
ian@0 1025 sabre_bus = pci_scan_bus(p->pci_first_busno,
ian@0 1026 p->pci_ops,
ian@0 1027 &p->pbm_A);
ian@0 1028 pci_fixup_host_bridge_self(sabre_bus);
ian@0 1029 sabre_bus->self->sysdata = cookie;
ian@0 1030
ian@0 1031 sabre_root_bus = sabre_bus;
ian@0 1032
ian@0 1033 apb_init(p, sabre_bus);
ian@0 1034
ian@0 1035 sabres_scanned = 0;
ian@0 1036
ian@0 1037 list_for_each_entry(pbus, &sabre_bus->children, node) {
ian@0 1038
ian@0 1039 if (pbus->number == p->pbm_A.pci_first_busno) {
ian@0 1040 pbm = &p->pbm_A;
ian@0 1041 } else if (pbus->number == p->pbm_B.pci_first_busno) {
ian@0 1042 pbm = &p->pbm_B;
ian@0 1043 } else
ian@0 1044 continue;
ian@0 1045
ian@0 1046 cookie = alloc_bridge_cookie(pbm);
ian@0 1047 pbus->self->sysdata = cookie;
ian@0 1048
ian@0 1049 sabres_scanned++;
ian@0 1050
ian@0 1051 pbus->sysdata = pbm;
ian@0 1052 pbm->pci_bus = pbus;
ian@0 1053 pci_fill_in_pbm_cookies(pbus, pbm, pbm->prom_node);
ian@0 1054 pci_record_assignments(pbm, pbus);
ian@0 1055 pci_assign_unassigned(pbm, pbus);
ian@0 1056 pci_fixup_irq(pbm, pbus);
ian@0 1057 pci_determine_66mhz_disposition(pbm, pbus);
ian@0 1058 pci_setup_busmastering(pbm, pbus);
ian@0 1059 }
ian@0 1060
ian@0 1061 if (!sabres_scanned) {
ian@0 1062 /* Hummingbird, no APBs. */
ian@0 1063 pbm = &p->pbm_A;
ian@0 1064 sabre_bus->sysdata = pbm;
ian@0 1065 pbm->pci_bus = sabre_bus;
ian@0 1066 pci_fill_in_pbm_cookies(sabre_bus, pbm, pbm->prom_node);
ian@0 1067 pci_record_assignments(pbm, sabre_bus);
ian@0 1068 pci_assign_unassigned(pbm, sabre_bus);
ian@0 1069 pci_fixup_irq(pbm, sabre_bus);
ian@0 1070 pci_determine_66mhz_disposition(pbm, sabre_bus);
ian@0 1071 pci_setup_busmastering(pbm, sabre_bus);
ian@0 1072 }
ian@0 1073
ian@0 1074 sabre_register_error_handlers(p);
ian@0 1075 }
ian@0 1076
ian@0 1077 static void sabre_iommu_init(struct pci_controller_info *p,
ian@0 1078 int tsbsize, unsigned long dvma_offset,
ian@0 1079 u32 dma_mask)
ian@0 1080 {
ian@0 1081 struct pci_iommu *iommu = p->pbm_A.iommu;
ian@0 1082 unsigned long i;
ian@0 1083 u64 control;
ian@0 1084
ian@0 1085 /* Register addresses. */
ian@0 1086 iommu->iommu_control = p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL;
ian@0 1087 iommu->iommu_tsbbase = p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE;
ian@0 1088 iommu->iommu_flush = p->pbm_A.controller_regs + SABRE_IOMMU_FLUSH;
ian@0 1089 iommu->write_complete_reg = p->pbm_A.controller_regs + SABRE_WRSYNC;
ian@0 1090 /* Sabre's IOMMU lacks ctx flushing. */
ian@0 1091 iommu->iommu_ctxflush = 0;
ian@0 1092
ian@0 1093 /* Invalidate TLB Entries. */
ian@0 1094 control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
ian@0 1095 control |= SABRE_IOMMUCTRL_DENAB;
ian@0 1096 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
ian@0 1097
ian@0 1098 for(i = 0; i < 16; i++) {
ian@0 1099 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TAG + (i * 8UL), 0);
ian@0 1100 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_DATA + (i * 8UL), 0);
ian@0 1101 }
ian@0 1102
ian@0 1103 /* Leave diag mode enabled for full-flushing done
ian@0 1104 * in pci_iommu.c
ian@0 1105 */
ian@0 1106 pci_iommu_table_init(iommu, tsbsize * 1024 * 8, dvma_offset, dma_mask);
ian@0 1107
ian@0 1108 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE,
ian@0 1109 __pa(iommu->page_table));
ian@0 1110
ian@0 1111 control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
ian@0 1112 control &= ~(SABRE_IOMMUCTRL_TSBSZ | SABRE_IOMMUCTRL_TBWSZ);
ian@0 1113 control |= SABRE_IOMMUCTRL_ENAB;
ian@0 1114 switch(tsbsize) {
ian@0 1115 case 64:
ian@0 1116 control |= SABRE_IOMMU_TSBSZ_64K;
ian@0 1117 break;
ian@0 1118 case 128:
ian@0 1119 control |= SABRE_IOMMU_TSBSZ_128K;
ian@0 1120 break;
ian@0 1121 default:
ian@0 1122 prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
ian@0 1123 prom_halt();
ian@0 1124 break;
ian@0 1125 }
ian@0 1126 sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
ian@0 1127 }
ian@0 1128
ian@0 1129 static void pbm_register_toplevel_resources(struct pci_controller_info *p,
ian@0 1130 struct pci_pbm_info *pbm)
ian@0 1131 {
ian@0 1132 char *name = pbm->name;
ian@0 1133 unsigned long ibase = p->pbm_A.controller_regs + SABRE_IOSPACE;
ian@0 1134 unsigned long mbase = p->pbm_A.controller_regs + SABRE_MEMSPACE;
ian@0 1135 unsigned int devfn;
ian@0 1136 unsigned long first, last, i;
ian@0 1137 u8 *addr, map;
ian@0 1138
ian@0 1139 sprintf(name, "SABRE%d PBM%c",
ian@0 1140 p->index,
ian@0 1141 (pbm == &p->pbm_A ? 'A' : 'B'));
ian@0 1142 pbm->io_space.name = pbm->mem_space.name = name;
ian@0 1143
ian@0 1144 devfn = PCI_DEVFN(1, (pbm == &p->pbm_A) ? 0 : 1);
ian@0 1145 addr = sabre_pci_config_mkaddr(pbm, 0, devfn, APB_IO_ADDRESS_MAP);
ian@0 1146 map = 0;
ian@0 1147 pci_config_read8(addr, &map);
ian@0 1148
ian@0 1149 first = 8;
ian@0 1150 last = 0;
ian@0 1151 for (i = 0; i < 8; i++) {
ian@0 1152 if ((map & (1 << i)) != 0) {
ian@0 1153 if (first > i)
ian@0 1154 first = i;
ian@0 1155 if (last < i)
ian@0 1156 last = i;
ian@0 1157 }
ian@0 1158 }
ian@0 1159 pbm->io_space.start = ibase + (first << 21UL);
ian@0 1160 pbm->io_space.end = ibase + (last << 21UL) + ((1 << 21UL) - 1);
ian@0 1161 pbm->io_space.flags = IORESOURCE_IO;
ian@0 1162
ian@0 1163 addr = sabre_pci_config_mkaddr(pbm, 0, devfn, APB_MEM_ADDRESS_MAP);
ian@0 1164 map = 0;
ian@0 1165 pci_config_read8(addr, &map);
ian@0 1166
ian@0 1167 first = 8;
ian@0 1168 last = 0;
ian@0 1169 for (i = 0; i < 8; i++) {
ian@0 1170 if ((map & (1 << i)) != 0) {
ian@0 1171 if (first > i)
ian@0 1172 first = i;
ian@0 1173 if (last < i)
ian@0 1174 last = i;
ian@0 1175 }
ian@0 1176 }
ian@0 1177 pbm->mem_space.start = mbase + (first << 29UL);
ian@0 1178 pbm->mem_space.end = mbase + (last << 29UL) + ((1 << 29UL) - 1);
ian@0 1179 pbm->mem_space.flags = IORESOURCE_MEM;
ian@0 1180
ian@0 1181 if (request_resource(&ioport_resource, &pbm->io_space) < 0) {
ian@0 1182 prom_printf("Cannot register PBM-%c's IO space.\n",
ian@0 1183 (pbm == &p->pbm_A ? 'A' : 'B'));
ian@0 1184 prom_halt();
ian@0 1185 }
ian@0 1186 if (request_resource(&iomem_resource, &pbm->mem_space) < 0) {
ian@0 1187 prom_printf("Cannot register PBM-%c's MEM space.\n",
ian@0 1188 (pbm == &p->pbm_A ? 'A' : 'B'));
ian@0 1189 prom_halt();
ian@0 1190 }
ian@0 1191
ian@0 1192 /* Register legacy regions if this PBM covers that area. */
ian@0 1193 if (pbm->io_space.start == ibase &&
ian@0 1194 pbm->mem_space.start == mbase)
ian@0 1195 pci_register_legacy_regions(&pbm->io_space,
ian@0 1196 &pbm->mem_space);
ian@0 1197 }
ian@0 1198
ian@240 1199 static void sabre_pbm_init(struct pci_controller_info *p, struct device_node *dp, u32 dma_start, u32 dma_end)
ian@0 1200 {
ian@0 1201 struct pci_pbm_info *pbm;
ian@0 1202 struct device_node *node;
ian@0 1203 struct property *prop;
ian@0 1204 u32 *busrange;
ian@0 1205 int len, simbas_found;
ian@0 1206
ian@0 1207 simbas_found = 0;
ian@0 1208 node = dp->child;
ian@0 1209 while (node != NULL) {
ian@0 1210 if (strcmp(node->name, "pci"))
ian@0 1211 goto next_pci;
ian@0 1212
ian@0 1213 prop = of_find_property(node, "model", NULL);
ian@0 1214 if (!prop || strncmp(prop->value, "SUNW,simba", prop->length))
ian@0 1215 goto next_pci;
ian@0 1216
ian@0 1217 simbas_found++;
ian@0 1218
ian@0 1219 prop = of_find_property(node, "bus-range", NULL);
ian@0 1220 busrange = prop->value;
ian@0 1221 if (busrange[0] == 1)
ian@0 1222 pbm = &p->pbm_B;
ian@0 1223 else
ian@0 1224 pbm = &p->pbm_A;
ian@0 1225
ian@0 1226 pbm->name = node->full_name;
ian@0 1227 printk("%s: SABRE PCI Bus Module\n", pbm->name);
ian@0 1228
ian@0 1229 pbm->chip_type = PBM_CHIP_TYPE_SABRE;
ian@0 1230 pbm->parent = p;
ian@0 1231 pbm->prom_node = node;
ian@0 1232 pbm->pci_first_slot = 1;
ian@0 1233 pbm->pci_first_busno = busrange[0];
ian@0 1234 pbm->pci_last_busno = busrange[1];
ian@0 1235
ian@0 1236 prop = of_find_property(node, "ranges", &len);
ian@0 1237 if (prop) {
ian@0 1238 pbm->pbm_ranges = prop->value;
ian@0 1239 pbm->num_pbm_ranges =
ian@0 1240 (len / sizeof(struct linux_prom_pci_ranges));
ian@0 1241 } else {
ian@0 1242 pbm->num_pbm_ranges = 0;
ian@0 1243 }
ian@0 1244
ian@0 1245 prop = of_find_property(node, "interrupt-map", &len);
ian@0 1246 if (prop) {
ian@0 1247 pbm->pbm_intmap = prop->value;
ian@0 1248 pbm->num_pbm_intmap =
ian@0 1249 (len / sizeof(struct linux_prom_pci_intmap));
ian@0 1250
ian@0 1251 prop = of_find_property(node, "interrupt-map-mask",
ian@0 1252 NULL);
ian@0 1253 pbm->pbm_intmask = prop->value;
ian@0 1254 } else {
ian@0 1255 pbm->num_pbm_intmap = 0;
ian@0 1256 }
ian@0 1257
ian@0 1258 pbm_register_toplevel_resources(p, pbm);
ian@0 1259
ian@0 1260 next_pci:
ian@0 1261 node = node->sibling;
ian@0 1262 }
ian@0 1263 if (simbas_found == 0) {
ian@240 1264 struct resource *rp;
ian@240 1265
ian@0 1266 /* No APBs underneath, probably this is a hummingbird
ian@0 1267 * system.
ian@0 1268 */
ian@0 1269 pbm = &p->pbm_A;
ian@0 1270 pbm->parent = p;
ian@0 1271 pbm->prom_node = dp;
ian@0 1272 pbm->pci_first_busno = p->pci_first_busno;
ian@0 1273 pbm->pci_last_busno = p->pci_last_busno;
ian@0 1274
ian@0 1275 prop = of_find_property(dp, "ranges", &len);
ian@0 1276 if (prop) {
ian@0 1277 pbm->pbm_ranges = prop->value;
ian@0 1278 pbm->num_pbm_ranges =
ian@0 1279 (len / sizeof(struct linux_prom_pci_ranges));
ian@0 1280 } else {
ian@0 1281 pbm->num_pbm_ranges = 0;
ian@0 1282 }
ian@0 1283
ian@0 1284 prop = of_find_property(dp, "interrupt-map", &len);
ian@0 1285 if (prop) {
ian@0 1286 pbm->pbm_intmap = prop->value;
ian@0 1287 pbm->num_pbm_intmap =
ian@0 1288 (len / sizeof(struct linux_prom_pci_intmap));
ian@0 1289
ian@0 1290 prop = of_find_property(dp, "interrupt-map-mask",
ian@0 1291 NULL);
ian@0 1292 pbm->pbm_intmask = prop->value;
ian@0 1293 } else {
ian@0 1294 pbm->num_pbm_intmap = 0;
ian@0 1295 }
ian@0 1296
ian@0 1297 pbm->name = dp->full_name;
ian@0 1298 printk("%s: SABRE PCI Bus Module\n", pbm->name);
ian@0 1299
ian@0 1300 pbm->io_space.name = pbm->mem_space.name = pbm->name;
ian@0 1301
ian@0 1302 /* Hack up top-level resources. */
ian@0 1303 pbm->io_space.start = p->pbm_A.controller_regs + SABRE_IOSPACE;
ian@0 1304 pbm->io_space.end = pbm->io_space.start + (1UL << 24) - 1UL;
ian@0 1305 pbm->io_space.flags = IORESOURCE_IO;
ian@0 1306
ian@240 1307 pbm->mem_space.start =
ian@240 1308 (p->pbm_A.controller_regs + SABRE_MEMSPACE);
ian@240 1309 pbm->mem_space.end =
ian@240 1310 (pbm->mem_space.start + ((1UL << 32UL) - 1UL));
ian@0 1311 pbm->mem_space.flags = IORESOURCE_MEM;
ian@0 1312
ian@0 1313 if (request_resource(&ioport_resource, &pbm->io_space) < 0) {
ian@0 1314 prom_printf("Cannot register Hummingbird's IO space.\n");
ian@0 1315 prom_halt();
ian@0 1316 }
ian@0 1317 if (request_resource(&iomem_resource, &pbm->mem_space) < 0) {
ian@0 1318 prom_printf("Cannot register Hummingbird's MEM space.\n");
ian@0 1319 prom_halt();
ian@0 1320 }
ian@0 1321
ian@240 1322 rp = kmalloc(sizeof(*rp), GFP_KERNEL);
ian@240 1323 if (!rp) {
ian@240 1324 prom_printf("Cannot allocate IOMMU resource.\n");
ian@240 1325 prom_halt();
ian@240 1326 }
ian@240 1327 rp->name = "IOMMU";
ian@240 1328 rp->start = pbm->mem_space.start + (unsigned long) dma_start;
ian@240 1329 rp->end = pbm->mem_space.start + (unsigned long) dma_end - 1UL;
ian@240 1330 rp->flags = IORESOURCE_BUSY;
ian@240 1331 request_resource(&pbm->mem_space, rp);
ian@240 1332
ian@0 1333 pci_register_legacy_regions(&pbm->io_space,
ian@0 1334 &pbm->mem_space);
ian@0 1335 }
ian@0 1336 }
ian@0 1337
ian@0 1338 void sabre_init(struct device_node *dp, char *model_name)
ian@0 1339 {
ian@0 1340 struct linux_prom64_registers *pr_regs;
ian@0 1341 struct pci_controller_info *p;
ian@0 1342 struct pci_iommu *iommu;
ian@0 1343 struct property *prop;
ian@0 1344 int tsbsize;
ian@0 1345 u32 *busrange;
ian@0 1346 u32 *vdma;
ian@0 1347 u32 upa_portid, dma_mask;
ian@0 1348 u64 clear_irq;
ian@0 1349
ian@0 1350 hummingbird_p = 0;
ian@0 1351 if (!strcmp(model_name, "pci108e,a001"))
ian@0 1352 hummingbird_p = 1;
ian@0 1353 else if (!strcmp(model_name, "SUNW,sabre")) {
ian@0 1354 prop = of_find_property(dp, "compatible", NULL);
ian@0 1355 if (prop) {
ian@0 1356 const char *compat = prop->value;
ian@0 1357
ian@0 1358 if (!strcmp(compat, "pci108e,a001"))
ian@0 1359 hummingbird_p = 1;
ian@0 1360 }
ian@0 1361 if (!hummingbird_p) {
ian@0 1362 struct device_node *dp;
ian@0 1363
ian@0 1364 /* Of course, Sun has to encode things a thousand
ian@0 1365 * different ways, inconsistently.
ian@0 1366 */
ian@0 1367 cpu_find_by_instance(0, &dp, NULL);
ian@0 1368 if (!strcmp(dp->name, "SUNW,UltraSPARC-IIe"))
ian@0 1369 hummingbird_p = 1;
ian@0 1370 }
ian@0 1371 }
ian@0 1372
ian@0 1373 p = kzalloc(sizeof(*p), GFP_ATOMIC);
ian@0 1374 if (!p) {
ian@0 1375 prom_printf("SABRE: Error, kmalloc(pci_controller_info) failed.\n");
ian@0 1376 prom_halt();
ian@0 1377 }
ian@0 1378
ian@0 1379 iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
ian@0 1380 if (!iommu) {
ian@0 1381 prom_printf("SABRE: Error, kmalloc(pci_iommu) failed.\n");
ian@0 1382 prom_halt();
ian@0 1383 }
ian@0 1384 p->pbm_A.iommu = p->pbm_B.iommu = iommu;
ian@0 1385
ian@0 1386 upa_portid = 0xff;
ian@0 1387 prop = of_find_property(dp, "upa-portid", NULL);
ian@0 1388 if (prop)
ian@0 1389 upa_portid = *(u32 *) prop->value;
ian@0 1390
ian@0 1391 p->next = pci_controller_root;
ian@0 1392 pci_controller_root = p;
ian@0 1393
ian@0 1394 p->pbm_A.portid = upa_portid;
ian@0 1395 p->pbm_B.portid = upa_portid;
ian@0 1396 p->index = pci_num_controllers++;
ian@0 1397 p->pbms_same_domain = 1;
ian@0 1398 p->scan_bus = sabre_scan_bus;
ian@0 1399 p->base_address_update = sabre_base_address_update;
ian@0 1400 p->resource_adjust = sabre_resource_adjust;
ian@0 1401 p->pci_ops = &sabre_ops;
ian@0 1402
ian@0 1403 /*
ian@0 1404 * Map in SABRE register set and report the presence of this SABRE.
ian@0 1405 */
ian@0 1406
ian@0 1407 prop = of_find_property(dp, "reg", NULL);
ian@0 1408 pr_regs = prop->value;
ian@0 1409
ian@0 1410 /*
ian@0 1411 * First REG in property is base of entire SABRE register space.
ian@0 1412 */
ian@0 1413 p->pbm_A.controller_regs = pr_regs[0].phys_addr;
ian@0 1414 p->pbm_B.controller_regs = pr_regs[0].phys_addr;
ian@0 1415
ian@0 1416 /* Clear interrupts */
ian@0 1417
ian@0 1418 /* PCI first */
ian@0 1419 for (clear_irq = SABRE_ICLR_A_SLOT0; clear_irq < SABRE_ICLR_B_SLOT0 + 0x80; clear_irq += 8)
ian@0 1420 sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
ian@0 1421
ian@0 1422 /* Then OBIO */
ian@0 1423 for (clear_irq = SABRE_ICLR_SCSI; clear_irq < SABRE_ICLR_SCSI + 0x80; clear_irq += 8)
ian@0 1424 sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
ian@0 1425
ian@0 1426 /* Error interrupts are enabled later after the bus scan. */
ian@0 1427 sabre_write(p->pbm_A.controller_regs + SABRE_PCICTRL,
ian@0 1428 (SABRE_PCICTRL_MRLEN | SABRE_PCICTRL_SERR |
ian@0 1429 SABRE_PCICTRL_ARBPARK | SABRE_PCICTRL_AEN));
ian@0 1430
ian@0 1431 /* Now map in PCI config space for entire SABRE. */
ian@0 1432 p->pbm_A.config_space = p->pbm_B.config_space =
ian@0 1433 (p->pbm_A.controller_regs + SABRE_CONFIGSPACE);
ian@0 1434
ian@0 1435 prop = of_find_property(dp, "virtual-dma", NULL);
ian@0 1436 vdma = prop->value;
ian@0 1437
ian@0 1438 dma_mask = vdma[0];
ian@0 1439 switch(vdma[1]) {
ian@0 1440 case 0x20000000:
ian@0 1441 dma_mask |= 0x1fffffff;
ian@0 1442 tsbsize = 64;
ian@0 1443 break;
ian@0 1444 case 0x40000000:
ian@0 1445 dma_mask |= 0x3fffffff;
ian@0 1446 tsbsize = 128;
ian@0 1447 break;
ian@0 1448
ian@0 1449 case 0x80000000:
ian@0 1450 dma_mask |= 0x7fffffff;
ian@0 1451 tsbsize = 128;
ian@0 1452 break;
ian@0 1453 default:
ian@0 1454 prom_printf("SABRE: strange virtual-dma size.\n");
ian@0 1455 prom_halt();
ian@0 1456 }
ian@0 1457
ian@0 1458 sabre_iommu_init(p, tsbsize, vdma[0], dma_mask);
ian@0 1459
ian@0 1460 prop = of_find_property(dp, "bus-range", NULL);
ian@0 1461 busrange = prop->value;
ian@0 1462 p->pci_first_busno = busrange[0];
ian@0 1463 p->pci_last_busno = busrange[1];
ian@0 1464
ian@0 1465 /*
ian@0 1466 * Look for APB underneath.
ian@0 1467 */
ian@240 1468 sabre_pbm_init(p, dp, vdma[0], vdma[0] + vdma[1]);
ian@0 1469 }