David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 1 | /* pci_sun4v.c: SUN4V specific PCI controller support. |
| 2 | * |
| 3 | * Copyright (C) 2006 David S. Miller (davem@davemloft.net) |
| 4 | */ |
| 5 | |
| 6 | #include <linux/kernel.h> |
| 7 | #include <linux/types.h> |
| 8 | #include <linux/pci.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/slab.h> |
| 11 | #include <linux/interrupt.h> |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 12 | #include <linux/percpu.h> |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 13 | |
| 14 | #include <asm/pbm.h> |
| 15 | #include <asm/iommu.h> |
| 16 | #include <asm/irq.h> |
| 17 | #include <asm/upa.h> |
| 18 | #include <asm/pstate.h> |
| 19 | #include <asm/oplib.h> |
| 20 | #include <asm/hypervisor.h> |
| 21 | |
| 22 | #include "pci_impl.h" |
| 23 | #include "iommu_common.h" |
| 24 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 25 | #include "pci_sun4v.h" |
| 26 | |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 27 | #define PGLIST_NENTS 2048 |
| 28 | |
| 29 | struct sun4v_pglist { |
| 30 | u64 pglist[PGLIST_NENTS]; |
| 31 | }; |
| 32 | |
| 33 | static DEFINE_PER_CPU(struct sun4v_pglist, iommu_pglists); |
| 34 | |
| 35 | static long pci_arena_alloc(struct pci_iommu_arena *arena, unsigned long npages) |
| 36 | { |
| 37 | unsigned long n, i, start, end, limit; |
| 38 | int pass; |
| 39 | |
| 40 | limit = arena->limit; |
| 41 | start = arena->hint; |
| 42 | pass = 0; |
| 43 | |
| 44 | again: |
| 45 | n = find_next_zero_bit(arena->map, limit, start); |
| 46 | end = n + npages; |
| 47 | if (unlikely(end >= limit)) { |
| 48 | if (likely(pass < 1)) { |
| 49 | limit = start; |
| 50 | start = 0; |
| 51 | pass++; |
| 52 | goto again; |
| 53 | } else { |
| 54 | /* Scanned the whole thing, give up. */ |
| 55 | return -1; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | for (i = n; i < end; i++) { |
| 60 | if (test_bit(i, arena->map)) { |
| 61 | start = i + 1; |
| 62 | goto again; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | for (i = n; i < end; i++) |
| 67 | __set_bit(i, arena->map); |
| 68 | |
| 69 | arena->hint = end; |
| 70 | |
| 71 | return n; |
| 72 | } |
| 73 | |
| 74 | static void pci_arena_free(struct pci_iommu_arena *arena, unsigned long base, unsigned long npages) |
| 75 | { |
| 76 | unsigned long i; |
| 77 | |
| 78 | for (i = base; i < (base + npages); i++) |
| 79 | __clear_bit(i, arena->map); |
| 80 | } |
| 81 | |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 82 | static void *pci_4v_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp) |
| 83 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 84 | struct pcidev_cookie *pcp; |
| 85 | struct pci_iommu *iommu; |
| 86 | unsigned long devhandle, flags, order, first_page, npages, n; |
| 87 | void *ret; |
| 88 | long entry; |
| 89 | u64 *pglist; |
| 90 | int cpu; |
| 91 | |
| 92 | size = IO_PAGE_ALIGN(size); |
| 93 | order = get_order(size); |
| 94 | if (order >= MAX_ORDER) |
| 95 | return NULL; |
| 96 | |
| 97 | npages = size >> IO_PAGE_SHIFT; |
| 98 | if (npages > PGLIST_NENTS) |
| 99 | return NULL; |
| 100 | |
| 101 | first_page = __get_free_pages(GFP_ATOMIC, order); |
| 102 | if (first_page == 0UL) |
| 103 | return NULL; |
| 104 | memset((char *)first_page, 0, PAGE_SIZE << order); |
| 105 | |
| 106 | pcp = pdev->sysdata; |
| 107 | devhandle = pcp->pbm->devhandle; |
| 108 | iommu = pcp->pbm->iommu; |
| 109 | |
| 110 | spin_lock_irqsave(&iommu->lock, flags); |
| 111 | entry = pci_arena_alloc(&iommu->arena, npages); |
| 112 | spin_unlock_irqrestore(&iommu->lock, flags); |
| 113 | |
| 114 | if (unlikely(entry < 0L)) { |
| 115 | free_pages(first_page, order); |
| 116 | return NULL; |
| 117 | } |
| 118 | |
| 119 | *dma_addrp = (iommu->page_table_map_base + |
| 120 | (entry << IO_PAGE_SHIFT)); |
| 121 | ret = (void *) first_page; |
| 122 | first_page = __pa(first_page); |
| 123 | |
| 124 | cpu = get_cpu(); |
| 125 | |
| 126 | pglist = &__get_cpu_var(iommu_pglists).pglist[0]; |
| 127 | for (n = 0; n < npages; n++) |
| 128 | pglist[n] = first_page + (n * PAGE_SIZE); |
| 129 | |
| 130 | do { |
| 131 | unsigned long num; |
| 132 | |
| 133 | num = pci_sun4v_iommu_map(devhandle, HV_PCI_TSBID(0, entry), |
| 134 | npages, |
| 135 | (HV_PCI_MAP_ATTR_READ | |
| 136 | HV_PCI_MAP_ATTR_WRITE), |
| 137 | __pa(pglist)); |
| 138 | entry += num; |
| 139 | npages -= num; |
| 140 | pglist += num; |
| 141 | } while (npages != 0); |
| 142 | |
| 143 | put_cpu(); |
| 144 | |
| 145 | return ret; |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | static void pci_4v_free_consistent(struct pci_dev *pdev, size_t size, void *cpu, dma_addr_t dvma) |
| 149 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 150 | struct pcidev_cookie *pcp; |
| 151 | struct pci_iommu *iommu; |
| 152 | unsigned long flags, order, npages, entry, devhandle; |
| 153 | |
| 154 | npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT; |
| 155 | pcp = pdev->sysdata; |
| 156 | iommu = pcp->pbm->iommu; |
| 157 | devhandle = pcp->pbm->devhandle; |
| 158 | entry = ((dvma - iommu->page_table_map_base) >> IO_PAGE_SHIFT); |
| 159 | |
| 160 | spin_lock_irqsave(&iommu->lock, flags); |
| 161 | |
| 162 | pci_arena_free(&iommu->arena, entry, npages); |
| 163 | |
| 164 | do { |
| 165 | unsigned long num; |
| 166 | |
| 167 | num = pci_sun4v_iommu_demap(devhandle, HV_PCI_TSBID(0, entry), |
| 168 | npages); |
| 169 | entry += num; |
| 170 | npages -= num; |
| 171 | } while (npages != 0); |
| 172 | |
| 173 | spin_unlock_irqrestore(&iommu->lock, flags); |
| 174 | |
| 175 | order = get_order(size); |
| 176 | if (order < 10) |
| 177 | free_pages((unsigned long)cpu, order); |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static dma_addr_t pci_4v_map_single(struct pci_dev *pdev, void *ptr, size_t sz, int direction) |
| 181 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 182 | struct pcidev_cookie *pcp; |
| 183 | struct pci_iommu *iommu; |
| 184 | unsigned long flags, npages, oaddr; |
| 185 | unsigned long i, base_paddr, devhandle; |
| 186 | u32 bus_addr, ret; |
| 187 | unsigned long prot; |
| 188 | long entry; |
| 189 | u64 *pglist; |
| 190 | int cpu; |
| 191 | |
| 192 | pcp = pdev->sysdata; |
| 193 | iommu = pcp->pbm->iommu; |
| 194 | devhandle = pcp->pbm->devhandle; |
| 195 | |
| 196 | if (unlikely(direction == PCI_DMA_NONE)) |
| 197 | goto bad; |
| 198 | |
| 199 | oaddr = (unsigned long)ptr; |
| 200 | npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK); |
| 201 | npages >>= IO_PAGE_SHIFT; |
| 202 | if (unlikely(npages > PGLIST_NENTS)) |
| 203 | goto bad; |
| 204 | |
| 205 | spin_lock_irqsave(&iommu->lock, flags); |
| 206 | entry = pci_arena_alloc(&iommu->arena, npages); |
| 207 | spin_unlock_irqrestore(&iommu->lock, flags); |
| 208 | |
| 209 | if (unlikely(entry < 0L)) |
| 210 | goto bad; |
| 211 | |
| 212 | bus_addr = (iommu->page_table_map_base + |
| 213 | (entry << IO_PAGE_SHIFT)); |
| 214 | ret = bus_addr | (oaddr & ~IO_PAGE_MASK); |
| 215 | base_paddr = __pa(oaddr & IO_PAGE_MASK); |
| 216 | prot = HV_PCI_MAP_ATTR_READ; |
| 217 | if (direction != PCI_DMA_TODEVICE) |
| 218 | prot |= HV_PCI_MAP_ATTR_WRITE; |
| 219 | |
| 220 | cpu = get_cpu(); |
| 221 | |
| 222 | pglist = &__get_cpu_var(iommu_pglists).pglist[0]; |
| 223 | for (i = 0; i < npages; i++, base_paddr += IO_PAGE_SIZE) |
| 224 | pglist[i] = base_paddr; |
| 225 | |
| 226 | do { |
| 227 | unsigned long num; |
| 228 | |
| 229 | num = pci_sun4v_iommu_map(devhandle, HV_PCI_TSBID(0, entry), |
| 230 | npages, prot, |
| 231 | __pa(pglist)); |
| 232 | entry += num; |
| 233 | npages -= num; |
| 234 | pglist += num; |
| 235 | } while (npages != 0); |
| 236 | |
| 237 | put_cpu(); |
| 238 | |
| 239 | return ret; |
| 240 | |
| 241 | bad: |
| 242 | if (printk_ratelimit()) |
| 243 | WARN_ON(1); |
| 244 | return PCI_DMA_ERROR_CODE; |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static void pci_4v_unmap_single(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int direction) |
| 248 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 249 | struct pcidev_cookie *pcp; |
| 250 | struct pci_iommu *iommu; |
| 251 | unsigned long flags, npages, devhandle; |
| 252 | long entry; |
| 253 | |
| 254 | if (unlikely(direction == PCI_DMA_NONE)) { |
| 255 | if (printk_ratelimit()) |
| 256 | WARN_ON(1); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | pcp = pdev->sysdata; |
| 261 | iommu = pcp->pbm->iommu; |
| 262 | devhandle = pcp->pbm->devhandle; |
| 263 | |
| 264 | npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK); |
| 265 | npages >>= IO_PAGE_SHIFT; |
| 266 | bus_addr &= IO_PAGE_MASK; |
| 267 | |
| 268 | spin_lock_irqsave(&iommu->lock, flags); |
| 269 | |
| 270 | entry = (bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT; |
| 271 | pci_arena_free(&iommu->arena, entry, npages); |
| 272 | |
| 273 | do { |
| 274 | unsigned long num; |
| 275 | |
| 276 | num = pci_sun4v_iommu_demap(devhandle, HV_PCI_TSBID(0, entry), |
| 277 | npages); |
| 278 | entry += num; |
| 279 | npages -= num; |
| 280 | } while (npages != 0); |
| 281 | |
| 282 | spin_unlock_irqrestore(&iommu->lock, flags); |
| 283 | } |
| 284 | |
| 285 | #define SG_ENT_PHYS_ADDRESS(SG) \ |
| 286 | (__pa(page_address((SG)->page)) + (SG)->offset) |
| 287 | |
| 288 | static inline void fill_sg(long entry, unsigned long devhandle, |
| 289 | struct scatterlist *sg, |
| 290 | int nused, int nelems, unsigned long prot) |
| 291 | { |
| 292 | struct scatterlist *dma_sg = sg; |
| 293 | struct scatterlist *sg_end = sg + nelems; |
| 294 | int i, cpu, pglist_ent; |
| 295 | u64 *pglist; |
| 296 | |
| 297 | cpu = get_cpu(); |
| 298 | pglist = &__get_cpu_var(iommu_pglists).pglist[0]; |
| 299 | pglist_ent = 0; |
| 300 | for (i = 0; i < nused; i++) { |
| 301 | unsigned long pteval = ~0UL; |
| 302 | u32 dma_npages; |
| 303 | |
| 304 | dma_npages = ((dma_sg->dma_address & (IO_PAGE_SIZE - 1UL)) + |
| 305 | dma_sg->dma_length + |
| 306 | ((IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT; |
| 307 | do { |
| 308 | unsigned long offset; |
| 309 | signed int len; |
| 310 | |
| 311 | /* If we are here, we know we have at least one |
| 312 | * more page to map. So walk forward until we |
| 313 | * hit a page crossing, and begin creating new |
| 314 | * mappings from that spot. |
| 315 | */ |
| 316 | for (;;) { |
| 317 | unsigned long tmp; |
| 318 | |
| 319 | tmp = SG_ENT_PHYS_ADDRESS(sg); |
| 320 | len = sg->length; |
| 321 | if (((tmp ^ pteval) >> IO_PAGE_SHIFT) != 0UL) { |
| 322 | pteval = tmp & IO_PAGE_MASK; |
| 323 | offset = tmp & (IO_PAGE_SIZE - 1UL); |
| 324 | break; |
| 325 | } |
| 326 | if (((tmp ^ (tmp + len - 1UL)) >> IO_PAGE_SHIFT) != 0UL) { |
| 327 | pteval = (tmp + IO_PAGE_SIZE) & IO_PAGE_MASK; |
| 328 | offset = 0UL; |
| 329 | len -= (IO_PAGE_SIZE - (tmp & (IO_PAGE_SIZE - 1UL))); |
| 330 | break; |
| 331 | } |
| 332 | sg++; |
| 333 | } |
| 334 | |
| 335 | pteval = (pteval & IOPTE_PAGE); |
| 336 | while (len > 0) { |
| 337 | pglist[pglist_ent++] = pteval; |
| 338 | pteval += IO_PAGE_SIZE; |
| 339 | len -= (IO_PAGE_SIZE - offset); |
| 340 | offset = 0; |
| 341 | dma_npages--; |
| 342 | } |
| 343 | |
| 344 | pteval = (pteval & IOPTE_PAGE) + len; |
| 345 | sg++; |
| 346 | |
| 347 | /* Skip over any tail mappings we've fully mapped, |
| 348 | * adjusting pteval along the way. Stop when we |
| 349 | * detect a page crossing event. |
| 350 | */ |
| 351 | while (sg < sg_end && |
| 352 | (pteval << (64 - IO_PAGE_SHIFT)) != 0UL && |
| 353 | (pteval == SG_ENT_PHYS_ADDRESS(sg)) && |
| 354 | ((pteval ^ |
| 355 | (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) { |
| 356 | pteval += sg->length; |
| 357 | sg++; |
| 358 | } |
| 359 | if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL) |
| 360 | pteval = ~0UL; |
| 361 | } while (dma_npages != 0); |
| 362 | dma_sg++; |
| 363 | } |
| 364 | |
| 365 | BUG_ON(pglist_ent == 0); |
| 366 | |
| 367 | do { |
| 368 | unsigned long num; |
| 369 | |
| 370 | num = pci_sun4v_iommu_demap(devhandle, HV_PCI_TSBID(0, entry), |
| 371 | pglist_ent); |
| 372 | entry += num; |
| 373 | pglist_ent -= num; |
| 374 | } while (pglist_ent != 0); |
| 375 | |
| 376 | put_cpu(); |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static int pci_4v_map_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction) |
| 380 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 381 | struct pcidev_cookie *pcp; |
| 382 | struct pci_iommu *iommu; |
| 383 | unsigned long flags, npages, prot, devhandle; |
| 384 | u32 dma_base; |
| 385 | struct scatterlist *sgtmp; |
| 386 | long entry; |
| 387 | int used; |
| 388 | |
| 389 | /* Fast path single entry scatterlists. */ |
| 390 | if (nelems == 1) { |
| 391 | sglist->dma_address = |
| 392 | pci_4v_map_single(pdev, |
| 393 | (page_address(sglist->page) + sglist->offset), |
| 394 | sglist->length, direction); |
| 395 | if (unlikely(sglist->dma_address == PCI_DMA_ERROR_CODE)) |
| 396 | return 0; |
| 397 | sglist->dma_length = sglist->length; |
| 398 | return 1; |
| 399 | } |
| 400 | |
| 401 | pcp = pdev->sysdata; |
| 402 | iommu = pcp->pbm->iommu; |
| 403 | devhandle = pcp->pbm->devhandle; |
| 404 | |
| 405 | if (unlikely(direction == PCI_DMA_NONE)) |
| 406 | goto bad; |
| 407 | |
| 408 | /* Step 1: Prepare scatter list. */ |
| 409 | npages = prepare_sg(sglist, nelems); |
| 410 | if (unlikely(npages > PGLIST_NENTS)) |
| 411 | goto bad; |
| 412 | |
| 413 | /* Step 2: Allocate a cluster and context, if necessary. */ |
| 414 | spin_lock_irqsave(&iommu->lock, flags); |
| 415 | entry = pci_arena_alloc(&iommu->arena, npages); |
| 416 | spin_unlock_irqrestore(&iommu->lock, flags); |
| 417 | |
| 418 | if (unlikely(entry < 0L)) |
| 419 | goto bad; |
| 420 | |
| 421 | dma_base = iommu->page_table_map_base + |
| 422 | (entry << IO_PAGE_SHIFT); |
| 423 | |
| 424 | /* Step 3: Normalize DMA addresses. */ |
| 425 | used = nelems; |
| 426 | |
| 427 | sgtmp = sglist; |
| 428 | while (used && sgtmp->dma_length) { |
| 429 | sgtmp->dma_address += dma_base; |
| 430 | sgtmp++; |
| 431 | used--; |
| 432 | } |
| 433 | used = nelems - used; |
| 434 | |
| 435 | /* Step 4: Create the mappings. */ |
| 436 | prot = HV_PCI_MAP_ATTR_READ; |
| 437 | if (direction != PCI_DMA_TODEVICE) |
| 438 | prot |= HV_PCI_MAP_ATTR_WRITE; |
| 439 | |
| 440 | fill_sg(entry, devhandle, sglist, used, nelems, prot); |
| 441 | |
| 442 | return used; |
| 443 | |
| 444 | bad: |
| 445 | if (printk_ratelimit()) |
| 446 | WARN_ON(1); |
| 447 | return 0; |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static void pci_4v_unmap_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction) |
| 451 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 452 | struct pcidev_cookie *pcp; |
| 453 | struct pci_iommu *iommu; |
| 454 | unsigned long flags, i, npages, devhandle; |
| 455 | long entry; |
| 456 | u32 bus_addr; |
| 457 | |
| 458 | if (unlikely(direction == PCI_DMA_NONE)) { |
| 459 | if (printk_ratelimit()) |
| 460 | WARN_ON(1); |
| 461 | } |
| 462 | |
| 463 | pcp = pdev->sysdata; |
| 464 | iommu = pcp->pbm->iommu; |
| 465 | devhandle = pcp->pbm->devhandle; |
| 466 | |
| 467 | bus_addr = sglist->dma_address & IO_PAGE_MASK; |
| 468 | |
| 469 | for (i = 1; i < nelems; i++) |
| 470 | if (sglist[i].dma_length == 0) |
| 471 | break; |
| 472 | i--; |
| 473 | npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length) - |
| 474 | bus_addr) >> IO_PAGE_SHIFT; |
| 475 | |
| 476 | entry = ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT); |
| 477 | |
| 478 | spin_lock_irqsave(&iommu->lock, flags); |
| 479 | |
| 480 | pci_arena_free(&iommu->arena, entry, npages); |
| 481 | |
| 482 | do { |
| 483 | unsigned long num; |
| 484 | |
| 485 | num = pci_sun4v_iommu_demap(devhandle, HV_PCI_TSBID(0, entry), |
| 486 | npages); |
| 487 | entry += num; |
| 488 | npages -= num; |
| 489 | } while (npages != 0); |
| 490 | |
| 491 | spin_unlock_irqrestore(&iommu->lock, flags); |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static void pci_4v_dma_sync_single_for_cpu(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int direction) |
| 495 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 496 | /* Nothing to do... */ |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static void pci_4v_dma_sync_sg_for_cpu(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction) |
| 500 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 501 | /* Nothing to do... */ |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | struct pci_iommu_ops pci_sun4v_iommu_ops = { |
| 505 | .alloc_consistent = pci_4v_alloc_consistent, |
| 506 | .free_consistent = pci_4v_free_consistent, |
| 507 | .map_single = pci_4v_map_single, |
| 508 | .unmap_single = pci_4v_unmap_single, |
| 509 | .map_sg = pci_4v_map_sg, |
| 510 | .unmap_sg = pci_4v_unmap_sg, |
| 511 | .dma_sync_single_for_cpu = pci_4v_dma_sync_single_for_cpu, |
| 512 | .dma_sync_sg_for_cpu = pci_4v_dma_sync_sg_for_cpu, |
| 513 | }; |
| 514 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 515 | /* SUN4V PCI configuration space accessors. */ |
| 516 | |
David S. Miller | 059833e | 2006-02-12 23:49:18 -0800 | [diff] [blame^] | 517 | static inline int pci_sun4v_out_of_range(struct pci_pbm_info *pbm, unsigned int bus) |
| 518 | { |
| 519 | if (bus < pbm->pci_first_busno || |
| 520 | bus > pbm->pci_last_busno) |
| 521 | return 1; |
| 522 | return 0; |
| 523 | } |
| 524 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 525 | static int pci_sun4v_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn, |
| 526 | int where, int size, u32 *value) |
| 527 | { |
David S. Miller | 7eae642 | 2006-02-09 22:20:01 -0800 | [diff] [blame] | 528 | struct pci_pbm_info *pbm = bus_dev->sysdata; |
David S. Miller | 059833e | 2006-02-12 23:49:18 -0800 | [diff] [blame^] | 529 | u32 devhandle = pbm->devhandle; |
David S. Miller | 7eae642 | 2006-02-09 22:20:01 -0800 | [diff] [blame] | 530 | unsigned int bus = bus_dev->number; |
| 531 | unsigned int device = PCI_SLOT(devfn); |
| 532 | unsigned int func = PCI_FUNC(devfn); |
| 533 | unsigned long ret; |
| 534 | |
David S. Miller | 059833e | 2006-02-12 23:49:18 -0800 | [diff] [blame^] | 535 | if (pci_sun4v_out_of_range(pbm, bus)) { |
| 536 | ret = ~0UL; |
| 537 | } else { |
| 538 | ret = pci_sun4v_config_get(devhandle, |
| 539 | HV_PCI_DEVICE_BUILD(bus, device, func), |
| 540 | where, size); |
| 541 | } |
David S. Miller | 7eae642 | 2006-02-09 22:20:01 -0800 | [diff] [blame] | 542 | switch (size) { |
| 543 | case 1: |
| 544 | *value = ret & 0xff; |
| 545 | break; |
| 546 | case 2: |
| 547 | *value = ret & 0xffff; |
| 548 | break; |
| 549 | case 4: |
| 550 | *value = ret & 0xffffffff; |
| 551 | break; |
| 552 | }; |
| 553 | |
| 554 | |
| 555 | return PCIBIOS_SUCCESSFUL; |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static int pci_sun4v_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn, |
| 559 | int where, int size, u32 value) |
| 560 | { |
David S. Miller | 7eae642 | 2006-02-09 22:20:01 -0800 | [diff] [blame] | 561 | struct pci_pbm_info *pbm = bus_dev->sysdata; |
David S. Miller | 059833e | 2006-02-12 23:49:18 -0800 | [diff] [blame^] | 562 | u32 devhandle = pbm->devhandle; |
David S. Miller | 7eae642 | 2006-02-09 22:20:01 -0800 | [diff] [blame] | 563 | unsigned int bus = bus_dev->number; |
| 564 | unsigned int device = PCI_SLOT(devfn); |
| 565 | unsigned int func = PCI_FUNC(devfn); |
| 566 | unsigned long ret; |
| 567 | |
David S. Miller | 059833e | 2006-02-12 23:49:18 -0800 | [diff] [blame^] | 568 | if (pci_sun4v_out_of_range(pbm, bus)) { |
| 569 | /* Do nothing. */ |
| 570 | } else { |
| 571 | ret = pci_sun4v_config_put(devhandle, |
| 572 | HV_PCI_DEVICE_BUILD(bus, device, func), |
| 573 | where, size, value); |
| 574 | } |
David S. Miller | 7eae642 | 2006-02-09 22:20:01 -0800 | [diff] [blame] | 575 | return PCIBIOS_SUCCESSFUL; |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static struct pci_ops pci_sun4v_ops = { |
| 579 | .read = pci_sun4v_read_pci_cfg, |
| 580 | .write = pci_sun4v_write_pci_cfg, |
| 581 | }; |
| 582 | |
| 583 | |
David S. Miller | c260926 | 2006-02-12 22:18:52 -0800 | [diff] [blame] | 584 | static void pbm_scan_bus(struct pci_controller_info *p, |
| 585 | struct pci_pbm_info *pbm) |
| 586 | { |
| 587 | struct pcidev_cookie *cookie = kmalloc(sizeof(*cookie), GFP_KERNEL); |
| 588 | |
| 589 | if (!cookie) { |
| 590 | prom_printf("%s: Critical allocation failure.\n", pbm->name); |
| 591 | prom_halt(); |
| 592 | } |
| 593 | |
| 594 | /* All we care about is the PBM. */ |
| 595 | memset(cookie, 0, sizeof(*cookie)); |
| 596 | cookie->pbm = pbm; |
| 597 | |
| 598 | pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno, |
| 599 | p->pci_ops, |
| 600 | pbm); |
| 601 | pci_fixup_host_bridge_self(pbm->pci_bus); |
| 602 | pbm->pci_bus->self->sysdata = cookie; |
| 603 | |
| 604 | pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node); |
| 605 | pci_record_assignments(pbm, pbm->pci_bus); |
| 606 | pci_assign_unassigned(pbm, pbm->pci_bus); |
| 607 | pci_fixup_irq(pbm, pbm->pci_bus); |
| 608 | pci_determine_66mhz_disposition(pbm, pbm->pci_bus); |
| 609 | pci_setup_busmastering(pbm, pbm->pci_bus); |
| 610 | } |
| 611 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 612 | static void pci_sun4v_scan_bus(struct pci_controller_info *p) |
| 613 | { |
David S. Miller | c260926 | 2006-02-12 22:18:52 -0800 | [diff] [blame] | 614 | if (p->pbm_A.prom_node) { |
| 615 | p->pbm_A.is_66mhz_capable = |
| 616 | prom_getbool(p->pbm_A.prom_node, "66mhz-capable"); |
| 617 | |
| 618 | pbm_scan_bus(p, &p->pbm_A); |
| 619 | } |
| 620 | if (p->pbm_B.prom_node) { |
| 621 | p->pbm_B.is_66mhz_capable = |
| 622 | prom_getbool(p->pbm_B.prom_node, "66mhz-capable"); |
| 623 | |
| 624 | pbm_scan_bus(p, &p->pbm_B); |
| 625 | } |
| 626 | |
| 627 | /* XXX register error interrupt handlers XXX */ |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static unsigned int pci_sun4v_irq_build(struct pci_pbm_info *pbm, |
| 631 | struct pci_dev *pdev, |
| 632 | unsigned int ino) |
| 633 | { |
| 634 | /* XXX Implement me! XXX */ |
| 635 | return 0; |
| 636 | } |
| 637 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 638 | static void pci_sun4v_base_address_update(struct pci_dev *pdev, int resource) |
| 639 | { |
| 640 | struct pcidev_cookie *pcp = pdev->sysdata; |
| 641 | struct pci_pbm_info *pbm = pcp->pbm; |
| 642 | struct resource *res, *root; |
| 643 | u32 reg; |
| 644 | int where, size, is_64bit; |
| 645 | |
| 646 | res = &pdev->resource[resource]; |
| 647 | if (resource < 6) { |
| 648 | where = PCI_BASE_ADDRESS_0 + (resource * 4); |
| 649 | } else if (resource == PCI_ROM_RESOURCE) { |
| 650 | where = pdev->rom_base_reg; |
| 651 | } else { |
| 652 | /* Somebody might have asked allocation of a non-standard resource */ |
| 653 | return; |
| 654 | } |
| 655 | |
David S. Miller | c260926 | 2006-02-12 22:18:52 -0800 | [diff] [blame] | 656 | /* XXX 64-bit MEM handling is not %100 correct... XXX */ |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 657 | is_64bit = 0; |
| 658 | if (res->flags & IORESOURCE_IO) |
| 659 | root = &pbm->io_space; |
| 660 | else { |
| 661 | root = &pbm->mem_space; |
| 662 | if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK) |
| 663 | == PCI_BASE_ADDRESS_MEM_TYPE_64) |
| 664 | is_64bit = 1; |
| 665 | } |
| 666 | |
| 667 | size = res->end - res->start; |
| 668 | pci_read_config_dword(pdev, where, ®); |
| 669 | reg = ((reg & size) | |
| 670 | (((u32)(res->start - root->start)) & ~size)); |
| 671 | if (resource == PCI_ROM_RESOURCE) { |
| 672 | reg |= PCI_ROM_ADDRESS_ENABLE; |
| 673 | res->flags |= IORESOURCE_ROM_ENABLE; |
| 674 | } |
| 675 | pci_write_config_dword(pdev, where, reg); |
| 676 | |
| 677 | /* This knows that the upper 32-bits of the address |
| 678 | * must be zero. Our PCI common layer enforces this. |
| 679 | */ |
| 680 | if (is_64bit) |
| 681 | pci_write_config_dword(pdev, where + 4, 0); |
| 682 | } |
| 683 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 684 | static void pci_sun4v_resource_adjust(struct pci_dev *pdev, |
| 685 | struct resource *res, |
| 686 | struct resource *root) |
| 687 | { |
| 688 | res->start += root->start; |
| 689 | res->end += root->start; |
| 690 | } |
| 691 | |
| 692 | /* Use ranges property to determine where PCI MEM, I/O, and Config |
| 693 | * space are for this PCI bus module. |
| 694 | */ |
| 695 | static void pci_sun4v_determine_mem_io_space(struct pci_pbm_info *pbm) |
| 696 | { |
David S. Miller | 221b2fb | 2006-02-11 23:38:00 -0800 | [diff] [blame] | 697 | int i, saw_mem, saw_io; |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 698 | |
David S. Miller | 221b2fb | 2006-02-11 23:38:00 -0800 | [diff] [blame] | 699 | saw_mem = saw_io = 0; |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 700 | for (i = 0; i < pbm->num_pbm_ranges; i++) { |
| 701 | struct linux_prom_pci_ranges *pr = &pbm->pbm_ranges[i]; |
| 702 | unsigned long a; |
| 703 | int type; |
| 704 | |
| 705 | type = (pr->child_phys_hi >> 24) & 0x3; |
| 706 | a = (((unsigned long)pr->parent_phys_hi << 32UL) | |
| 707 | ((unsigned long)pr->parent_phys_lo << 0UL)); |
| 708 | |
| 709 | switch (type) { |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 710 | case 1: |
| 711 | /* 16-bit IO space, 16MB */ |
| 712 | pbm->io_space.start = a; |
| 713 | pbm->io_space.end = a + ((16UL*1024UL*1024UL) - 1UL); |
| 714 | pbm->io_space.flags = IORESOURCE_IO; |
| 715 | saw_io = 1; |
| 716 | break; |
| 717 | |
| 718 | case 2: |
| 719 | /* 32-bit MEM space, 2GB */ |
| 720 | pbm->mem_space.start = a; |
| 721 | pbm->mem_space.end = a + (0x80000000UL - 1UL); |
| 722 | pbm->mem_space.flags = IORESOURCE_MEM; |
| 723 | saw_mem = 1; |
| 724 | break; |
| 725 | |
David S. Miller | c260926 | 2006-02-12 22:18:52 -0800 | [diff] [blame] | 726 | case 3: |
| 727 | /* XXX 64-bit MEM handling XXX */ |
| 728 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 729 | default: |
| 730 | break; |
| 731 | }; |
| 732 | } |
| 733 | |
David S. Miller | 221b2fb | 2006-02-11 23:38:00 -0800 | [diff] [blame] | 734 | if (!saw_io || !saw_mem) { |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 735 | prom_printf("%s: Fatal error, missing %s PBM range.\n", |
| 736 | pbm->name, |
David S. Miller | 221b2fb | 2006-02-11 23:38:00 -0800 | [diff] [blame] | 737 | (!saw_io ? "IO" : "MEM")); |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 738 | prom_halt(); |
| 739 | } |
| 740 | |
David S. Miller | 221b2fb | 2006-02-11 23:38:00 -0800 | [diff] [blame] | 741 | printk("%s: PCI IO[%lx] MEM[%lx]\n", |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 742 | pbm->name, |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 743 | pbm->io_space.start, |
| 744 | pbm->mem_space.start); |
| 745 | } |
| 746 | |
| 747 | static void pbm_register_toplevel_resources(struct pci_controller_info *p, |
| 748 | struct pci_pbm_info *pbm) |
| 749 | { |
| 750 | pbm->io_space.name = pbm->mem_space.name = pbm->name; |
| 751 | |
| 752 | request_resource(&ioport_resource, &pbm->io_space); |
| 753 | request_resource(&iomem_resource, &pbm->mem_space); |
| 754 | pci_register_legacy_regions(&pbm->io_space, |
| 755 | &pbm->mem_space); |
| 756 | } |
| 757 | |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 758 | static void probe_existing_entries(struct pci_pbm_info *pbm, |
| 759 | struct pci_iommu *iommu) |
| 760 | { |
| 761 | struct pci_iommu_arena *arena = &iommu->arena; |
| 762 | unsigned long i, devhandle; |
| 763 | |
| 764 | devhandle = pbm->devhandle; |
| 765 | for (i = 0; i < arena->limit; i++) { |
| 766 | unsigned long ret, io_attrs, ra; |
| 767 | |
| 768 | ret = pci_sun4v_iommu_getmap(devhandle, |
| 769 | HV_PCI_TSBID(0, i), |
| 770 | &io_attrs, &ra); |
| 771 | if (ret == HV_EOK) |
| 772 | __set_bit(i, arena->map); |
| 773 | } |
| 774 | } |
| 775 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 776 | static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm) |
| 777 | { |
David S. Miller | 1839794 | 2006-02-10 00:08:26 -0800 | [diff] [blame] | 778 | struct pci_iommu *iommu = pbm->iommu; |
| 779 | unsigned long num_tsb_entries, sz; |
| 780 | u32 vdma[2], dma_mask, dma_offset; |
| 781 | int err, tsbsize; |
| 782 | |
| 783 | err = prom_getproperty(pbm->prom_node, "virtual-dma", |
| 784 | (char *)&vdma[0], sizeof(vdma)); |
| 785 | if (err == 0 || err == -1) { |
| 786 | /* No property, use default values. */ |
| 787 | vdma[0] = 0x80000000; |
| 788 | vdma[1] = 0x80000000; |
| 789 | } |
| 790 | |
| 791 | dma_mask = vdma[0]; |
| 792 | switch (vdma[1]) { |
| 793 | case 0x20000000: |
| 794 | dma_mask |= 0x1fffffff; |
| 795 | tsbsize = 64; |
| 796 | break; |
| 797 | |
| 798 | case 0x40000000: |
| 799 | dma_mask |= 0x3fffffff; |
| 800 | tsbsize = 128; |
| 801 | break; |
| 802 | |
| 803 | case 0x80000000: |
| 804 | dma_mask |= 0x7fffffff; |
| 805 | tsbsize = 128; |
| 806 | break; |
| 807 | |
| 808 | default: |
| 809 | prom_printf("PCI-SUN4V: strange virtual-dma size.\n"); |
| 810 | prom_halt(); |
| 811 | }; |
| 812 | |
| 813 | num_tsb_entries = tsbsize / sizeof(iopte_t); |
| 814 | |
| 815 | dma_offset = vdma[0]; |
| 816 | |
| 817 | /* Setup initial software IOMMU state. */ |
| 818 | spin_lock_init(&iommu->lock); |
| 819 | iommu->ctx_lowest_free = 1; |
| 820 | iommu->page_table_map_base = dma_offset; |
| 821 | iommu->dma_addr_mask = dma_mask; |
| 822 | |
| 823 | /* Allocate and initialize the free area map. */ |
| 824 | sz = num_tsb_entries / 8; |
| 825 | sz = (sz + 7UL) & ~7UL; |
| 826 | iommu->arena.map = kmalloc(sz, GFP_KERNEL); |
| 827 | if (!iommu->arena.map) { |
| 828 | prom_printf("PCI_IOMMU: Error, kmalloc(arena.map) failed.\n"); |
| 829 | prom_halt(); |
| 830 | } |
| 831 | memset(iommu->arena.map, 0, sz); |
| 832 | iommu->arena.limit = num_tsb_entries; |
| 833 | |
| 834 | probe_existing_entries(pbm, iommu); |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 835 | } |
| 836 | |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 837 | static void pci_sun4v_pbm_init(struct pci_controller_info *p, int prom_node, unsigned int devhandle) |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 838 | { |
| 839 | struct pci_pbm_info *pbm; |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 840 | unsigned int busrange[2]; |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 841 | int err, i; |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 842 | |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 843 | if (devhandle & 0x40) |
| 844 | pbm = &p->pbm_B; |
| 845 | else |
| 846 | pbm = &p->pbm_A; |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 847 | |
| 848 | pbm->parent = p; |
| 849 | pbm->prom_node = prom_node; |
| 850 | pbm->pci_first_slot = 1; |
| 851 | |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 852 | pbm->devhandle = devhandle; |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 853 | |
| 854 | sprintf(pbm->name, "SUN4V-PCI%d PBM%c", |
| 855 | p->index, (pbm == &p->pbm_A ? 'A' : 'B')); |
| 856 | |
| 857 | printk("%s: devhandle[%x]\n", pbm->name, pbm->devhandle); |
| 858 | |
| 859 | prom_getstring(prom_node, "name", |
| 860 | pbm->prom_name, sizeof(pbm->prom_name)); |
| 861 | |
| 862 | err = prom_getproperty(prom_node, "ranges", |
| 863 | (char *) pbm->pbm_ranges, |
| 864 | sizeof(pbm->pbm_ranges)); |
| 865 | if (err == 0 || err == -1) { |
| 866 | prom_printf("%s: Fatal error, no ranges property.\n", |
| 867 | pbm->name); |
| 868 | prom_halt(); |
| 869 | } |
| 870 | |
| 871 | pbm->num_pbm_ranges = |
| 872 | (err / sizeof(struct linux_prom_pci_ranges)); |
| 873 | |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 874 | /* Mask out the top 8 bits of the ranges, leaving the real |
| 875 | * physical address. |
| 876 | */ |
| 877 | for (i = 0; i < pbm->num_pbm_ranges; i++) |
| 878 | pbm->pbm_ranges[i].parent_phys_hi &= 0x0fffffff; |
| 879 | |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 880 | pci_sun4v_determine_mem_io_space(pbm); |
| 881 | pbm_register_toplevel_resources(p, pbm); |
| 882 | |
| 883 | err = prom_getproperty(prom_node, "interrupt-map", |
| 884 | (char *)pbm->pbm_intmap, |
| 885 | sizeof(pbm->pbm_intmap)); |
| 886 | if (err != -1) { |
| 887 | pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap)); |
| 888 | err = prom_getproperty(prom_node, "interrupt-map-mask", |
| 889 | (char *)&pbm->pbm_intmask, |
| 890 | sizeof(pbm->pbm_intmask)); |
| 891 | if (err == -1) { |
| 892 | prom_printf("%s: Fatal error, no " |
| 893 | "interrupt-map-mask.\n", pbm->name); |
| 894 | prom_halt(); |
| 895 | } |
| 896 | } else { |
| 897 | pbm->num_pbm_intmap = 0; |
| 898 | memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask)); |
| 899 | } |
| 900 | |
| 901 | err = prom_getproperty(prom_node, "bus-range", |
| 902 | (char *)&busrange[0], |
| 903 | sizeof(busrange)); |
| 904 | if (err == 0 || err == -1) { |
| 905 | prom_printf("%s: Fatal error, no bus-range.\n", pbm->name); |
| 906 | prom_halt(); |
| 907 | } |
| 908 | pbm->pci_first_busno = busrange[0]; |
| 909 | pbm->pci_last_busno = busrange[1]; |
| 910 | |
| 911 | pci_sun4v_iommu_init(pbm); |
| 912 | } |
| 913 | |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 914 | void sun4v_pci_init(int node, char *model_name) |
| 915 | { |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 916 | struct pci_controller_info *p; |
| 917 | struct pci_iommu *iommu; |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 918 | struct linux_prom64_registers regs; |
| 919 | unsigned int devhandle; |
| 920 | |
| 921 | prom_getproperty(node, "reg", (char *)®s, sizeof(regs)); |
| 922 | devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff;; |
| 923 | |
| 924 | for (p = pci_controller_root; p; p = p->next) { |
| 925 | struct pci_pbm_info *pbm; |
| 926 | |
| 927 | if (p->pbm_A.prom_node && p->pbm_B.prom_node) |
| 928 | continue; |
| 929 | |
| 930 | pbm = (p->pbm_A.prom_node ? |
| 931 | &p->pbm_A : |
| 932 | &p->pbm_B); |
| 933 | |
David S. Miller | 0b52249 | 2006-02-12 22:29:36 -0800 | [diff] [blame] | 934 | if (pbm->devhandle == (devhandle ^ 0x40)) { |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 935 | pci_sun4v_pbm_init(p, node, devhandle); |
David S. Miller | 0b52249 | 2006-02-12 22:29:36 -0800 | [diff] [blame] | 936 | return; |
| 937 | } |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 938 | } |
David S. Miller | bade562 | 2006-02-09 22:05:54 -0800 | [diff] [blame] | 939 | |
| 940 | p = kmalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); |
| 941 | if (!p) { |
| 942 | prom_printf("SUN4V_PCI: Fatal memory allocation error.\n"); |
| 943 | prom_halt(); |
| 944 | } |
| 945 | memset(p, 0, sizeof(*p)); |
| 946 | |
| 947 | iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC); |
| 948 | if (!iommu) { |
| 949 | prom_printf("SCHIZO: Fatal memory allocation error.\n"); |
| 950 | prom_halt(); |
| 951 | } |
| 952 | memset(iommu, 0, sizeof(*iommu)); |
| 953 | p->pbm_A.iommu = iommu; |
| 954 | |
| 955 | iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC); |
| 956 | if (!iommu) { |
| 957 | prom_printf("SCHIZO: Fatal memory allocation error.\n"); |
| 958 | prom_halt(); |
| 959 | } |
| 960 | memset(iommu, 0, sizeof(*iommu)); |
| 961 | p->pbm_B.iommu = iommu; |
| 962 | |
| 963 | p->next = pci_controller_root; |
| 964 | pci_controller_root = p; |
| 965 | |
| 966 | p->index = pci_num_controllers++; |
| 967 | p->pbms_same_domain = 0; |
| 968 | |
| 969 | p->scan_bus = pci_sun4v_scan_bus; |
| 970 | p->irq_build = pci_sun4v_irq_build; |
| 971 | p->base_address_update = pci_sun4v_base_address_update; |
| 972 | p->resource_adjust = pci_sun4v_resource_adjust; |
| 973 | p->pci_ops = &pci_sun4v_ops; |
| 974 | |
| 975 | /* Like PSYCHO and SCHIZO we have a 2GB aligned area |
| 976 | * for memory space. |
| 977 | */ |
| 978 | pci_memspace_mask = 0x7fffffffUL; |
| 979 | |
David S. Miller | 3833789 | 2006-02-12 22:06:53 -0800 | [diff] [blame] | 980 | pci_sun4v_pbm_init(p, node, devhandle); |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 981 | } |