Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Derived from arch/powerpc/kernel/iommu.c |
| 3 | * |
Muli Ben-Yehuda | 9882234 | 2007-07-21 17:10:48 +0200 | [diff] [blame] | 4 | * Copyright IBM Corporation, 2006-2007 |
Jon Mason | d8d2bed | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 5 | * Copyright (C) 2006 Jon Mason <jdmason@kudzu.us> |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 6 | * |
Jon Mason | d8d2bed | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 7 | * Author: Jon Mason <jdmason@kudzu.us> |
Muli Ben-Yehuda | aa0a9f3 | 2006-07-10 17:06:15 +0200 | [diff] [blame] | 8 | * Author: Muli Ben-Yehuda <muli@il.ibm.com> |
| 9 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/mm.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/dma-mapping.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/bitops.h> |
| 35 | #include <linux/pci_ids.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <asm/proto.h> |
| 39 | #include <asm/calgary.h> |
| 40 | #include <asm/tce.h> |
| 41 | #include <asm/pci-direct.h> |
| 42 | #include <asm/system.h> |
| 43 | #include <asm/dma.h> |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 44 | #include <asm/rio.h> |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 45 | |
Muli Ben-Yehuda | bff6547 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 46 | #ifdef CONFIG_CALGARY_IOMMU_ENABLED_BY_DEFAULT |
| 47 | int use_calgary __read_mostly = 1; |
| 48 | #else |
| 49 | int use_calgary __read_mostly = 0; |
| 50 | #endif /* CONFIG_CALGARY_DEFAULT_ENABLED */ |
| 51 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 52 | #define PCI_DEVICE_ID_IBM_CALGARY 0x02a1 |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 53 | #define PCI_DEVICE_ID_IBM_CALIOC2 0x0308 |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 54 | |
| 55 | /* we need these for register space address calculation */ |
| 56 | #define START_ADDRESS 0xfe000000 |
| 57 | #define CHASSIS_BASE 0 |
| 58 | #define ONE_BASED_CHASSIS_NUM 1 |
| 59 | |
| 60 | /* register offsets inside the host bridge space */ |
Muli Ben-Yehuda | cb01fc7 | 2006-10-22 00:41:15 +0200 | [diff] [blame] | 61 | #define CALGARY_CONFIG_REG 0x0108 |
| 62 | #define PHB_CSR_OFFSET 0x0110 /* Channel Status */ |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 63 | #define PHB_PLSSR_OFFSET 0x0120 |
| 64 | #define PHB_CONFIG_RW_OFFSET 0x0160 |
| 65 | #define PHB_IOBASE_BAR_LOW 0x0170 |
| 66 | #define PHB_IOBASE_BAR_HIGH 0x0180 |
| 67 | #define PHB_MEM_1_LOW 0x0190 |
| 68 | #define PHB_MEM_1_HIGH 0x01A0 |
| 69 | #define PHB_IO_ADDR_SIZE 0x01B0 |
| 70 | #define PHB_MEM_1_SIZE 0x01C0 |
| 71 | #define PHB_MEM_ST_OFFSET 0x01D0 |
| 72 | #define PHB_AER_OFFSET 0x0200 |
| 73 | #define PHB_CONFIG_0_HIGH 0x0220 |
| 74 | #define PHB_CONFIG_0_LOW 0x0230 |
| 75 | #define PHB_CONFIG_0_END 0x0240 |
| 76 | #define PHB_MEM_2_LOW 0x02B0 |
| 77 | #define PHB_MEM_2_HIGH 0x02C0 |
| 78 | #define PHB_MEM_2_SIZE_HIGH 0x02D0 |
| 79 | #define PHB_MEM_2_SIZE_LOW 0x02E0 |
| 80 | #define PHB_DOSHOLE_OFFSET 0x08E0 |
| 81 | |
Muli Ben-Yehuda | c386010 | 2007-07-21 17:10:53 +0200 | [diff] [blame] | 82 | /* CalIOC2 specific */ |
| 83 | #define PHB_SAVIOR_L2 0x0DB0 |
Muli Ben-Yehuda | 00be3fa | 2007-07-21 17:10:54 +0200 | [diff] [blame^] | 84 | #define PHB_PAGE_MIG_CTRL 0x0DA8 |
| 85 | #define PHB_PAGE_MIG_DEBUG 0x0DA0 |
Muli Ben-Yehuda | c386010 | 2007-07-21 17:10:53 +0200 | [diff] [blame] | 86 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 87 | /* PHB_CONFIG_RW */ |
| 88 | #define PHB_TCE_ENABLE 0x20000000 |
| 89 | #define PHB_SLOT_DISABLE 0x1C000000 |
| 90 | #define PHB_DAC_DISABLE 0x01000000 |
| 91 | #define PHB_MEM2_ENABLE 0x00400000 |
| 92 | #define PHB_MCSR_ENABLE 0x00100000 |
| 93 | /* TAR (Table Address Register) */ |
| 94 | #define TAR_SW_BITS 0x0000ffffffff800fUL |
| 95 | #define TAR_VALID 0x0000000000000008UL |
| 96 | /* CSR (Channel/DMA Status Register) */ |
| 97 | #define CSR_AGENT_MASK 0xffe0ffff |
Muli Ben-Yehuda | cb01fc7 | 2006-10-22 00:41:15 +0200 | [diff] [blame] | 98 | /* CCR (Calgary Configuration Register) */ |
| 99 | #define CCR_2SEC_TIMEOUT 0x000000000000000EUL |
Muli Ben-Yehuda | 00be3fa | 2007-07-21 17:10:54 +0200 | [diff] [blame^] | 100 | /* PMCR/PMDR (Page Migration Control/Debug Registers */ |
| 101 | #define PMR_SOFTSTOP 0x80000000 |
| 102 | #define PMR_SOFTSTOPFAULT 0x40000000 |
| 103 | #define PMR_HARDSTOP 0x20000000 |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 104 | |
| 105 | #define MAX_NUM_OF_PHBS 8 /* how many PHBs in total? */ |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 106 | #define MAX_NUM_CHASSIS 8 /* max number of chassis */ |
Muli Ben-Yehuda | 4ea8a5d | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 107 | /* MAX_PHB_BUS_NUM is the maximal possible dev->bus->number */ |
| 108 | #define MAX_PHB_BUS_NUM (MAX_NUM_OF_PHBS * MAX_NUM_CHASSIS * 2) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 109 | #define PHBS_PER_CALGARY 4 |
| 110 | |
| 111 | /* register offsets in Calgary's internal register space */ |
| 112 | static const unsigned long tar_offsets[] = { |
| 113 | 0x0580 /* TAR0 */, |
| 114 | 0x0588 /* TAR1 */, |
| 115 | 0x0590 /* TAR2 */, |
| 116 | 0x0598 /* TAR3 */ |
| 117 | }; |
| 118 | |
| 119 | static const unsigned long split_queue_offsets[] = { |
| 120 | 0x4870 /* SPLIT QUEUE 0 */, |
| 121 | 0x5870 /* SPLIT QUEUE 1 */, |
| 122 | 0x6870 /* SPLIT QUEUE 2 */, |
| 123 | 0x7870 /* SPLIT QUEUE 3 */ |
| 124 | }; |
| 125 | |
| 126 | static const unsigned long phb_offsets[] = { |
| 127 | 0x8000 /* PHB0 */, |
| 128 | 0x9000 /* PHB1 */, |
| 129 | 0xA000 /* PHB2 */, |
| 130 | 0xB000 /* PHB3 */ |
| 131 | }; |
| 132 | |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 133 | /* PHB debug registers */ |
| 134 | |
| 135 | static const unsigned long phb_debug_offsets[] = { |
| 136 | 0x4000 /* PHB 0 DEBUG */, |
| 137 | 0x5000 /* PHB 1 DEBUG */, |
| 138 | 0x6000 /* PHB 2 DEBUG */, |
| 139 | 0x7000 /* PHB 3 DEBUG */ |
| 140 | }; |
| 141 | |
| 142 | /* |
| 143 | * STUFF register for each debug PHB, |
| 144 | * byte 1 = start bus number, byte 2 = end bus number |
| 145 | */ |
| 146 | |
| 147 | #define PHB_DEBUG_STUFF_OFFSET 0x0020 |
| 148 | |
Muli Ben-Yehuda | 310adfd | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 149 | #define EMERGENCY_PAGES 32 /* = 128KB */ |
| 150 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 151 | unsigned int specified_table_size = TCE_TABLE_SIZE_UNSPECIFIED; |
| 152 | static int translate_empty_slots __read_mostly = 0; |
| 153 | static int calgary_detected __read_mostly = 0; |
| 154 | |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 155 | static struct rio_table_hdr *rio_table_hdr __initdata; |
| 156 | static struct scal_detail *scal_devs[MAX_NUMNODES] __initdata; |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 157 | static struct rio_detail *rio_devs[MAX_NUMNODES * 4] __initdata; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 158 | |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 159 | struct calgary_bus_info { |
| 160 | void *tce_space; |
Muli Ben-Yehuda | 0577f14 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 161 | unsigned char translation_disabled; |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 162 | signed char phbid; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 163 | void __iomem *bbar; |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 164 | }; |
| 165 | |
Muli Ben-Yehuda | ff297b8 | 2007-07-21 17:10:50 +0200 | [diff] [blame] | 166 | static void calgary_handle_quirks(struct iommu_table *tbl, struct pci_dev *dev); |
| 167 | static void calgary_tce_cache_blast(struct iommu_table *tbl); |
Muli Ben-Yehuda | c386010 | 2007-07-21 17:10:53 +0200 | [diff] [blame] | 168 | static void calioc2_handle_quirks(struct iommu_table *tbl, struct pci_dev *dev); |
Muli Ben-Yehuda | 00be3fa | 2007-07-21 17:10:54 +0200 | [diff] [blame^] | 169 | static void calioc2_tce_cache_blast(struct iommu_table *tbl); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 170 | |
Muli Ben-Yehuda | ff297b8 | 2007-07-21 17:10:50 +0200 | [diff] [blame] | 171 | static struct cal_chipset_ops calgary_chip_ops = { |
| 172 | .handle_quirks = calgary_handle_quirks, |
| 173 | .tce_cache_blast = calgary_tce_cache_blast |
| 174 | }; |
| 175 | |
Muli Ben-Yehuda | c386010 | 2007-07-21 17:10:53 +0200 | [diff] [blame] | 176 | static struct cal_chipset_ops calioc2_chip_ops = { |
| 177 | .handle_quirks = calioc2_handle_quirks, |
Muli Ben-Yehuda | 00be3fa | 2007-07-21 17:10:54 +0200 | [diff] [blame^] | 178 | .tce_cache_blast = calioc2_tce_cache_blast |
Muli Ben-Yehuda | c386010 | 2007-07-21 17:10:53 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Muli Ben-Yehuda | ff297b8 | 2007-07-21 17:10:50 +0200 | [diff] [blame] | 181 | static struct calgary_bus_info bus_info[MAX_PHB_BUS_NUM] = { { NULL, 0, 0 }, }; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 182 | |
| 183 | /* enable this to stress test the chip's TCE cache */ |
| 184 | #ifdef CONFIG_IOMMU_DEBUG |
Muli Ben-Yehuda | de68465 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 185 | int debugging __read_mostly = 1; |
| 186 | |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 187 | static inline unsigned long verify_bit_range(unsigned long* bitmap, |
| 188 | int expected, unsigned long start, unsigned long end) |
| 189 | { |
| 190 | unsigned long idx = start; |
| 191 | |
| 192 | BUG_ON(start >= end); |
| 193 | |
| 194 | while (idx < end) { |
| 195 | if (!!test_bit(idx, bitmap) != expected) |
| 196 | return idx; |
| 197 | ++idx; |
| 198 | } |
| 199 | |
| 200 | /* all bits have the expected value */ |
| 201 | return ~0UL; |
| 202 | } |
Muli Ben-Yehuda | de68465 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 203 | #else /* debugging is disabled */ |
| 204 | int debugging __read_mostly = 0; |
| 205 | |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 206 | static inline unsigned long verify_bit_range(unsigned long* bitmap, |
| 207 | int expected, unsigned long start, unsigned long end) |
| 208 | { |
| 209 | return ~0UL; |
| 210 | } |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 211 | |
Muli Ben-Yehuda | de68465 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 212 | #endif /* CONFIG_IOMMU_DEBUG */ |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 213 | |
| 214 | static inline unsigned int num_dma_pages(unsigned long dma, unsigned int dmalen) |
| 215 | { |
| 216 | unsigned int npages; |
| 217 | |
| 218 | npages = PAGE_ALIGN(dma + dmalen) - (dma & PAGE_MASK); |
| 219 | npages >>= PAGE_SHIFT; |
| 220 | |
| 221 | return npages; |
| 222 | } |
| 223 | |
| 224 | static inline int translate_phb(struct pci_dev* dev) |
| 225 | { |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 226 | int disabled = bus_info[dev->bus->number].translation_disabled; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 227 | return !disabled; |
| 228 | } |
| 229 | |
| 230 | static void iommu_range_reserve(struct iommu_table *tbl, |
| 231 | unsigned long start_addr, unsigned int npages) |
| 232 | { |
| 233 | unsigned long index; |
| 234 | unsigned long end; |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 235 | unsigned long badbit; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 236 | |
| 237 | index = start_addr >> PAGE_SHIFT; |
| 238 | |
| 239 | /* bail out if we're asked to reserve a region we don't cover */ |
| 240 | if (index >= tbl->it_size) |
| 241 | return; |
| 242 | |
| 243 | end = index + npages; |
| 244 | if (end > tbl->it_size) /* don't go off the table */ |
| 245 | end = tbl->it_size; |
| 246 | |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 247 | badbit = verify_bit_range(tbl->it_map, 0, index, end); |
| 248 | if (badbit != ~0UL) { |
| 249 | if (printk_ratelimit()) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 250 | printk(KERN_ERR "Calgary: entry already allocated at " |
| 251 | "0x%lx tbl %p dma 0x%lx npages %u\n", |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 252 | badbit, tbl, start_addr, npages); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 253 | } |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 254 | |
| 255 | set_bit_string(tbl->it_map, index, npages); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static unsigned long iommu_range_alloc(struct iommu_table *tbl, |
| 259 | unsigned int npages) |
| 260 | { |
| 261 | unsigned long offset; |
| 262 | |
| 263 | BUG_ON(npages == 0); |
| 264 | |
| 265 | offset = find_next_zero_string(tbl->it_map, tbl->it_hint, |
| 266 | tbl->it_size, npages); |
| 267 | if (offset == ~0UL) { |
Muli Ben-Yehuda | ff297b8 | 2007-07-21 17:10:50 +0200 | [diff] [blame] | 268 | tbl->chip_ops->tce_cache_blast(tbl); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 269 | offset = find_next_zero_string(tbl->it_map, 0, |
| 270 | tbl->it_size, npages); |
| 271 | if (offset == ~0UL) { |
| 272 | printk(KERN_WARNING "Calgary: IOMMU full.\n"); |
| 273 | if (panic_on_overflow) |
| 274 | panic("Calgary: fix the allocator.\n"); |
| 275 | else |
| 276 | return bad_dma_address; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | set_bit_string(tbl->it_map, offset, npages); |
| 281 | tbl->it_hint = offset + npages; |
| 282 | BUG_ON(tbl->it_hint > tbl->it_size); |
| 283 | |
| 284 | return offset; |
| 285 | } |
| 286 | |
| 287 | static dma_addr_t iommu_alloc(struct iommu_table *tbl, void *vaddr, |
| 288 | unsigned int npages, int direction) |
| 289 | { |
| 290 | unsigned long entry, flags; |
| 291 | dma_addr_t ret = bad_dma_address; |
| 292 | |
| 293 | spin_lock_irqsave(&tbl->it_lock, flags); |
| 294 | |
| 295 | entry = iommu_range_alloc(tbl, npages); |
| 296 | |
| 297 | if (unlikely(entry == bad_dma_address)) |
| 298 | goto error; |
| 299 | |
| 300 | /* set the return dma address */ |
| 301 | ret = (entry << PAGE_SHIFT) | ((unsigned long)vaddr & ~PAGE_MASK); |
| 302 | |
| 303 | /* put the TCEs in the HW table */ |
| 304 | tce_build(tbl, entry, npages, (unsigned long)vaddr & PAGE_MASK, |
| 305 | direction); |
| 306 | |
| 307 | spin_unlock_irqrestore(&tbl->it_lock, flags); |
| 308 | |
| 309 | return ret; |
| 310 | |
| 311 | error: |
| 312 | spin_unlock_irqrestore(&tbl->it_lock, flags); |
| 313 | printk(KERN_WARNING "Calgary: failed to allocate %u pages in " |
| 314 | "iommu %p\n", npages, tbl); |
| 315 | return bad_dma_address; |
| 316 | } |
| 317 | |
| 318 | static void __iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr, |
| 319 | unsigned int npages) |
| 320 | { |
| 321 | unsigned long entry; |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 322 | unsigned long badbit; |
Muli Ben-Yehuda | 310adfd | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 323 | unsigned long badend; |
| 324 | |
| 325 | /* were we called with bad_dma_address? */ |
| 326 | badend = bad_dma_address + (EMERGENCY_PAGES * PAGE_SIZE); |
| 327 | if (unlikely((dma_addr >= bad_dma_address) && (dma_addr < badend))) { |
| 328 | printk(KERN_ERR "Calgary: driver tried unmapping bad DMA " |
| 329 | "address 0x%Lx\n", dma_addr); |
| 330 | WARN_ON(1); |
| 331 | return; |
| 332 | } |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 333 | |
| 334 | entry = dma_addr >> PAGE_SHIFT; |
| 335 | |
| 336 | BUG_ON(entry + npages > tbl->it_size); |
| 337 | |
| 338 | tce_free(tbl, entry, npages); |
| 339 | |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 340 | badbit = verify_bit_range(tbl->it_map, 1, entry, entry + npages); |
| 341 | if (badbit != ~0UL) { |
| 342 | if (printk_ratelimit()) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 343 | printk(KERN_ERR "Calgary: bit is off at 0x%lx " |
| 344 | "tbl %p dma 0x%Lx entry 0x%lx npages %u\n", |
Muli Ben-Yehuda | 796e439 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 345 | badbit, tbl, dma_addr, entry, npages); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | __clear_bit_string(tbl->it_map, entry, npages); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr, |
| 352 | unsigned int npages) |
| 353 | { |
| 354 | unsigned long flags; |
| 355 | |
| 356 | spin_lock_irqsave(&tbl->it_lock, flags); |
| 357 | |
| 358 | __iommu_free(tbl, dma_addr, npages); |
| 359 | |
| 360 | spin_unlock_irqrestore(&tbl->it_lock, flags); |
| 361 | } |
| 362 | |
Muli Ben-Yehuda | 35b6dfa | 2007-07-21 17:10:51 +0200 | [diff] [blame] | 363 | static inline struct iommu_table *find_iommu_table(struct device *dev) |
| 364 | { |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 365 | struct pci_dev *pdev; |
| 366 | struct pci_bus *pbus; |
Muli Ben-Yehuda | 35b6dfa | 2007-07-21 17:10:51 +0200 | [diff] [blame] | 367 | struct iommu_table *tbl; |
| 368 | |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 369 | pdev = to_pci_dev(dev); |
| 370 | |
| 371 | /* is the device behind a bridge? */ |
| 372 | if (unlikely(pdev->bus->parent)) |
| 373 | pbus = pdev->bus->parent; |
| 374 | else |
| 375 | pbus = pdev->bus; |
| 376 | |
| 377 | tbl = pbus->self->sysdata; |
| 378 | BUG_ON(pdev->bus->parent && (tbl->it_busno != pdev->bus->parent->number)); |
Muli Ben-Yehuda | 35b6dfa | 2007-07-21 17:10:51 +0200 | [diff] [blame] | 379 | |
| 380 | return tbl; |
| 381 | } |
| 382 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 383 | static void __calgary_unmap_sg(struct iommu_table *tbl, |
| 384 | struct scatterlist *sglist, int nelems, int direction) |
| 385 | { |
| 386 | while (nelems--) { |
| 387 | unsigned int npages; |
| 388 | dma_addr_t dma = sglist->dma_address; |
| 389 | unsigned int dmalen = sglist->dma_length; |
| 390 | |
| 391 | if (dmalen == 0) |
| 392 | break; |
| 393 | |
| 394 | npages = num_dma_pages(dma, dmalen); |
| 395 | __iommu_free(tbl, dma, npages); |
| 396 | sglist++; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | void calgary_unmap_sg(struct device *dev, struct scatterlist *sglist, |
| 401 | int nelems, int direction) |
| 402 | { |
| 403 | unsigned long flags; |
Muli Ben-Yehuda | 35b6dfa | 2007-07-21 17:10:51 +0200 | [diff] [blame] | 404 | struct iommu_table *tbl = find_iommu_table(dev); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 405 | |
| 406 | if (!translate_phb(to_pci_dev(dev))) |
| 407 | return; |
| 408 | |
| 409 | spin_lock_irqsave(&tbl->it_lock, flags); |
| 410 | |
| 411 | __calgary_unmap_sg(tbl, sglist, nelems, direction); |
| 412 | |
| 413 | spin_unlock_irqrestore(&tbl->it_lock, flags); |
| 414 | } |
| 415 | |
| 416 | static int calgary_nontranslate_map_sg(struct device* dev, |
| 417 | struct scatterlist *sg, int nelems, int direction) |
| 418 | { |
| 419 | int i; |
| 420 | |
| 421 | for (i = 0; i < nelems; i++ ) { |
| 422 | struct scatterlist *s = &sg[i]; |
| 423 | BUG_ON(!s->page); |
| 424 | s->dma_address = virt_to_bus(page_address(s->page) +s->offset); |
| 425 | s->dma_length = s->length; |
| 426 | } |
| 427 | return nelems; |
| 428 | } |
| 429 | |
| 430 | int calgary_map_sg(struct device *dev, struct scatterlist *sg, |
| 431 | int nelems, int direction) |
| 432 | { |
Muli Ben-Yehuda | 35b6dfa | 2007-07-21 17:10:51 +0200 | [diff] [blame] | 433 | struct iommu_table *tbl = find_iommu_table(dev); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 434 | unsigned long flags; |
| 435 | unsigned long vaddr; |
| 436 | unsigned int npages; |
| 437 | unsigned long entry; |
| 438 | int i; |
| 439 | |
| 440 | if (!translate_phb(to_pci_dev(dev))) |
| 441 | return calgary_nontranslate_map_sg(dev, sg, nelems, direction); |
| 442 | |
| 443 | spin_lock_irqsave(&tbl->it_lock, flags); |
| 444 | |
| 445 | for (i = 0; i < nelems; i++ ) { |
| 446 | struct scatterlist *s = &sg[i]; |
| 447 | BUG_ON(!s->page); |
| 448 | |
| 449 | vaddr = (unsigned long)page_address(s->page) + s->offset; |
| 450 | npages = num_dma_pages(vaddr, s->length); |
| 451 | |
| 452 | entry = iommu_range_alloc(tbl, npages); |
| 453 | if (entry == bad_dma_address) { |
| 454 | /* makes sure unmap knows to stop */ |
| 455 | s->dma_length = 0; |
| 456 | goto error; |
| 457 | } |
| 458 | |
| 459 | s->dma_address = (entry << PAGE_SHIFT) | s->offset; |
| 460 | |
| 461 | /* insert into HW table */ |
| 462 | tce_build(tbl, entry, npages, vaddr & PAGE_MASK, |
| 463 | direction); |
| 464 | |
| 465 | s->dma_length = s->length; |
| 466 | } |
| 467 | |
| 468 | spin_unlock_irqrestore(&tbl->it_lock, flags); |
| 469 | |
| 470 | return nelems; |
| 471 | error: |
| 472 | __calgary_unmap_sg(tbl, sg, nelems, direction); |
| 473 | for (i = 0; i < nelems; i++) { |
| 474 | sg[i].dma_address = bad_dma_address; |
| 475 | sg[i].dma_length = 0; |
| 476 | } |
| 477 | spin_unlock_irqrestore(&tbl->it_lock, flags); |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | dma_addr_t calgary_map_single(struct device *dev, void *vaddr, |
| 482 | size_t size, int direction) |
| 483 | { |
| 484 | dma_addr_t dma_handle = bad_dma_address; |
| 485 | unsigned long uaddr; |
| 486 | unsigned int npages; |
Muli Ben-Yehuda | 35b6dfa | 2007-07-21 17:10:51 +0200 | [diff] [blame] | 487 | struct iommu_table *tbl = find_iommu_table(dev); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 488 | |
| 489 | uaddr = (unsigned long)vaddr; |
| 490 | npages = num_dma_pages(uaddr, size); |
| 491 | |
| 492 | if (translate_phb(to_pci_dev(dev))) |
| 493 | dma_handle = iommu_alloc(tbl, vaddr, npages, direction); |
| 494 | else |
| 495 | dma_handle = virt_to_bus(vaddr); |
| 496 | |
| 497 | return dma_handle; |
| 498 | } |
| 499 | |
| 500 | void calgary_unmap_single(struct device *dev, dma_addr_t dma_handle, |
| 501 | size_t size, int direction) |
| 502 | { |
Muli Ben-Yehuda | 35b6dfa | 2007-07-21 17:10:51 +0200 | [diff] [blame] | 503 | struct iommu_table *tbl = find_iommu_table(dev); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 504 | unsigned int npages; |
| 505 | |
| 506 | if (!translate_phb(to_pci_dev(dev))) |
| 507 | return; |
| 508 | |
| 509 | npages = num_dma_pages(dma_handle, size); |
| 510 | iommu_free(tbl, dma_handle, npages); |
| 511 | } |
| 512 | |
| 513 | void* calgary_alloc_coherent(struct device *dev, size_t size, |
| 514 | dma_addr_t *dma_handle, gfp_t flag) |
| 515 | { |
| 516 | void *ret = NULL; |
| 517 | dma_addr_t mapping; |
| 518 | unsigned int npages, order; |
Muli Ben-Yehuda | 35b6dfa | 2007-07-21 17:10:51 +0200 | [diff] [blame] | 519 | struct iommu_table *tbl = find_iommu_table(dev); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 520 | |
| 521 | size = PAGE_ALIGN(size); /* size rounded up to full pages */ |
| 522 | npages = size >> PAGE_SHIFT; |
| 523 | order = get_order(size); |
| 524 | |
| 525 | /* alloc enough pages (and possibly more) */ |
| 526 | ret = (void *)__get_free_pages(flag, order); |
| 527 | if (!ret) |
| 528 | goto error; |
| 529 | memset(ret, 0, size); |
| 530 | |
| 531 | if (translate_phb(to_pci_dev(dev))) { |
| 532 | /* set up tces to cover the allocated range */ |
| 533 | mapping = iommu_alloc(tbl, ret, npages, DMA_BIDIRECTIONAL); |
| 534 | if (mapping == bad_dma_address) |
| 535 | goto free; |
| 536 | |
| 537 | *dma_handle = mapping; |
| 538 | } else /* non translated slot */ |
| 539 | *dma_handle = virt_to_bus(ret); |
| 540 | |
| 541 | return ret; |
| 542 | |
| 543 | free: |
| 544 | free_pages((unsigned long)ret, get_order(size)); |
| 545 | ret = NULL; |
| 546 | error: |
| 547 | return ret; |
| 548 | } |
| 549 | |
Stephen Hemminger | e658450 | 2007-05-02 19:27:06 +0200 | [diff] [blame] | 550 | static const struct dma_mapping_ops calgary_dma_ops = { |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 551 | .alloc_coherent = calgary_alloc_coherent, |
| 552 | .map_single = calgary_map_single, |
| 553 | .unmap_single = calgary_unmap_single, |
| 554 | .map_sg = calgary_map_sg, |
| 555 | .unmap_sg = calgary_unmap_sg, |
| 556 | }; |
| 557 | |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 558 | static inline void __iomem * busno_to_bbar(unsigned char num) |
| 559 | { |
| 560 | return bus_info[num].bbar; |
| 561 | } |
| 562 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 563 | static inline int busno_to_phbid(unsigned char num) |
| 564 | { |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 565 | return bus_info[num].phbid; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static inline unsigned long split_queue_offset(unsigned char num) |
| 569 | { |
| 570 | size_t idx = busno_to_phbid(num); |
| 571 | |
| 572 | return split_queue_offsets[idx]; |
| 573 | } |
| 574 | |
| 575 | static inline unsigned long tar_offset(unsigned char num) |
| 576 | { |
| 577 | size_t idx = busno_to_phbid(num); |
| 578 | |
| 579 | return tar_offsets[idx]; |
| 580 | } |
| 581 | |
| 582 | static inline unsigned long phb_offset(unsigned char num) |
| 583 | { |
| 584 | size_t idx = busno_to_phbid(num); |
| 585 | |
| 586 | return phb_offsets[idx]; |
| 587 | } |
| 588 | |
| 589 | static inline void __iomem* calgary_reg(void __iomem *bar, unsigned long offset) |
| 590 | { |
| 591 | unsigned long target = ((unsigned long)bar) | offset; |
| 592 | return (void __iomem*)target; |
| 593 | } |
| 594 | |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 595 | static inline int is_calioc2(unsigned short device) |
| 596 | { |
| 597 | return (device == PCI_DEVICE_ID_IBM_CALIOC2); |
| 598 | } |
| 599 | |
| 600 | static inline int is_calgary(unsigned short device) |
| 601 | { |
| 602 | return (device == PCI_DEVICE_ID_IBM_CALGARY); |
| 603 | } |
| 604 | |
| 605 | static inline int is_cal_pci_dev(unsigned short device) |
| 606 | { |
| 607 | return (is_calgary(device) || is_calioc2(device)); |
| 608 | } |
| 609 | |
Muli Ben-Yehuda | ff297b8 | 2007-07-21 17:10:50 +0200 | [diff] [blame] | 610 | static void calgary_tce_cache_blast(struct iommu_table *tbl) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 611 | { |
| 612 | u64 val; |
| 613 | u32 aer; |
| 614 | int i = 0; |
| 615 | void __iomem *bbar = tbl->bbar; |
| 616 | void __iomem *target; |
| 617 | |
| 618 | /* disable arbitration on the bus */ |
| 619 | target = calgary_reg(bbar, phb_offset(tbl->it_busno) | PHB_AER_OFFSET); |
| 620 | aer = readl(target); |
| 621 | writel(0, target); |
| 622 | |
| 623 | /* read plssr to ensure it got there */ |
| 624 | target = calgary_reg(bbar, phb_offset(tbl->it_busno) | PHB_PLSSR_OFFSET); |
| 625 | val = readl(target); |
| 626 | |
| 627 | /* poll split queues until all DMA activity is done */ |
| 628 | target = calgary_reg(bbar, split_queue_offset(tbl->it_busno)); |
| 629 | do { |
| 630 | val = readq(target); |
| 631 | i++; |
| 632 | } while ((val & 0xff) != 0xff && i < 100); |
| 633 | if (i == 100) |
| 634 | printk(KERN_WARNING "Calgary: PCI bus not quiesced, " |
| 635 | "continuing anyway\n"); |
| 636 | |
| 637 | /* invalidate TCE cache */ |
| 638 | target = calgary_reg(bbar, tar_offset(tbl->it_busno)); |
| 639 | writeq(tbl->tar_val, target); |
| 640 | |
| 641 | /* enable arbitration */ |
| 642 | target = calgary_reg(bbar, phb_offset(tbl->it_busno) | PHB_AER_OFFSET); |
| 643 | writel(aer, target); |
| 644 | (void)readl(target); /* flush */ |
| 645 | } |
| 646 | |
Muli Ben-Yehuda | 00be3fa | 2007-07-21 17:10:54 +0200 | [diff] [blame^] | 647 | static void calioc2_tce_cache_blast(struct iommu_table *tbl) |
| 648 | { |
| 649 | void __iomem *bbar = tbl->bbar; |
| 650 | void __iomem *target; |
| 651 | u64 val64; |
| 652 | u32 val; |
| 653 | int i = 0; |
| 654 | int count = 1; |
| 655 | unsigned char bus = tbl->it_busno; |
| 656 | |
| 657 | begin: |
| 658 | printk(KERN_DEBUG "Calgary: CalIOC2 bus 0x%x entering tce cache blast " |
| 659 | "sequence - count %d\n", bus, count); |
| 660 | |
| 661 | /* 1. using the Page Migration Control reg set SoftStop */ |
| 662 | target = calgary_reg(bbar, phb_offset(bus) | PHB_PAGE_MIG_CTRL); |
| 663 | val = be32_to_cpu(readl(target)); |
| 664 | printk(KERN_DEBUG "1a. read 0x%x [LE] from %p\n", val, target); |
| 665 | val |= PMR_SOFTSTOP; |
| 666 | printk(KERN_DEBUG "1b. writing 0x%x [LE] to %p\n", val, target); |
| 667 | writel(cpu_to_be32(val), target); |
| 668 | |
| 669 | /* 2. poll split queues until all DMA activity is done */ |
| 670 | printk(KERN_DEBUG "2a. starting to poll split queues\n"); |
| 671 | target = calgary_reg(bbar, split_queue_offset(bus)); |
| 672 | do { |
| 673 | val64 = readq(target); |
| 674 | i++; |
| 675 | } while ((val64 & 0xff) != 0xff && i < 100); |
| 676 | if (i == 100) |
| 677 | printk(KERN_WARNING "CalIOC2: PCI bus not quiesced, " |
| 678 | "continuing anyway\n"); |
| 679 | |
| 680 | /* 3. poll Page Migration DEBUG for SoftStopFault */ |
| 681 | target = calgary_reg(bbar, phb_offset(bus) | PHB_PAGE_MIG_DEBUG); |
| 682 | val = be32_to_cpu(readl(target)); |
| 683 | printk(KERN_DEBUG "3. read 0x%x [LE] from %p\n", val, target); |
| 684 | |
| 685 | /* 4. if SoftStopFault - goto (1) */ |
| 686 | if (val & PMR_SOFTSTOPFAULT) { |
| 687 | if (++count < 100) |
| 688 | goto begin; |
| 689 | else { |
| 690 | printk(KERN_WARNING "CalIOC2: too many SoftStopFaults, " |
| 691 | "aborting TCE cache flush sequence!\n"); |
| 692 | return; /* pray for the best */ |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | /* 5. Slam into HardStop by reading PHB_PAGE_MIG_CTRL */ |
| 697 | target = calgary_reg(bbar, phb_offset(bus) | PHB_PAGE_MIG_CTRL); |
| 698 | printk(KERN_DEBUG "5a. slamming into HardStop by reading %p\n", target); |
| 699 | val = be32_to_cpu(readl(target)); |
| 700 | printk(KERN_DEBUG "5b. read 0x%x [LE] from %p\n", val, target); |
| 701 | target = calgary_reg(bbar, phb_offset(bus) | PHB_PAGE_MIG_DEBUG); |
| 702 | val = be32_to_cpu(readl(target)); |
| 703 | printk(KERN_DEBUG "5c. read 0x%x [LE] from %p (debug)\n", val, target); |
| 704 | |
| 705 | /* 6. invalidate TCE cache */ |
| 706 | printk(KERN_DEBUG "6. invalidating TCE cache\n"); |
| 707 | target = calgary_reg(bbar, tar_offset(bus)); |
| 708 | writeq(tbl->tar_val, target); |
| 709 | |
| 710 | /* 7. Re-read PMCR */ |
| 711 | printk(KERN_DEBUG "7a. Re-reading PMCR\n"); |
| 712 | target = calgary_reg(bbar, phb_offset(bus) | PHB_PAGE_MIG_CTRL); |
| 713 | val = be32_to_cpu(readl(target)); |
| 714 | printk(KERN_DEBUG "7b. read 0x%x [LE] from %p\n", val, target); |
| 715 | |
| 716 | /* 8. Remove HardStop */ |
| 717 | printk(KERN_DEBUG "8a. removing HardStop from PMCR\n"); |
| 718 | target = calgary_reg(bbar, phb_offset(bus) | PHB_PAGE_MIG_CTRL); |
| 719 | val = 0; |
| 720 | printk(KERN_DEBUG "8b. writing 0x%x [LE] to %p\n", val, target); |
| 721 | writel(cpu_to_be32(val), target); |
| 722 | val = be32_to_cpu(readl(target)); |
| 723 | printk(KERN_DEBUG "8c. read 0x%x [LE] from %p\n", val, target); |
| 724 | } |
| 725 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 726 | static void __init calgary_reserve_mem_region(struct pci_dev *dev, u64 start, |
| 727 | u64 limit) |
| 728 | { |
| 729 | unsigned int numpages; |
| 730 | |
| 731 | limit = limit | 0xfffff; |
| 732 | limit++; |
| 733 | |
| 734 | numpages = ((limit - start) >> PAGE_SHIFT); |
| 735 | iommu_range_reserve(dev->sysdata, start, numpages); |
| 736 | } |
| 737 | |
| 738 | static void __init calgary_reserve_peripheral_mem_1(struct pci_dev *dev) |
| 739 | { |
| 740 | void __iomem *target; |
| 741 | u64 low, high, sizelow; |
| 742 | u64 start, limit; |
| 743 | struct iommu_table *tbl = dev->sysdata; |
| 744 | unsigned char busnum = dev->bus->number; |
| 745 | void __iomem *bbar = tbl->bbar; |
| 746 | |
| 747 | /* peripheral MEM_1 region */ |
| 748 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_1_LOW); |
| 749 | low = be32_to_cpu(readl(target)); |
| 750 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_1_HIGH); |
| 751 | high = be32_to_cpu(readl(target)); |
| 752 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_1_SIZE); |
| 753 | sizelow = be32_to_cpu(readl(target)); |
| 754 | |
| 755 | start = (high << 32) | low; |
| 756 | limit = sizelow; |
| 757 | |
| 758 | calgary_reserve_mem_region(dev, start, limit); |
| 759 | } |
| 760 | |
| 761 | static void __init calgary_reserve_peripheral_mem_2(struct pci_dev *dev) |
| 762 | { |
| 763 | void __iomem *target; |
| 764 | u32 val32; |
| 765 | u64 low, high, sizelow, sizehigh; |
| 766 | u64 start, limit; |
| 767 | struct iommu_table *tbl = dev->sysdata; |
| 768 | unsigned char busnum = dev->bus->number; |
| 769 | void __iomem *bbar = tbl->bbar; |
| 770 | |
| 771 | /* is it enabled? */ |
| 772 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_CONFIG_RW_OFFSET); |
| 773 | val32 = be32_to_cpu(readl(target)); |
| 774 | if (!(val32 & PHB_MEM2_ENABLE)) |
| 775 | return; |
| 776 | |
| 777 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_2_LOW); |
| 778 | low = be32_to_cpu(readl(target)); |
| 779 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_2_HIGH); |
| 780 | high = be32_to_cpu(readl(target)); |
| 781 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_2_SIZE_LOW); |
| 782 | sizelow = be32_to_cpu(readl(target)); |
| 783 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_MEM_2_SIZE_HIGH); |
| 784 | sizehigh = be32_to_cpu(readl(target)); |
| 785 | |
| 786 | start = (high << 32) | low; |
| 787 | limit = (sizehigh << 32) | sizelow; |
| 788 | |
| 789 | calgary_reserve_mem_region(dev, start, limit); |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * some regions of the IO address space do not get translated, so we |
| 794 | * must not give devices IO addresses in those regions. The regions |
| 795 | * are the 640KB-1MB region and the two PCI peripheral memory holes. |
| 796 | * Reserve all of them in the IOMMU bitmap to avoid giving them out |
| 797 | * later. |
| 798 | */ |
| 799 | static void __init calgary_reserve_regions(struct pci_dev *dev) |
| 800 | { |
| 801 | unsigned int npages; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 802 | u64 start; |
| 803 | struct iommu_table *tbl = dev->sysdata; |
| 804 | |
Muli Ben-Yehuda | 310adfd | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 805 | /* reserve EMERGENCY_PAGES from bad_dma_address and up */ |
| 806 | iommu_range_reserve(tbl, bad_dma_address, EMERGENCY_PAGES); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 807 | |
| 808 | /* avoid the BIOS/VGA first 640KB-1MB region */ |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 809 | /* for CalIOC2 - avoid the entire first 2MB */ |
| 810 | if (is_calgary(dev->device)) { |
| 811 | start = (640 * 1024); |
| 812 | npages = ((1024 - 640) * 1024) >> PAGE_SHIFT; |
| 813 | } else { /* calioc2 */ |
| 814 | start = 0; |
| 815 | npages = (2 * 1024 * 1024) >> PAGE_SHIFT; |
| 816 | } |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 817 | iommu_range_reserve(tbl, start, npages); |
| 818 | |
| 819 | /* reserve the two PCI peripheral memory regions in IO space */ |
| 820 | calgary_reserve_peripheral_mem_1(dev); |
| 821 | calgary_reserve_peripheral_mem_2(dev); |
| 822 | } |
| 823 | |
| 824 | static int __init calgary_setup_tar(struct pci_dev *dev, void __iomem *bbar) |
| 825 | { |
| 826 | u64 val64; |
| 827 | u64 table_phys; |
| 828 | void __iomem *target; |
| 829 | int ret; |
| 830 | struct iommu_table *tbl; |
| 831 | |
| 832 | /* build TCE tables for each PHB */ |
| 833 | ret = build_tce_table(dev, bbar); |
| 834 | if (ret) |
| 835 | return ret; |
| 836 | |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 837 | tbl = dev->sysdata; |
| 838 | tbl->it_base = (unsigned long)bus_info[dev->bus->number].tce_space; |
| 839 | tce_free(tbl, 0, tbl->it_size); |
| 840 | |
Muli Ben-Yehuda | c386010 | 2007-07-21 17:10:53 +0200 | [diff] [blame] | 841 | if (is_calgary(dev->device)) |
| 842 | tbl->chip_ops = &calgary_chip_ops; |
| 843 | else if (is_calioc2(dev->device)) |
| 844 | tbl->chip_ops = &calioc2_chip_ops; |
| 845 | else |
| 846 | BUG(); |
Muli Ben-Yehuda | ff297b8 | 2007-07-21 17:10:50 +0200 | [diff] [blame] | 847 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 848 | calgary_reserve_regions(dev); |
| 849 | |
| 850 | /* set TARs for each PHB */ |
| 851 | target = calgary_reg(bbar, tar_offset(dev->bus->number)); |
| 852 | val64 = be64_to_cpu(readq(target)); |
| 853 | |
| 854 | /* zero out all TAR bits under sw control */ |
| 855 | val64 &= ~TAR_SW_BITS; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 856 | table_phys = (u64)__pa(tbl->it_base); |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 857 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 858 | val64 |= table_phys; |
| 859 | |
| 860 | BUG_ON(specified_table_size > TCE_TABLE_SIZE_8M); |
| 861 | val64 |= (u64) specified_table_size; |
| 862 | |
| 863 | tbl->tar_val = cpu_to_be64(val64); |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 864 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 865 | writeq(tbl->tar_val, target); |
| 866 | readq(target); /* flush */ |
| 867 | |
| 868 | return 0; |
| 869 | } |
| 870 | |
Muli Ben-Yehuda | b8f4fe6 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 871 | static void __init calgary_free_bus(struct pci_dev *dev) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 872 | { |
| 873 | u64 val64; |
| 874 | struct iommu_table *tbl = dev->sysdata; |
| 875 | void __iomem *target; |
Muli Ben-Yehuda | b8f4fe6 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 876 | unsigned int bitmapsz; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 877 | |
| 878 | target = calgary_reg(tbl->bbar, tar_offset(dev->bus->number)); |
| 879 | val64 = be64_to_cpu(readq(target)); |
| 880 | val64 &= ~TAR_SW_BITS; |
| 881 | writeq(cpu_to_be64(val64), target); |
| 882 | readq(target); /* flush */ |
| 883 | |
Muli Ben-Yehuda | b8f4fe6 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 884 | bitmapsz = tbl->it_size / BITS_PER_BYTE; |
| 885 | free_pages((unsigned long)tbl->it_map, get_order(bitmapsz)); |
| 886 | tbl->it_map = NULL; |
| 887 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 888 | kfree(tbl); |
| 889 | dev->sysdata = NULL; |
Muli Ben-Yehuda | b8f4fe6 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 890 | |
| 891 | /* Can't free bootmem allocated memory after system is up :-( */ |
| 892 | bus_info[dev->bus->number].tce_space = NULL; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 893 | } |
| 894 | |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 895 | static void calgary_dump_error_regs(struct iommu_table *tbl) |
| 896 | { |
| 897 | void __iomem *bbar = tbl->bbar; |
| 898 | u32 csr, csmr, plssr, mck; |
| 899 | void __iomem *target; |
| 900 | unsigned long phboff = phb_offset(tbl->it_busno); |
| 901 | unsigned long erroff; |
| 902 | u32 errregs[7]; |
| 903 | int i; |
| 904 | |
| 905 | /* dump CSR */ |
| 906 | target = calgary_reg(bbar, phboff | PHB_CSR_OFFSET); |
| 907 | csr = be32_to_cpu(readl(target)); |
| 908 | /* dump PLSSR */ |
| 909 | target = calgary_reg(bbar, phboff | PHB_PLSSR_OFFSET); |
| 910 | plssr = be32_to_cpu(readl(target)); |
| 911 | /* dump CSMR */ |
| 912 | target = calgary_reg(bbar, phboff | 0x290); |
| 913 | csmr = be32_to_cpu(readl(target)); |
| 914 | /* dump mck */ |
| 915 | target = calgary_reg(bbar, phboff | 0x800); |
| 916 | mck = be32_to_cpu(readl(target)); |
| 917 | |
| 918 | printk(KERN_EMERG "Calgary: 0x%08x@CSR 0x%08x@PLSSR 0x%08x@CSMR " |
| 919 | "0x%08x@MCK\n", csr, plssr, csmr, mck); |
| 920 | |
| 921 | /* dump rest of error regs */ |
| 922 | printk(KERN_EMERG "Calgary: "); |
| 923 | for (i = 0; i < ARRAY_SIZE(errregs); i++) { |
| 924 | erroff = (0x810 + (i * 0x10)); /* err regs are at 0x810 - 0x870 */ |
| 925 | target = calgary_reg(bbar, phboff | erroff); |
| 926 | errregs[i] = be32_to_cpu(readl(target)); |
| 927 | printk("0x%08x@0x%lx ", errregs[i], erroff); |
| 928 | } |
| 929 | printk("\n"); |
| 930 | } |
| 931 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 932 | static void calgary_watchdog(unsigned long data) |
| 933 | { |
| 934 | struct pci_dev *dev = (struct pci_dev *)data; |
| 935 | struct iommu_table *tbl = dev->sysdata; |
| 936 | void __iomem *bbar = tbl->bbar; |
| 937 | u32 val32; |
| 938 | void __iomem *target; |
| 939 | |
| 940 | target = calgary_reg(bbar, phb_offset(tbl->it_busno) | PHB_CSR_OFFSET); |
| 941 | val32 = be32_to_cpu(readl(target)); |
| 942 | |
| 943 | /* If no error, the agent ID in the CSR is not valid */ |
| 944 | if (val32 & CSR_AGENT_MASK) { |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 945 | printk(KERN_EMERG "Calgary: DMA error on PHB %#x\n", |
| 946 | dev->bus->number); |
| 947 | calgary_dump_error_regs(tbl); |
| 948 | |
| 949 | /* reset error */ |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 950 | writel(0, target); |
| 951 | |
| 952 | /* Disable bus that caused the error */ |
| 953 | target = calgary_reg(bbar, phb_offset(tbl->it_busno) | |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 954 | PHB_CONFIG_RW_OFFSET); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 955 | val32 = be32_to_cpu(readl(target)); |
| 956 | val32 |= PHB_SLOT_DISABLE; |
| 957 | writel(cpu_to_be32(val32), target); |
| 958 | readl(target); /* flush */ |
| 959 | } else { |
| 960 | /* Reset the timer */ |
| 961 | mod_timer(&tbl->watchdog_timer, jiffies + 2 * HZ); |
| 962 | } |
| 963 | } |
| 964 | |
Muli Ben-Yehuda | a2b663f | 2007-07-21 17:10:47 +0200 | [diff] [blame] | 965 | static void __init calgary_set_split_completion_timeout(void __iomem *bbar, |
| 966 | unsigned char busnum, unsigned long timeout) |
Muli Ben-Yehuda | cb01fc7 | 2006-10-22 00:41:15 +0200 | [diff] [blame] | 967 | { |
| 968 | u64 val64; |
| 969 | void __iomem *target; |
Muli Ben-Yehuda | 58db854 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 970 | unsigned int phb_shift = ~0; /* silence gcc */ |
Muli Ben-Yehuda | cb01fc7 | 2006-10-22 00:41:15 +0200 | [diff] [blame] | 971 | u64 mask; |
| 972 | |
| 973 | switch (busno_to_phbid(busnum)) { |
| 974 | case 0: phb_shift = (63 - 19); |
| 975 | break; |
| 976 | case 1: phb_shift = (63 - 23); |
| 977 | break; |
| 978 | case 2: phb_shift = (63 - 27); |
| 979 | break; |
| 980 | case 3: phb_shift = (63 - 35); |
| 981 | break; |
| 982 | default: |
| 983 | BUG_ON(busno_to_phbid(busnum)); |
| 984 | } |
| 985 | |
| 986 | target = calgary_reg(bbar, CALGARY_CONFIG_REG); |
| 987 | val64 = be64_to_cpu(readq(target)); |
| 988 | |
| 989 | /* zero out this PHB's timer bits */ |
| 990 | mask = ~(0xFUL << phb_shift); |
| 991 | val64 &= mask; |
Muli Ben-Yehuda | a2b663f | 2007-07-21 17:10:47 +0200 | [diff] [blame] | 992 | val64 |= (timeout << phb_shift); |
Muli Ben-Yehuda | cb01fc7 | 2006-10-22 00:41:15 +0200 | [diff] [blame] | 993 | writeq(cpu_to_be64(val64), target); |
| 994 | readq(target); /* flush */ |
| 995 | } |
| 996 | |
Muli Ben-Yehuda | c386010 | 2007-07-21 17:10:53 +0200 | [diff] [blame] | 997 | static void calioc2_handle_quirks(struct iommu_table *tbl, struct pci_dev *dev) |
| 998 | { |
| 999 | unsigned char busnum = dev->bus->number; |
| 1000 | void __iomem *bbar = tbl->bbar; |
| 1001 | void __iomem *target; |
| 1002 | u32 val; |
| 1003 | |
| 1004 | /* |
| 1005 | * CalIOC2 designers recommend setting bit 8 in 0xnDB0 to 1 |
| 1006 | */ |
| 1007 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_SAVIOR_L2); |
| 1008 | val = cpu_to_be32(readl(target)); |
| 1009 | val |= 0x00800000; |
| 1010 | writel(cpu_to_be32(val), target); |
| 1011 | } |
| 1012 | |
| 1013 | static void calgary_handle_quirks(struct iommu_table *tbl, struct pci_dev *dev) |
Muli Ben-Yehuda | b8d2ea1 | 2007-07-21 17:10:49 +0200 | [diff] [blame] | 1014 | { |
| 1015 | unsigned char busnum = dev->bus->number; |
Muli Ben-Yehuda | b8d2ea1 | 2007-07-21 17:10:49 +0200 | [diff] [blame] | 1016 | |
| 1017 | /* |
| 1018 | * Give split completion a longer timeout on bus 1 for aic94xx |
| 1019 | * http://bugzilla.kernel.org/show_bug.cgi?id=7180 |
| 1020 | */ |
Muli Ben-Yehuda | c386010 | 2007-07-21 17:10:53 +0200 | [diff] [blame] | 1021 | if (is_calgary(dev->device) && (busnum == 1)) |
Muli Ben-Yehuda | b8d2ea1 | 2007-07-21 17:10:49 +0200 | [diff] [blame] | 1022 | calgary_set_split_completion_timeout(tbl->bbar, busnum, |
| 1023 | CCR_2SEC_TIMEOUT); |
| 1024 | } |
| 1025 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1026 | static void __init calgary_enable_translation(struct pci_dev *dev) |
| 1027 | { |
| 1028 | u32 val32; |
| 1029 | unsigned char busnum; |
| 1030 | void __iomem *target; |
| 1031 | void __iomem *bbar; |
| 1032 | struct iommu_table *tbl; |
| 1033 | |
| 1034 | busnum = dev->bus->number; |
| 1035 | tbl = dev->sysdata; |
| 1036 | bbar = tbl->bbar; |
| 1037 | |
| 1038 | /* enable TCE in PHB Config Register */ |
| 1039 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_CONFIG_RW_OFFSET); |
| 1040 | val32 = be32_to_cpu(readl(target)); |
| 1041 | val32 |= PHB_TCE_ENABLE | PHB_DAC_DISABLE | PHB_MCSR_ENABLE; |
| 1042 | |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1043 | printk(KERN_INFO "Calgary: enabling translation on %s PHB %#x\n", |
| 1044 | (dev->device == PCI_DEVICE_ID_IBM_CALGARY) ? |
| 1045 | "Calgary" : "CalIOC2", busnum); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1046 | printk(KERN_INFO "Calgary: errant DMAs will now be prevented on this " |
| 1047 | "bus.\n"); |
| 1048 | |
| 1049 | writel(cpu_to_be32(val32), target); |
| 1050 | readl(target); /* flush */ |
| 1051 | |
| 1052 | init_timer(&tbl->watchdog_timer); |
| 1053 | tbl->watchdog_timer.function = &calgary_watchdog; |
| 1054 | tbl->watchdog_timer.data = (unsigned long)dev; |
| 1055 | mod_timer(&tbl->watchdog_timer, jiffies); |
| 1056 | } |
| 1057 | |
| 1058 | static void __init calgary_disable_translation(struct pci_dev *dev) |
| 1059 | { |
| 1060 | u32 val32; |
| 1061 | unsigned char busnum; |
| 1062 | void __iomem *target; |
| 1063 | void __iomem *bbar; |
| 1064 | struct iommu_table *tbl; |
| 1065 | |
| 1066 | busnum = dev->bus->number; |
| 1067 | tbl = dev->sysdata; |
| 1068 | bbar = tbl->bbar; |
| 1069 | |
| 1070 | /* disable TCE in PHB Config Register */ |
| 1071 | target = calgary_reg(bbar, phb_offset(busnum) | PHB_CONFIG_RW_OFFSET); |
| 1072 | val32 = be32_to_cpu(readl(target)); |
| 1073 | val32 &= ~(PHB_TCE_ENABLE | PHB_DAC_DISABLE | PHB_MCSR_ENABLE); |
| 1074 | |
Jon Mason | 70d666d | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 1075 | printk(KERN_INFO "Calgary: disabling translation on PHB %#x!\n", busnum); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1076 | writel(cpu_to_be32(val32), target); |
| 1077 | readl(target); /* flush */ |
| 1078 | |
| 1079 | del_timer_sync(&tbl->watchdog_timer); |
| 1080 | } |
| 1081 | |
Muli Ben-Yehuda | a4fc520 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1082 | static void __init calgary_init_one_nontraslated(struct pci_dev *dev) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1083 | { |
Muli Ben-Yehuda | 871b170 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1084 | pci_dev_get(dev); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1085 | dev->sysdata = NULL; |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1086 | |
| 1087 | /* is the device behind a bridge? */ |
| 1088 | if (dev->bus->parent) |
| 1089 | dev->bus->parent->self = dev; |
| 1090 | else |
| 1091 | dev->bus->self = dev; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | static int __init calgary_init_one(struct pci_dev *dev) |
| 1095 | { |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1096 | void __iomem *bbar; |
Muli Ben-Yehuda | ff297b8 | 2007-07-21 17:10:50 +0200 | [diff] [blame] | 1097 | struct iommu_table *tbl; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1098 | int ret; |
| 1099 | |
Jon Mason | dedc993 | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 1100 | BUG_ON(dev->bus->number >= MAX_PHB_BUS_NUM); |
| 1101 | |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1102 | bbar = busno_to_bbar(dev->bus->number); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1103 | ret = calgary_setup_tar(dev, bbar); |
| 1104 | if (ret) |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1105 | goto done; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1106 | |
Muli Ben-Yehuda | 871b170 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1107 | pci_dev_get(dev); |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1108 | |
| 1109 | if (dev->bus->parent) { |
| 1110 | if (dev->bus->parent->self) |
| 1111 | printk(KERN_WARNING "Calgary: IEEEE, dev %p has " |
| 1112 | "bus->parent->self!\n", dev); |
| 1113 | dev->bus->parent->self = dev; |
| 1114 | } else |
| 1115 | dev->bus->self = dev; |
Muli Ben-Yehuda | b8d2ea1 | 2007-07-21 17:10:49 +0200 | [diff] [blame] | 1116 | |
Muli Ben-Yehuda | ff297b8 | 2007-07-21 17:10:50 +0200 | [diff] [blame] | 1117 | tbl = dev->sysdata; |
| 1118 | tbl->chip_ops->handle_quirks(tbl, dev); |
Muli Ben-Yehuda | b8d2ea1 | 2007-07-21 17:10:49 +0200 | [diff] [blame] | 1119 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1120 | calgary_enable_translation(dev); |
| 1121 | |
| 1122 | return 0; |
| 1123 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1124 | done: |
| 1125 | return ret; |
| 1126 | } |
| 1127 | |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1128 | static int __init calgary_locate_bbars(void) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1129 | { |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1130 | int ret; |
| 1131 | int rioidx, phb, bus; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1132 | void __iomem *bbar; |
| 1133 | void __iomem *target; |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1134 | unsigned long offset; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1135 | u8 start_bus, end_bus; |
| 1136 | u32 val; |
| 1137 | |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1138 | ret = -ENODATA; |
| 1139 | for (rioidx = 0; rioidx < rio_table_hdr->num_rio_dev; rioidx++) { |
| 1140 | struct rio_detail *rio = rio_devs[rioidx]; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1141 | |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1142 | if ((rio->type != COMPAT_CALGARY) && (rio->type != ALT_CALGARY)) |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1143 | continue; |
| 1144 | |
| 1145 | /* map entire 1MB of Calgary config space */ |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1146 | bbar = ioremap_nocache(rio->BBAR, 1024 * 1024); |
| 1147 | if (!bbar) |
| 1148 | goto error; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1149 | |
| 1150 | for (phb = 0; phb < PHBS_PER_CALGARY; phb++) { |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1151 | offset = phb_debug_offsets[phb] | PHB_DEBUG_STUFF_OFFSET; |
| 1152 | target = calgary_reg(bbar, offset); |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1153 | |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1154 | val = be32_to_cpu(readl(target)); |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1155 | |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1156 | start_bus = (u8)((val & 0x00FF0000) >> 16); |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1157 | end_bus = (u8)((val & 0x0000FF00) >> 8); |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1158 | |
| 1159 | if (end_bus) { |
| 1160 | for (bus = start_bus; bus <= end_bus; bus++) { |
| 1161 | bus_info[bus].bbar = bbar; |
| 1162 | bus_info[bus].phbid = phb; |
| 1163 | } |
| 1164 | } else { |
| 1165 | bus_info[start_bus].bbar = bbar; |
| 1166 | bus_info[start_bus].phbid = phb; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1171 | return 0; |
| 1172 | |
| 1173 | error: |
| 1174 | /* scan bus_info and iounmap any bbars we previously ioremap'd */ |
| 1175 | for (bus = 0; bus < ARRAY_SIZE(bus_info); bus++) |
| 1176 | if (bus_info[bus].bbar) |
| 1177 | iounmap(bus_info[bus].bbar); |
| 1178 | |
| 1179 | return ret; |
| 1180 | } |
| 1181 | |
| 1182 | static int __init calgary_init(void) |
| 1183 | { |
| 1184 | int ret; |
| 1185 | struct pci_dev *dev = NULL; |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1186 | void* tce_space; |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1187 | |
| 1188 | ret = calgary_locate_bbars(); |
| 1189 | if (ret) |
| 1190 | return ret; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1191 | |
Jon Mason | dedc993 | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 1192 | do { |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1193 | dev = pci_get_device(PCI_VENDOR_ID_IBM, PCI_ANY_ID, dev); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1194 | if (!dev) |
| 1195 | break; |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1196 | if (!is_cal_pci_dev(dev->device)) |
| 1197 | continue; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1198 | if (!translate_phb(dev)) { |
| 1199 | calgary_init_one_nontraslated(dev); |
| 1200 | continue; |
| 1201 | } |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1202 | tce_space = bus_info[dev->bus->number].tce_space; |
| 1203 | if (!tce_space && !translate_empty_slots) { |
| 1204 | printk("Calg: %p failed tce_space check\n", dev); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1205 | continue; |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1206 | } |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1207 | ret = calgary_init_one(dev); |
| 1208 | if (ret) |
| 1209 | goto error; |
Jon Mason | dedc993 | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 1210 | } while (1); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1211 | |
| 1212 | return ret; |
| 1213 | |
| 1214 | error: |
Jon Mason | dedc993 | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 1215 | do { |
Alan Cox | 7cd8b68 | 2006-12-07 02:14:03 +0100 | [diff] [blame] | 1216 | dev = pci_get_device_reverse(PCI_VENDOR_ID_IBM, |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1217 | PCI_ANY_ID, dev); |
Muli Ben-Yehuda | 9f2dc46 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1218 | if (!dev) |
| 1219 | break; |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1220 | if (!is_cal_pci_dev(dev->device)) |
| 1221 | continue; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1222 | if (!translate_phb(dev)) { |
| 1223 | pci_dev_put(dev); |
| 1224 | continue; |
| 1225 | } |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1226 | if (!bus_info[dev->bus->number].tce_space && !translate_empty_slots) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1227 | continue; |
Muli Ben-Yehuda | 871b170 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1228 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1229 | calgary_disable_translation(dev); |
Muli Ben-Yehuda | b8f4fe6 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1230 | calgary_free_bus(dev); |
Muli Ben-Yehuda | 871b170 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1231 | pci_dev_put(dev); /* Undo calgary_init_one()'s pci_dev_get() */ |
Jon Mason | dedc993 | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 1232 | } while (1); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1233 | |
| 1234 | return ret; |
| 1235 | } |
| 1236 | |
| 1237 | static inline int __init determine_tce_table_size(u64 ram) |
| 1238 | { |
| 1239 | int ret; |
| 1240 | |
| 1241 | if (specified_table_size != TCE_TABLE_SIZE_UNSPECIFIED) |
| 1242 | return specified_table_size; |
| 1243 | |
| 1244 | /* |
| 1245 | * Table sizes are from 0 to 7 (TCE_TABLE_SIZE_64K to |
| 1246 | * TCE_TABLE_SIZE_8M). Table size 0 has 8K entries and each |
| 1247 | * larger table size has twice as many entries, so shift the |
| 1248 | * max ram address by 13 to divide by 8K and then look at the |
| 1249 | * order of the result to choose between 0-7. |
| 1250 | */ |
| 1251 | ret = get_order(ram >> 13); |
| 1252 | if (ret > TCE_TABLE_SIZE_8M) |
| 1253 | ret = TCE_TABLE_SIZE_8M; |
| 1254 | |
| 1255 | return ret; |
| 1256 | } |
| 1257 | |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1258 | static int __init build_detail_arrays(void) |
| 1259 | { |
| 1260 | unsigned long ptr; |
| 1261 | int i, scal_detail_size, rio_detail_size; |
| 1262 | |
| 1263 | if (rio_table_hdr->num_scal_dev > MAX_NUMNODES){ |
| 1264 | printk(KERN_WARNING |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1265 | "Calgary: MAX_NUMNODES too low! Defined as %d, " |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1266 | "but system has %d nodes.\n", |
| 1267 | MAX_NUMNODES, rio_table_hdr->num_scal_dev); |
| 1268 | return -ENODEV; |
| 1269 | } |
| 1270 | |
| 1271 | switch (rio_table_hdr->version){ |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1272 | case 2: |
| 1273 | scal_detail_size = 11; |
| 1274 | rio_detail_size = 13; |
| 1275 | break; |
| 1276 | case 3: |
| 1277 | scal_detail_size = 12; |
| 1278 | rio_detail_size = 15; |
| 1279 | break; |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1280 | default: |
| 1281 | printk(KERN_WARNING |
| 1282 | "Calgary: Invalid Rio Grande Table Version: %d\n", |
| 1283 | rio_table_hdr->version); |
| 1284 | return -EPROTO; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | ptr = ((unsigned long)rio_table_hdr) + 3; |
| 1288 | for (i = 0; i < rio_table_hdr->num_scal_dev; |
| 1289 | i++, ptr += scal_detail_size) |
| 1290 | scal_devs[i] = (struct scal_detail *)ptr; |
| 1291 | |
| 1292 | for (i = 0; i < rio_table_hdr->num_rio_dev; |
| 1293 | i++, ptr += rio_detail_size) |
| 1294 | rio_devs[i] = (struct rio_detail *)ptr; |
| 1295 | |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1299 | static int __init calgary_bus_has_devices(int bus, unsigned short pci_dev) |
| 1300 | { |
| 1301 | int dev; |
| 1302 | u32 val; |
| 1303 | |
| 1304 | if (pci_dev == PCI_DEVICE_ID_IBM_CALIOC2) { |
| 1305 | /* |
| 1306 | * FIXME: properly scan for devices accross the |
| 1307 | * PCI-to-PCI bridge on every CalIOC2 port. |
| 1308 | */ |
| 1309 | return 1; |
| 1310 | } |
| 1311 | |
| 1312 | for (dev = 1; dev < 8; dev++) { |
| 1313 | val = read_pci_config(bus, dev, 0, 0); |
| 1314 | if (val != 0xffffffff) |
| 1315 | break; |
| 1316 | } |
| 1317 | return (val != 0xffffffff); |
| 1318 | } |
| 1319 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1320 | void __init detect_calgary(void) |
| 1321 | { |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 1322 | int bus; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1323 | void *tbl; |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 1324 | int calgary_found = 0; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1325 | unsigned long ptr; |
Ingo Molnar | 136f1e7 | 2006-12-20 11:53:32 +0100 | [diff] [blame] | 1326 | unsigned int offset, prev_offset; |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1327 | int ret; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1328 | |
| 1329 | /* |
| 1330 | * if the user specified iommu=off or iommu=soft or we found |
| 1331 | * another HW IOMMU already, bail out. |
| 1332 | */ |
| 1333 | if (swiotlb || no_iommu || iommu_detected) |
| 1334 | return; |
| 1335 | |
Muli Ben-Yehuda | bff6547 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 1336 | if (!use_calgary) |
| 1337 | return; |
| 1338 | |
Andi Kleen | 0637a70 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 1339 | if (!early_pci_allowed()) |
| 1340 | return; |
| 1341 | |
Muli Ben-Yehuda | b92cc55 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 1342 | printk(KERN_DEBUG "Calgary: detecting Calgary via BIOS EBDA area\n"); |
| 1343 | |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1344 | ptr = (unsigned long)phys_to_virt(get_bios_ebda()); |
| 1345 | |
| 1346 | rio_table_hdr = NULL; |
Ingo Molnar | 136f1e7 | 2006-12-20 11:53:32 +0100 | [diff] [blame] | 1347 | prev_offset = 0; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1348 | offset = 0x180; |
Ingo Molnar | 136f1e7 | 2006-12-20 11:53:32 +0100 | [diff] [blame] | 1349 | /* |
| 1350 | * The next offset is stored in the 1st word. |
| 1351 | * Only parse up until the offset increases: |
| 1352 | */ |
| 1353 | while (offset > prev_offset) { |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1354 | /* The block id is stored in the 2nd word */ |
| 1355 | if (*((unsigned short *)(ptr + offset + 2)) == 0x4752){ |
| 1356 | /* set the pointer past the offset & block id */ |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1357 | rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4); |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1358 | break; |
| 1359 | } |
Ingo Molnar | 136f1e7 | 2006-12-20 11:53:32 +0100 | [diff] [blame] | 1360 | prev_offset = offset; |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1361 | offset = *((unsigned short *)(ptr + offset)); |
| 1362 | } |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1363 | if (!rio_table_hdr) { |
Muli Ben-Yehuda | b92cc55 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 1364 | printk(KERN_DEBUG "Calgary: Unable to locate Rio Grande table " |
| 1365 | "in EBDA - bailing!\n"); |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1366 | return; |
| 1367 | } |
| 1368 | |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1369 | ret = build_detail_arrays(); |
| 1370 | if (ret) { |
Muli Ben-Yehuda | b92cc55 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 1371 | printk(KERN_DEBUG "Calgary: build_detail_arrays ret %d\n", ret); |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1372 | return; |
Muli Ben-Yehuda | eae9375 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1373 | } |
Laurent Vivier | b34e90b | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 1374 | |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1375 | specified_table_size = determine_tce_table_size(end_pfn * PAGE_SIZE); |
| 1376 | |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 1377 | for (bus = 0; bus < MAX_PHB_BUS_NUM; bus++) { |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1378 | struct calgary_bus_info *info = &bus_info[bus]; |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1379 | unsigned short pci_device; |
| 1380 | u32 val; |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 1381 | |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1382 | val = read_pci_config(bus, 0, 0, 0); |
| 1383 | pci_device = (val & 0xFFFF0000) >> 16; |
| 1384 | |
| 1385 | if (!is_cal_pci_dev(pci_device)) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1386 | continue; |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 1387 | |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1388 | if (info->translation_disabled) |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1389 | continue; |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1390 | |
Muli Ben-Yehuda | 8a24459 | 2007-07-21 17:10:52 +0200 | [diff] [blame] | 1391 | if (calgary_bus_has_devices(bus, pci_device) || |
| 1392 | translate_empty_slots) { |
| 1393 | tbl = alloc_tce_table(); |
| 1394 | if (!tbl) |
| 1395 | goto cleanup; |
| 1396 | info->tce_space = tbl; |
| 1397 | calgary_found = 1; |
| 1398 | printk("Calg: allocated tce_table %p for bus 0x%x\n", |
| 1399 | info->tce_space, bus); |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 1400 | } |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
Muli Ben-Yehuda | b92cc55 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 1403 | printk(KERN_DEBUG "Calgary: finished detection, Calgary %s\n", |
| 1404 | calgary_found ? "found" : "not found"); |
| 1405 | |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 1406 | if (calgary_found) { |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1407 | iommu_detected = 1; |
| 1408 | calgary_detected = 1; |
Muli Ben-Yehuda | de68465 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 1409 | printk(KERN_INFO "PCI-DMA: Calgary IOMMU detected.\n"); |
| 1410 | printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d, " |
| 1411 | "CONFIG_IOMMU_DEBUG is %s.\n", specified_table_size, |
| 1412 | debugging ? "enabled" : "disabled"); |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1413 | } |
| 1414 | return; |
| 1415 | |
| 1416 | cleanup: |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1417 | for (--bus; bus >= 0; --bus) { |
| 1418 | struct calgary_bus_info *info = &bus_info[bus]; |
| 1419 | |
| 1420 | if (info->tce_space) |
| 1421 | free_tce_table(info->tce_space); |
| 1422 | } |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | int __init calgary_iommu_init(void) |
| 1426 | { |
| 1427 | int ret; |
| 1428 | |
| 1429 | if (no_iommu || swiotlb) |
| 1430 | return -ENODEV; |
| 1431 | |
| 1432 | if (!calgary_detected) |
| 1433 | return -ENODEV; |
| 1434 | |
| 1435 | /* ok, we're trying to use Calgary - let's roll */ |
| 1436 | printk(KERN_INFO "PCI-DMA: Using Calgary IOMMU\n"); |
| 1437 | |
| 1438 | ret = calgary_init(); |
| 1439 | if (ret) { |
| 1440 | printk(KERN_ERR "PCI-DMA: Calgary init failed %d, " |
| 1441 | "falling back to no_iommu\n", ret); |
| 1442 | if (end_pfn > MAX_DMA32_PFN) |
| 1443 | printk(KERN_ERR "WARNING more than 4GB of memory, " |
| 1444 | "32bit PCI may malfunction.\n"); |
| 1445 | return ret; |
| 1446 | } |
| 1447 | |
| 1448 | force_iommu = 1; |
Muli Ben-Yehuda | 310adfd | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 1449 | bad_dma_address = 0x0; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1450 | dma_ops = &calgary_dma_ops; |
| 1451 | |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
| 1455 | static int __init calgary_parse_options(char *p) |
| 1456 | { |
| 1457 | unsigned int bridge; |
| 1458 | size_t len; |
| 1459 | char* endp; |
| 1460 | |
| 1461 | while (*p) { |
| 1462 | if (!strncmp(p, "64k", 3)) |
| 1463 | specified_table_size = TCE_TABLE_SIZE_64K; |
| 1464 | else if (!strncmp(p, "128k", 4)) |
| 1465 | specified_table_size = TCE_TABLE_SIZE_128K; |
| 1466 | else if (!strncmp(p, "256k", 4)) |
| 1467 | specified_table_size = TCE_TABLE_SIZE_256K; |
| 1468 | else if (!strncmp(p, "512k", 4)) |
| 1469 | specified_table_size = TCE_TABLE_SIZE_512K; |
| 1470 | else if (!strncmp(p, "1M", 2)) |
| 1471 | specified_table_size = TCE_TABLE_SIZE_1M; |
| 1472 | else if (!strncmp(p, "2M", 2)) |
| 1473 | specified_table_size = TCE_TABLE_SIZE_2M; |
| 1474 | else if (!strncmp(p, "4M", 2)) |
| 1475 | specified_table_size = TCE_TABLE_SIZE_4M; |
| 1476 | else if (!strncmp(p, "8M", 2)) |
| 1477 | specified_table_size = TCE_TABLE_SIZE_8M; |
| 1478 | |
| 1479 | len = strlen("translate_empty_slots"); |
| 1480 | if (!strncmp(p, "translate_empty_slots", len)) |
| 1481 | translate_empty_slots = 1; |
| 1482 | |
| 1483 | len = strlen("disable"); |
| 1484 | if (!strncmp(p, "disable", len)) { |
| 1485 | p += len; |
| 1486 | if (*p == '=') |
| 1487 | ++p; |
| 1488 | if (*p == '\0') |
| 1489 | break; |
| 1490 | bridge = simple_strtol(p, &endp, 0); |
| 1491 | if (p == endp) |
| 1492 | break; |
| 1493 | |
Jon Mason | d2105b1 | 2006-07-29 21:42:43 +0200 | [diff] [blame] | 1494 | if (bridge < MAX_PHB_BUS_NUM) { |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1495 | printk(KERN_INFO "Calgary: disabling " |
Jon Mason | 70d666d | 2006-10-05 18:47:21 +0200 | [diff] [blame] | 1496 | "translation for PHB %#x\n", bridge); |
Muli Ben-Yehuda | f38db65 | 2006-09-26 10:52:31 +0200 | [diff] [blame] | 1497 | bus_info[bridge].translation_disabled = 1; |
Jon Mason | e465058 | 2006-06-26 13:58:14 +0200 | [diff] [blame] | 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | p = strpbrk(p, ","); |
| 1502 | if (!p) |
| 1503 | break; |
| 1504 | |
| 1505 | p++; /* skip ',' */ |
| 1506 | } |
| 1507 | return 1; |
| 1508 | } |
| 1509 | __setup("calgary=", calgary_parse_options); |