Lines Matching refs:ioc

172 struct ioc {  struct
201 struct ioc *next; /* list of IOC's in system */ argument
211 static struct ioc *ioc_list; argument
226 # define GET_IOC(dev) ((struct ioc *) PCI_CONTROLLER(dev)->iommu)
284 sba_dump_pdir_entry(struct ioc *ioc, char *msg, uint pide) in sba_dump_pdir_entry() argument
287 u64 *ptr = &ioc->pdir_base[pide & ~(BITS_PER_LONG - 1)]; in sba_dump_pdir_entry()
288 unsigned long *rptr = (unsigned long *) &ioc->res_map[(pide >>3) & -sizeof(unsigned long)]; in sba_dump_pdir_entry()
315 sba_check_pdir(struct ioc *ioc, char *msg) in sba_check_pdir() argument
317 u64 *rptr_end = (u64 *) &(ioc->res_map[ioc->res_size]); in sba_check_pdir()
318 u64 *rptr = (u64 *) ioc->res_map; /* resource map ptr */ in sba_check_pdir()
319 u64 *pptr = ioc->pdir_base; /* pdir ptr */ in sba_check_pdir()
338 sba_dump_pdir_entry(ioc, msg, pide); in sba_check_pdir()
362 sba_dump_sg( struct ioc *ioc, struct scatterlist *startsg, int nents) in sba_dump_sg() argument
373 sba_check_sg( struct ioc *ioc, struct scatterlist *startsg, int nents) in sba_check_sg() argument
402 #define SBA_IOVA(ioc,iovp,offset,hint_reg) ((ioc->ibase) | (iovp) | (offset)) argument
403 #define SBA_IOVP(ioc,iova) ((iova) & ~(ioc->ibase)) argument
442 sba_search_bitmap(struct ioc *ioc, unsigned long bits_wanted) in sba_search_bitmap() argument
444 unsigned long *res_ptr = ioc->res_hint; in sba_search_bitmap()
445 unsigned long *res_end = (unsigned long *) &(ioc->res_map[ioc->res_size]); in sba_search_bitmap()
448 ASSERT(((unsigned long) ioc->res_hint & (sizeof(unsigned long) - 1UL)) == 0); in sba_search_bitmap()
463 pide = ((unsigned long)res_ptr - (unsigned long)ioc->res_map); in sba_search_bitmap()
470 ioc->res_bitshift = 0; in sba_search_bitmap()
479 uint bitshiftcnt = ROUNDUP(ioc->res_bitshift, o); in sba_search_bitmap()
495 pide = ((unsigned long)res_ptr - (unsigned long)ioc->res_map); in sba_search_bitmap()
509 ioc->res_bitshift = bitshiftcnt + bits_wanted; in sba_search_bitmap()
514 ioc->res_hint = (unsigned long *) ioc->res_map; in sba_search_bitmap()
515 ioc->res_bitshift = 0; in sba_search_bitmap()
517 ioc->res_hint = res_ptr; in sba_search_bitmap()
532 sba_alloc_range(struct ioc *ioc, size_t size) in sba_alloc_range() argument
548 pide = sba_search_bitmap(ioc, pages_needed); in sba_alloc_range()
549 if (pide >= (ioc->res_size << 3)) { in sba_alloc_range()
550 pide = sba_search_bitmap(ioc, pages_needed); in sba_alloc_range()
551 if (pide >= (ioc->res_size << 3)) in sba_alloc_range()
553 ioc->ioc_hpa); in sba_alloc_range()
558 if(0x00 != ((u8 *) ioc->pdir_base)[pide*PDIR_ENTRY_SIZE + 7]) { in sba_alloc_range()
559 sba_dump_pdir_entry(ioc, "sba_search_bitmap() botched it?", pide); in sba_alloc_range()
565 (uint) ((unsigned long) ioc->res_hint - (unsigned long) ioc->res_map), in sba_alloc_range()
566 ioc->res_bitshift ); in sba_alloc_range()
569 ioc->avg_search[ioc->avg_idx++] = ia64_get_itc() - itc_start; in sba_alloc_range()
570 ioc->avg_idx &= SBA_SEARCH_SAMPLE - 1; in sba_alloc_range()
586 sba_free_range(struct ioc *ioc, dma_addr_t iova, size_t size) in sba_free_range() argument
588 unsigned long iovp = SBA_IOVP(ioc, iova); in sba_free_range()
591 unsigned long *res_ptr = (unsigned long *) &((ioc)->res_map[ridx & ~RESMAP_IDX_MASK]); in sba_free_range()
618 #define SBA_DMA_HINT(ioc, val) ((val) << (ioc)->hint_shift_pdir) argument
695 sba_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt) in sba_mark_invalid() argument
697 u32 iovp = (u32) SBA_IOVP(ioc,iova); in sba_mark_invalid()
707 if (!(ioc->pdir_base[off] >> 60)) { in sba_mark_invalid()
708 sba_dump_pdir_entry(ioc,"sba_mark_invalid()", PDIR_INDEX(iovp)); in sba_mark_invalid()
714 ASSERT(off < ioc->pdir_size); in sba_mark_invalid()
725 ioc->pdir_base[off] &= ~(0x80000000000000FFULL); in sba_mark_invalid()
732 ioc->pdir_base[off] = (0x80000000000000FFULL | prefetch_spill_page); in sba_mark_invalid()
742 ASSERT(ioc->pdir_base[off] >> 63); in sba_mark_invalid()
745 ioc->pdir_base[off] &= ~(0x80000000000000FFULL); in sba_mark_invalid()
747 ioc->pdir_base[off] = (0x80000000000000FFULL | prefetch_spill_page); in sba_mark_invalid()
754 WRITE_REG(iovp | ioc->ibase, ioc->ioc_hpa+IOC_PCOM); in sba_mark_invalid()
769 struct ioc *ioc; in sba_map_single() local
779 ioc = GET_IOC(dev); in sba_map_single()
780 ASSERT(ioc); in sba_map_single()
806 spin_lock_irqsave(&ioc->res_lock, flags); in sba_map_single()
808 if (sba_check_pdir(ioc,"Check before sba_map_single()")) in sba_map_single()
812 pide = sba_alloc_range(ioc, size); in sba_map_single()
818 pdir_start = &(ioc->pdir_base[pide]); in sba_map_single()
835 sba_check_pdir(ioc,"Check after sba_map_single()"); in sba_map_single()
837 spin_unlock_irqrestore(&ioc->res_lock, flags); in sba_map_single()
838 return SBA_IOVA(ioc, iovp, offset, DEFAULT_DMA_HINT_REG); in sba_map_single()
852 struct ioc *ioc; in sba_unmap_single() local
859 ioc = GET_IOC(dev); in sba_unmap_single()
860 ASSERT(ioc); in sba_unmap_single()
863 if ((iova & ioc->imask) != ioc->ibase) { in sba_unmap_single()
886 spin_lock_irqsave(&ioc->res_lock, flags); in sba_unmap_single()
889 d = &(ioc->saved[ioc->saved_cnt]); in sba_unmap_single()
892 if (++(ioc->saved_cnt) >= DELAYED_RESOURCE_CNT) { in sba_unmap_single()
893 int cnt = ioc->saved_cnt; in sba_unmap_single()
895 sba_mark_invalid(ioc, d->iova, d->size); in sba_unmap_single()
896 sba_free_range(ioc, d->iova, d->size); in sba_unmap_single()
899 ioc->saved_cnt = 0; in sba_unmap_single()
900 READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */ in sba_unmap_single()
903 sba_mark_invalid(ioc, iova, size); in sba_unmap_single()
904 sba_free_range(ioc, iova, size); in sba_unmap_single()
905 READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */ in sba_unmap_single()
909 u32 iovp = (u32) SBA_IOVP(ioc,iova); in sba_unmap_single()
914 addr = phys_to_virt(ioc->pdir_base[off] & in sba_unmap_single()
921 addr = phys_to_virt(ioc->pdir_base[off] & in sba_unmap_single()
931 spin_unlock_irqrestore(&ioc->res_lock, flags); in sba_unmap_single()
955 struct ioc *ioc; in sba_alloc_coherent() local
969 ioc = GET_IOC(dev); in sba_alloc_coherent()
970 ASSERT(ioc); in sba_alloc_coherent()
971 *dma_handle = sba_map_single(ioc->sac_only_dev, addr, size, 0); in sba_alloc_coherent()
1018 struct ioc *ioc, in sba_fill_pdir() argument
1050 dma_sg->dma_address = pide | ioc->ibase; in sba_fill_pdir()
1051 pdirp = &(ioc->pdir_base[pide >> iovp_shift]); in sba_fill_pdir()
1113 sba_coalesce_chunks( struct ioc *ioc, in sba_coalesce_chunks() argument
1219 | (sba_alloc_range(ioc, dma_len) << iovp_shift) in sba_coalesce_chunks()
1239 struct ioc *ioc; in sba_map_sg() local
1247 ioc = GET_IOC(dev); in sba_map_sg()
1248 ASSERT(ioc); in sba_map_sg()
1251 if (dev->dma_mask >= ioc->dma_mask) { in sba_map_sg()
1267 spin_lock_irqsave(&ioc->res_lock, flags); in sba_map_sg()
1270 if (sba_check_pdir(ioc,"Check before sba_map_sg()")) in sba_map_sg()
1272 sba_dump_sg(ioc, sglist, nents); in sba_map_sg()
1285 coalesced = sba_coalesce_chunks(ioc, sglist, nents); in sba_map_sg()
1295 filled = sba_fill_pdir(ioc, sglist, nents); in sba_map_sg()
1298 if (sba_check_pdir(ioc,"Check after sba_map_sg()")) in sba_map_sg()
1300 sba_dump_sg(ioc, sglist, nents); in sba_map_sg()
1305 spin_unlock_irqrestore(&ioc->res_lock, flags); in sba_map_sg()
1325 struct ioc *ioc; in sba_unmap_sg() local
1333 ioc = GET_IOC(dev); in sba_unmap_sg()
1334 ASSERT(ioc); in sba_unmap_sg()
1337 spin_lock_irqsave(&ioc->res_lock, flags); in sba_unmap_sg()
1338 sba_check_pdir(ioc,"Check before sba_unmap_sg()"); in sba_unmap_sg()
1339 spin_unlock_irqrestore(&ioc->res_lock, flags); in sba_unmap_sg()
1352 spin_lock_irqsave(&ioc->res_lock, flags); in sba_unmap_sg()
1353 sba_check_pdir(ioc,"Check after sba_unmap_sg()"); in sba_unmap_sg()
1354 spin_unlock_irqrestore(&ioc->res_lock, flags); in sba_unmap_sg()
1366 ioc_iova_init(struct ioc *ioc) in ioc_iova_init() argument
1380 ioc->ibase = READ_REG(ioc->ioc_hpa + IOC_IBASE) & ~0x1UL; in ioc_iova_init()
1381 ioc->imask = READ_REG(ioc->ioc_hpa + IOC_IMASK) | 0xFFFFFFFF00000000UL; in ioc_iova_init()
1383 ioc->iov_size = ~ioc->imask + 1; in ioc_iova_init()
1386 __FUNCTION__, ioc->ioc_hpa, ioc->ibase, ioc->imask, in ioc_iova_init()
1387 ioc->iov_size >> 20); in ioc_iova_init()
1399 WRITE_REG(tcnfg, ioc->ioc_hpa + IOC_TCNFG); in ioc_iova_init()
1401 ioc->pdir_size = (ioc->iov_size / iovp_size) * PDIR_ENTRY_SIZE; in ioc_iova_init()
1402 ioc->pdir_base = (void *) __get_free_pages(GFP_KERNEL, in ioc_iova_init()
1403 get_order(ioc->pdir_size)); in ioc_iova_init()
1404 if (!ioc->pdir_base) in ioc_iova_init()
1407 memset(ioc->pdir_base, 0, ioc->pdir_size); in ioc_iova_init()
1410 iovp_size >> 10, ioc->pdir_base, ioc->pdir_size); in ioc_iova_init()
1412 ASSERT(ALIGN((unsigned long) ioc->pdir_base, 4*1024) == (unsigned long) ioc->pdir_base); in ioc_iova_init()
1413 WRITE_REG(virt_to_phys(ioc->pdir_base), ioc->ioc_hpa + IOC_PDIR_BASE); in ioc_iova_init()
1428 ioc->iov_size/2 >> 20, ioc->ibase + ioc->iov_size/2); in ioc_iova_init()
1429 ioc->pdir_size /= 2; in ioc_iova_init()
1430 ((u64 *)ioc->pdir_base)[PDIR_INDEX(ioc->iov_size/2)] = ZX1_SBA_IOMMU_COOKIE; in ioc_iova_init()
1457 for (index = 0 ; index < (ioc->pdir_size / PDIR_ENTRY_SIZE) ; index++) in ioc_iova_init()
1458 ((u64 *)ioc->pdir_base)[index] = (0x80000000000000FF | prefetch_spill_page); in ioc_iova_init()
1462 WRITE_REG(ioc->ibase | (get_iovp_order(ioc->iov_size) + iovp_shift), ioc->ioc_hpa + IOC_PCOM); in ioc_iova_init()
1463 READ_REG(ioc->ioc_hpa + IOC_PCOM); in ioc_iova_init()
1466 WRITE_REG(ioc->ibase | 1, ioc->ioc_hpa + IOC_IBASE); in ioc_iova_init()
1467 READ_REG(ioc->ioc_hpa + IOC_IBASE); in ioc_iova_init()
1471 ioc_resource_init(struct ioc *ioc) in ioc_resource_init() argument
1473 spin_lock_init(&ioc->res_lock); in ioc_resource_init()
1476 ioc->res_size = ioc->pdir_size / PDIR_ENTRY_SIZE; /* entries */ in ioc_resource_init()
1477 ioc->res_size >>= 3; /* convert bit count to byte count */ in ioc_resource_init()
1478 DBG_INIT("%s() res_size 0x%x\n", __FUNCTION__, ioc->res_size); in ioc_resource_init()
1480 ioc->res_map = (char *) __get_free_pages(GFP_KERNEL, in ioc_resource_init()
1481 get_order(ioc->res_size)); in ioc_resource_init()
1482 if (!ioc->res_map) in ioc_resource_init()
1485 memset(ioc->res_map, 0, ioc->res_size); in ioc_resource_init()
1487 ioc->res_hint = (unsigned long *) ioc->res_map; in ioc_resource_init()
1491 ioc->res_map[0] = 0x1; in ioc_resource_init()
1492 ioc->pdir_base[0] = 0x8000000000000000ULL | ZX1_SBA_IOMMU_COOKIE; in ioc_resource_init()
1496 ioc->res_map[ioc->res_size - 1] |= 0x80UL; /* res_map is chars */ in ioc_resource_init()
1497 ioc->pdir_base[(ioc->pdir_size / PDIR_ENTRY_SIZE) - 1] = (0x80000000000000FF in ioc_resource_init()
1502 ioc->res_size, (void *) ioc->res_map); in ioc_resource_init()
1506 ioc_sac_init(struct ioc *ioc) in ioc_sac_init() argument
1526 controller->iommu = ioc; in ioc_sac_init()
1529 ioc->sac_only_dev = sac; in ioc_sac_init()
1533 ioc_zx1_init(struct ioc *ioc) in ioc_zx1_init() argument
1535 if (ioc->rev < 0x20) in ioc_zx1_init()
1538 ioc->dma_mask = 0xFFFFFFFFFFUL; in ioc_zx1_init()
1549 ioc_sx1000_init(struct ioc *ioc) in ioc_sx1000_init() argument
1558 typedef void (initfunc)(struct ioc *);
1572 static struct ioc * __init
1575 struct ioc *ioc; in ioc_init() local
1578 ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); in ioc_init()
1579 if (!ioc) in ioc_init()
1582 memset(ioc, 0, sizeof(*ioc)); in ioc_init()
1584 ioc->next = ioc_list; in ioc_init()
1585 ioc_list = ioc; in ioc_init()
1587 ioc->handle = handle; in ioc_init()
1588 ioc->ioc_hpa = ioremap(hpa, 0x1000); in ioc_init()
1590 ioc->func_id = READ_REG(ioc->ioc_hpa + IOC_FUNC_ID); in ioc_init()
1591 ioc->rev = READ_REG(ioc->ioc_hpa + IOC_FCLASS) & 0xFFUL; in ioc_init()
1592 ioc->dma_mask = 0xFFFFFFFFFFFFFFFFUL; /* conservative */ in ioc_init()
1600 if (ioc->func_id == info->func_id) { in ioc_init()
1601 ioc->name = info->name; in ioc_init()
1603 (info->init)(ioc); in ioc_init()
1609 if (!ioc->name) { in ioc_init()
1610 ioc->name = kmalloc(24, GFP_KERNEL); in ioc_init()
1611 if (ioc->name) in ioc_init()
1612 sprintf((char *) ioc->name, "Unknown (%04x:%04x)", in ioc_init()
1613 ioc->func_id & 0xFFFF, (ioc->func_id >> 16) & 0xFFFF); in ioc_init()
1615 ioc->name = "Unknown"; in ioc_init()
1618 ioc_iova_init(ioc); in ioc_init()
1619 ioc_resource_init(ioc); in ioc_init()
1620 ioc_sac_init(ioc); in ioc_init()
1624 ioc->name, (ioc->rev >> 4) & 0xF, ioc->rev & 0xF, in ioc_init()
1625 hpa, ioc->iov_size >> 20, ioc->ibase); in ioc_init()
1627 return ioc; in ioc_init()
1645 struct ioc *ioc; in ioc_start() local
1648 for (ioc = ioc_list; ioc; ioc = ioc->next) in ioc_start()
1650 return ioc; in ioc_start()
1658 struct ioc *ioc = v; in ioc_next() local
1661 return ioc->next; in ioc_next()
1672 struct ioc *ioc = v; in ioc_show() local
1673 unsigned long *res_ptr = (unsigned long *)ioc->res_map; in ioc_show()
1677 ioc->name, ((ioc->rev >> 4) & 0xF), (ioc->rev & 0xF)); in ioc_show()
1678 seq_printf(s, "IOVA size : %d MB\n", ioc->iov_size/(1024*1024)); in ioc_show()
1681 for (i = 0; i < (ioc->res_size / sizeof(unsigned long)); ++i, ++res_ptr) in ioc_show()
1684 seq_printf(s, "PDIR size : %d entries\n", ioc->res_size << 3); in ioc_show()
1690 min = max = ioc->avg_search[0]; in ioc_show()
1692 avg += ioc->avg_search[i]; in ioc_show()
1693 if (ioc->avg_search[i] > max) max = ioc->avg_search[i]; in ioc_show()
1694 if (ioc->avg_search[i] < min) min = ioc->avg_search[i]; in ioc_show()
1747 struct ioc *ioc; in sba_connect_bus() local
1765 for (ioc = ioc_list; ioc; ioc = ioc->next) in sba_connect_bus()
1766 if (ioc->handle == handle) { in sba_connect_bus()
1767 PCI_CONTROLLER(bus)->iommu = ioc; in sba_connect_bus()
1783 struct ioc *ioc; in acpi_sba_ioc_add() local
1807 ioc = ioc_init(hpa, device->handle); in acpi_sba_ioc_add()
1808 if (!ioc) in acpi_sba_ioc_add()