Lines Matching refs:ioc

225 struct ioc {
253 struct ioc *next; /* Linked list of discovered iocs */
255 unsigned int hw_path; /* the hardware path this ioc is associatd with */
260 static struct ioc *ioc_list;
295 #define CCIO_SEARCH_LOOP(ioc, res_idx, mask, size) \
299 idx = (unsigned int)((unsigned long)res_ptr - (unsigned long)ioc->res_map); \
304 ioc->res_hint = res_idx + (size >> 3); \
310 u##size *res_ptr = (u##size *)&((ioc)->res_map[ioa->res_hint & ~((size >> 3) - 1)]); \
311 u##size *res_end = (u##size *)&(ioc)->res_map[ioa->res_size]; \
312 CCIO_SEARCH_LOOP(ioc, res_idx, mask, size); \
313 res_ptr = (u##size *)&(ioc)->res_map[0]; \
331 * ccio_alloc_range - Allocate pages in the ioc's resource map.
332 * @ioc: The I/O Controller.
336 * This function searches the resource map of the ioc to locate a range
340 ccio_alloc_range(struct ioc *ioc, struct device *dev, size_t size)
375 CCIO_FIND_FREE_MAPPING(ioc, res_idx, mask, 8);
377 CCIO_FIND_FREE_MAPPING(ioc, res_idx, 0xff, 8);
380 CCIO_FIND_FREE_MAPPING(ioc, res_idx, 0xffff, 16);
382 CCIO_FIND_FREE_MAPPING(ioc, res_idx, ~(unsigned int)0, 32);
385 CCIO_FIND_FREE_MAPPING(ioc, res_idx, ~0UL, 64);
398 __func__, res_idx, ioc->res_hint);
407 ioc->avg_search[ioc->avg_idx++] = cr_start;
408 ioc->avg_idx &= CCIO_SEARCH_SAMPLE - 1;
409 ioc->used_pages += pages_needed;
417 #define CCIO_FREE_MAPPINGS(ioc, res_idx, mask, size) \
418 u##size *res_ptr = (u##size *)&((ioc)->res_map[res_idx]); \
423 * ccio_free_range - Free pages from the ioc's resource map.
424 * @ioc: The I/O Controller.
432 ccio_free_range(struct ioc *ioc, dma_addr_t iova, unsigned long pages_mapped)
445 ioc->used_pages -= pages_mapped;
452 CCIO_FREE_MAPPINGS(ioc, res_idx, mask, 8);
454 CCIO_FREE_MAPPINGS(ioc, res_idx, 0xffUL, 8);
457 CCIO_FREE_MAPPINGS(ioc, res_idx, 0xffffUL, 16);
459 CCIO_FREE_MAPPINGS(ioc, res_idx, ~(unsigned int)0, 32);
462 CCIO_FREE_MAPPINGS(ioc, res_idx, ~0UL, 64);
622 * @ioc: The I/O Controller.
631 ccio_clear_io_tlb(struct ioc *ioc, dma_addr_t iovp, size_t byte_cnt)
633 u32 chain_size = 1 << ioc->chainid_shift;
639 WRITE_U32(CMD_TLB_PURGE | iovp, &ioc->ioc_regs->io_command);
647 * @ioc: The I/O Controller.
664 ccio_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt)
675 char *pdir_ptr = (char *) &(ioc->pdir_base[idx]);
677 BUG_ON(idx >= (ioc->pdir_size / sizeof(u64)));
694 ccio_clear_io_tlb(ioc, CCIO_IOVP(iova), saved_byte_cnt);
737 struct ioc *ioc;
745 ioc = GET_IOC(dev);
754 spin_lock_irqsave(&ioc->res_lock, flags);
757 ioc->msingle_calls++;
758 ioc->msingle_pages += size >> IOVP_SHIFT;
761 idx = ccio_alloc_range(ioc, dev, size);
764 pdir_start = &(ioc->pdir_base[idx]);
785 spin_unlock_irqrestore(&ioc->res_lock, flags);
804 struct ioc *ioc;
809 ioc = GET_IOC(dev);
818 spin_lock_irqsave(&ioc->res_lock, flags);
821 ioc->usingle_calls++;
822 ioc->usingle_pages += size >> IOVP_SHIFT;
825 ccio_mark_invalid(ioc, iova, size);
826 ccio_free_range(ioc, iova, (size >> IOVP_SHIFT));
827 spin_unlock_irqrestore(&ioc->res_lock, flags);
904 struct ioc *ioc;
912 ioc = GET_IOC(dev);
928 spin_lock_irqsave(&ioc->res_lock, flags);
931 ioc->msg_calls++;
942 coalesced = iommu_coalesce_chunks(ioc, dev, sglist, nents, ccio_alloc_range);
952 filled = iommu_fill_pdir(ioc, sglist, nents, hint, ccio_io_pdir_entry);
954 spin_unlock_irqrestore(&ioc->res_lock, flags);
981 struct ioc *ioc;
984 ioc = GET_IOC(dev);
990 ioc->usg_calls++;
996 ioc->usg_pages += sg_dma_len(sglist) >> PAGE_SHIFT;
1025 struct ioc *ioc = ioc_list;
1027 while (ioc != NULL) {
1028 unsigned int total_pages = ioc->res_size << 3;
1034 len += seq_printf(m, "%s\n", ioc->name);
1037 (ioc->cujo20_bug ? "yes" : "no"));
1044 total_pages - ioc->used_pages, ioc->used_pages,
1045 (int)(ioc->used_pages * 100 / total_pages));
1049 ioc->res_size, total_pages);
1052 min = max = ioc->avg_search[0];
1054 avg += ioc->avg_search[j];
1055 if(ioc->avg_search[j] > max)
1056 max = ioc->avg_search[j];
1057 if(ioc->avg_search[j] < min)
1058 min = ioc->avg_search[j];
1065 ioc->msingle_calls, ioc->msingle_pages,
1066 (int)((ioc->msingle_pages * 1000)/ioc->msingle_calls));
1069 min = ioc->usingle_calls - ioc->usg_calls;
1070 max = ioc->usingle_pages - ioc->usg_pages;
1075 ioc->msg_calls, ioc->msg_pages,
1076 (int)((ioc->msg_pages * 1000)/ioc->msg_calls));
1079 ioc->usg_calls, ioc->usg_pages,
1080 (int)((ioc->usg_pages * 1000)/ioc->usg_calls));
1083 ioc = ioc->next;
1105 struct ioc *ioc = ioc_list;
1107 while (ioc != NULL) {
1108 u32 *res_ptr = (u32 *)ioc->res_map;
1111 for (j = 0; j < (ioc->res_size / sizeof(u32)); j++) {
1118 ioc = ioc->next;
1140 * ccio_find_ioc - Find the ioc in the ioc_list
1141 * @hw_path: The hardware path of the ioc.
1143 * This function searches the ioc_list for an ioc that matches
1146 static struct ioc * ccio_find_ioc(int hw_path)
1149 struct ioc *ioc;
1151 ioc = ioc_list;
1153 if (ioc->hw_path == hw_path)
1154 return ioc;
1156 ioc = ioc->next;
1188 struct ioc *ioc = ccio_get_iommu(dev);
1191 ioc->cujo20_bug = 1;
1192 res_ptr = ioc->res_map;
1195 while (idx < ioc->res_size) {
1246 * @ioc: The I/O Controller.
1253 ccio_ioc_init(struct ioc *ioc)
1300 ioc->pdir_size = (iova_space_size / IOVP_SIZE) * sizeof(u64);
1302 BUG_ON(ioc->pdir_size > 8 * 1024 * 1024); /* max pdir size <= 8MB */
1305 BUG_ON((1 << get_order(ioc->pdir_size)) != (ioc->pdir_size >> PAGE_SHIFT));
1308 __func__, ioc->ioc_regs,
1313 ioc->pdir_base = (u64 *)__get_free_pages(GFP_KERNEL,
1314 get_order(ioc->pdir_size));
1315 if(NULL == ioc->pdir_base) {
1318 memset(ioc->pdir_base, 0, ioc->pdir_size);
1320 BUG_ON((((unsigned long)ioc->pdir_base) & PAGE_MASK) != (unsigned long)ioc->pdir_base);
1321 DBG_INIT(" base %p\n", ioc->pdir_base);
1324 ioc->res_size = (ioc->pdir_size / sizeof(u64)) >> 3;
1325 DBG_INIT("%s() res_size 0x%x\n", __func__, ioc->res_size);
1327 ioc->res_map = (u8 *)__get_free_pages(GFP_KERNEL,
1328 get_order(ioc->res_size));
1329 if(NULL == ioc->res_map) {
1332 memset(ioc->res_map, 0, ioc->res_size);
1335 ioc->res_hint = 16;
1338 spin_lock_init(&ioc->res_lock);
1344 ioc->chainid_shift = get_order(iova_space_size) + PAGE_SHIFT - CCIO_CHAINID_SHIFT;
1345 DBG_INIT(" chainid_shift 0x%x\n", ioc->chainid_shift);
1350 WRITE_U32(CCIO_CHAINID_MASK << ioc->chainid_shift,
1351 &ioc->ioc_regs->io_chain_id_mask);
1353 WRITE_U32(virt_to_phys(ioc->pdir_base),
1354 &ioc->ioc_regs->io_pdir_base);
1359 WRITE_U32(IOA_NORMAL_MODE, &ioc->ioc_regs->io_control);
1364 WRITE_U32(0, &ioc->ioc_regs->io_tlb_entry_m);
1365 WRITE_U32(0, &ioc->ioc_regs->io_tlb_entry_l);
1368 WRITE_U32((CMD_TLB_DIRECT_WRITE | (i << ioc->chainid_shift)),
1369 &ioc->ioc_regs->io_command);
1406 static void __init ccio_init_resources(struct ioc *ioc)
1408 struct resource *res = ioc->mmio_region;
1411 snprintf(name, 14, "GSC Bus [%d/]", ioc->hw_path);
1413 ccio_init_resource(res, name, &ioc->ioc_regs->io_io_low);
1414 ccio_init_resource(res + 1, name, &ioc->ioc_regs->io_io_low_hv);
1466 * Some other issues: one of the resources in the ioc may be unassigned.
1473 struct ioc *ioc = ccio_get_iommu(dev);
1474 if (!ioc)
1477 parent = ioc->mmio_region;
1489 &ioc->ioc_regs->io_io_low);
1491 &ioc->ioc_regs->io_io_high);
1495 &ioc->ioc_regs->io_io_low_hv);
1497 &ioc->ioc_regs->io_io_high_hv);
1510 struct ioc *ioc = ccio_get_iommu(dev);
1512 if (!ioc) {
1514 } else if ((ioc->mmio_region->start <= res->start) &&
1515 (res->end <= ioc->mmio_region->end)) {
1516 parent = ioc->mmio_region;
1517 } else if (((ioc->mmio_region + 1)->start <= res->start) &&
1518 (res->end <= (ioc->mmio_region + 1)->end)) {
1519 parent = ioc->mmio_region + 1;
1543 struct ioc *ioc, **ioc_p = &ioc_list;
1545 ioc = kzalloc(sizeof(struct ioc), GFP_KERNEL);
1546 if (ioc == NULL) {
1551 ioc->name = dev->id.hversion == U2_IOA_RUNWAY ? "U2" : "UTurn";
1553 printk(KERN_INFO "Found %s at 0x%lx\n", ioc->name,
1559 *ioc_p = ioc;
1561 ioc->hw_path = dev->hw_path;
1562 ioc->ioc_regs = ioremap_nocache(dev->hpa.start, 4096);
1563 ccio_ioc_init(ioc);
1564 ccio_init_resources(ioc);
1570 HBA_DATA(dev->dev.platform_data)->iommu = ioc;