• Home
  • Raw
  • Download

Lines Matching +full:d +full:- +full:tlb +full:- +full:sets

2 ** ccio-dma.c:
3 ** DMA management routines for first generation cache-coherent machines.
8 ** (c) Copyright 2000 Hewlett-Packard Company
18 ** the I/O MMU - basically what x86 does.
20 ** Philipp Rumpf has a "Real Mode" driver for PCX-W machines at:
21 ** CVSROOT=:pserver:anonymous@198.186.203.37:/cvsroot/linux-parisc
22 ** cvs -z3 co linux/arch/parisc/kernel/dma-rm.c
24 ** I've rewritten his code to work under TPG's tree. See ccio-rm-dma.c.
27 ** o outbound DMA is slower - U2 won't prefetch data (GSC+ XQL signal).
28 ** o Inbound DMA less efficient - U2 can't use DMA_FAST attribute.
30 ** o Doesn't work under PCX-U/U+ machines since they didn't follow
31 ** the coherency design originally worked out. Only PCX-W does.
46 #include <linux/iommu-helper.h>
56 #include <asm/parisc-device.h>
59 ** Choose "ccio" since that's what HP-UX calls it.
110 #define CMD_TLB_DIRECT_WRITE 35 /* IO_COMMAND for I/O TLB Writes */
111 #define CMD_TLB_PURGE 33 /* IO_COMMAND to Purge I/O TLB entry */
143 ** -------------
150 ** | HV | TLB | reserved | HV | mode | reserved |
171 ** o TLB field affects transactions which are forwarded from GSC+ to Runway.
174 ** TLB Mode Value Description
175 ** Real 0 No TLB translation. Address is directly mapped and the
177 ** Error 1 Software fills the TLB manually.
178 ** Normal 2 IOA fetches IO TLB misses from IO PDIR (in host memory).
194 ** with both sets of LOW/HIGH registers. If the address is in the range
219 ** Writes to both sets of registers will take effect immediately, bypassing
232 u32 res_hint; /* next available IOVP -
258 struct pci_dev *fake_pci_dev; /* the fake pci_dev for non-pci devs */
275 * allocation policies is also adjusted. We'd like to avoid
276 * I/O TLB thrashing by having resource allocation policy
277 * match the I/O TLB replacement policy.
301 idx = (unsigned int)((unsigned long)res_ptr - (unsigned long)ioc->res_map); \
306 ioc->res_hint = res_idx + (size >> 3); \
312 u##size *res_ptr = (u##size *)&((ioc)->res_map[ioa->res_hint & ~((size >> 3) - 1)]); \
313 u##size *res_end = (u##size *)&(ioc)->res_map[ioa->res_size]; \
315 res_ptr = (u##size *)&(ioc)->res_map[0]; \
321 ** o Most IOVA's are "temporary" - avg search time should be small.
333 * ccio_alloc_range - Allocate pages in the ioc's resource map.
354 DBG_RES("%s() size: %d pages_needed %d\n", in ccio_alloc_range()
367 * LAN traffic will not thrash the TLB IFF the same NIC in ccio_alloc_range()
373 * an unsigned long - not byte at a time. As it is now, in ccio_alloc_range()
399 DBG_RES("%s() res_idx %d res_hint: %d\n", in ccio_alloc_range()
400 __func__, res_idx, ioc->res_hint); in ccio_alloc_range()
405 unsigned long tmp = cr_end - cr_start; in ccio_alloc_range()
407 cr_start = (cr_end < cr_start) ? -(tmp) : (tmp); in ccio_alloc_range()
409 ioc->avg_search[ioc->avg_idx++] = cr_start; in ccio_alloc_range()
410 ioc->avg_idx &= CCIO_SEARCH_SAMPLE - 1; in ccio_alloc_range()
411 ioc->used_pages += pages_needed; in ccio_alloc_range()
420 u##size *res_ptr = (u##size *)&((ioc)->res_map[res_idx]); \
425 * ccio_free_range - Free pages from the ioc's resource map.
443 DBG_RES("%s(): res_idx: %d pages_mapped %d\n", in ccio_free_range()
447 ioc->used_pages -= pages_mapped; in ccio_free_range()
500 ** FIXME: the default hints need to be per GSC device - not global.
502 ** HP-UX dorks: linux device driver programming model is totally different
503 ** than HP-UX's. HP-UX always sets HINT_PREFETCH since it's drivers
504 ** do special things to work on non-coherent platforms...linux has to
530 * ccio_io_pdir_entry - Initialize an I/O Pdir.
542 * +------+----------------+-----------------------------------------------+
546 * +------+----------------+-----------------------------------------------+
548 * +-----------------------+-----------------------------------------------+
552 * +-----------------------+-----------------------------------------------+
569 ** WORD 1 - low order word in ccio_io_pdir_entry()
578 ** WORD 0 - high order word in ccio_io_pdir_entry()
606 ** PCX-U/U+ do. (eg C200/C240) in ccio_io_pdir_entry()
607 ** PCX-T'? Don't know. (eg C110 or similar K-class) in ccio_io_pdir_entry()
609 ** See PDC_MODEL/option 0/SW_CAP word for "Non-coherent IO-PDIR bit". in ccio_io_pdir_entry()
612 ** "Since PCX-U employs an offset hash that is incompatible with in ccio_io_pdir_entry()
621 * ccio_clear_io_tlb - Remove stale entries from the I/O TLB.
626 * Purge invalid I/O PDIR entries from the I/O TLB.
633 u32 chain_size = 1 << ioc->chainid_shift; in ccio_clear_io_tlb()
639 WRITE_U32(CMD_TLB_PURGE | iovp, &ioc->ioc_regs->io_command); in ccio_clear_io_tlb()
641 byte_cnt -= chain_size; in ccio_clear_io_tlb()
646 * ccio_mark_invalid - Mark the I/O Pdir entries invalid.
652 * TLB entries.
655 * away the entire I/O TLB instead of individual entries.
657 * FIXME: Uturn has 256 TLB entries. We don't need to purge every
658 * PDIR entry - just once for each possible TLB entry.
675 char *pdir_ptr = (char *) &(ioc->pdir_base[idx]); in ccio_mark_invalid()
677 BUG_ON(idx >= (ioc->pdir_size / sizeof(u64))); in ccio_mark_invalid()
681 ** PCX-U/U+ do. (eg C200/C240) in ccio_mark_invalid()
682 ** See PDC_MODEL/option 0/SW_CAP for "Non-coherent IO-PDIR bit". in ccio_mark_invalid()
690 byte_cnt -= IOVP_SIZE; in ccio_mark_invalid()
704 * ccio_dma_supported - Verify the IOMMU supports the DMA address range.
717 /* only support 32-bit devices (ie PCI/GSC) */ in ccio_dma_supported()
722 * ccio_map_single - Map an address range into the IOMMU.
754 spin_lock_irqsave(&ioc->res_lock, flags); in ccio_map_single()
757 ioc->msingle_calls++; in ccio_map_single()
758 ioc->msingle_pages += size >> IOVP_SHIFT; in ccio_map_single()
764 pdir_start = &(ioc->pdir_base[idx]); in ccio_map_single()
766 DBG_RUN("%s() 0x%p -> 0x%lx size: %0x%x\n", in ccio_map_single()
782 size -= IOVP_SIZE; in ccio_map_single()
785 spin_unlock_irqrestore(&ioc->res_lock, flags); in ccio_map_single()
803 * ccio_unmap_page - Unmap an address range from the IOMMU.
831 spin_lock_irqsave(&ioc->res_lock, flags); in ccio_unmap_page()
834 ioc->usingle_calls++; in ccio_unmap_page()
835 ioc->usingle_pages += size >> IOVP_SHIFT; in ccio_unmap_page()
840 spin_unlock_irqrestore(&ioc->res_lock, flags); in ccio_unmap_page()
844 * ccio_alloc - Allocate a consistent DMA mapping.
857 /* GRANT Need to establish hierarchy for non-PCI devs as well in ccio_alloc()
877 * ccio_free - Free a consistent DMA mapping.
903 #include "iommu-helpers.h"
906 * ccio_map_sg - Map the scatter/gather list into the IOMMU.
930 DBG_RUN_SG("%s() START %d entries\n", __func__, nents); in ccio_map_sg()
935 sg_virt(sglist), sglist->length, in ccio_map_sg()
937 sg_dma_len(sglist) = sglist->length; in ccio_map_sg()
944 spin_lock_irqsave(&ioc->res_lock, flags); in ccio_map_sg()
947 ioc->msg_calls++; in ccio_map_sg()
970 spin_unlock_irqrestore(&ioc->res_lock, flags); in ccio_map_sg()
974 DBG_RUN_SG("%s() DONE %d mappings\n", __func__, filled); in ccio_map_sg()
985 * ccio_unmap_sg - Unmap the scatter/gather list from the IOMMU.
1006 DBG_RUN_SG("%s() START %d entries, %p,%x\n", in ccio_unmap_sg()
1007 __func__, nents, sg_virt(sglist), sglist->length); in ccio_unmap_sg()
1010 ioc->usg_calls++; in ccio_unmap_sg()
1013 while(sg_dma_len(sglist) && nents--) { in ccio_unmap_sg()
1016 ioc->usg_pages += sg_dma_len(sglist) >> PAGE_SHIFT; in ccio_unmap_sg()
1023 DBG_RUN_SG("%s() DONE (nents %d)\n", __func__, nents); in ccio_unmap_sg()
1048 unsigned int total_pages = ioc->res_size << 3; in ccio_proc_info()
1054 seq_printf(m, "%s\n", ioc->name); in ccio_proc_info()
1057 (ioc->cujo20_bug ? "yes" : "no")); in ccio_proc_info()
1059 seq_printf(m, "IO PDIR size : %d bytes (%d entries)\n", in ccio_proc_info()
1063 seq_printf(m, "IO PDIR entries : %ld free %ld used (%d%%)\n", in ccio_proc_info()
1064 total_pages - ioc->used_pages, ioc->used_pages, in ccio_proc_info()
1065 (int)(ioc->used_pages * 100 / total_pages)); in ccio_proc_info()
1068 seq_printf(m, "Resource bitmap : %d bytes (%d pages)\n", in ccio_proc_info()
1069 ioc->res_size, total_pages); in ccio_proc_info()
1072 min = max = ioc->avg_search[0]; in ccio_proc_info()
1074 avg += ioc->avg_search[j]; in ccio_proc_info()
1075 if(ioc->avg_search[j] > max) in ccio_proc_info()
1076 max = ioc->avg_search[j]; in ccio_proc_info()
1077 if(ioc->avg_search[j] < min) in ccio_proc_info()
1078 min = ioc->avg_search[j]; in ccio_proc_info()
1084 seq_printf(m, "pci_map_single(): %8ld calls %8ld pages (avg %d/1000)\n", in ccio_proc_info()
1085 ioc->msingle_calls, ioc->msingle_pages, in ccio_proc_info()
1086 (int)((ioc->msingle_pages * 1000)/ioc->msingle_calls)); in ccio_proc_info()
1088 /* KLUGE - unmap_sg calls unmap_page for each mapped page */ in ccio_proc_info()
1089 min = ioc->usingle_calls - ioc->usg_calls; in ccio_proc_info()
1090 max = ioc->usingle_pages - ioc->usg_pages; in ccio_proc_info()
1091 seq_printf(m, "pci_unmap_single: %8ld calls %8ld pages (avg %d/1000)\n", in ccio_proc_info()
1094 seq_printf(m, "pci_map_sg() : %8ld calls %8ld pages (avg %d/1000)\n", in ccio_proc_info()
1095 ioc->msg_calls, ioc->msg_pages, in ccio_proc_info()
1096 (int)((ioc->msg_pages * 1000)/ioc->msg_calls)); in ccio_proc_info()
1098 seq_printf(m, "pci_unmap_sg() : %8ld calls %8ld pages (avg %d/1000)\n\n\n", in ccio_proc_info()
1099 ioc->usg_calls, ioc->usg_pages, in ccio_proc_info()
1100 (int)((ioc->usg_pages * 1000)/ioc->usg_calls)); in ccio_proc_info()
1103 ioc = ioc->next; in ccio_proc_info()
1114 seq_hex_dump(m, " ", DUMP_PREFIX_NONE, 32, 4, ioc->res_map, in ccio_proc_bitmap_info()
1115 ioc->res_size, false); in ccio_proc_bitmap_info()
1117 ioc = ioc->next; in ccio_proc_bitmap_info()
1118 break; /* XXX - remove me */ in ccio_proc_bitmap_info()
1126 * ccio_find_ioc - Find the ioc in the ioc_list
1139 if (ioc->hw_path == hw_path) in ccio_find_ioc()
1142 ioc = ioc->next; in ccio_find_ioc()
1149 * ccio_get_iommu - Find the iommu which controls this device
1161 return ccio_find_ioc(dev->hw_path); in ccio_get_iommu()
1177 ioc->cujo20_bug = 1; in ccio_cujo20_fixup()
1178 res_ptr = ioc->res_map; in ccio_cujo20_fixup()
1181 while (idx < ioc->res_size) { in ccio_cujo20_fixup()
1188 /* GRANT - is this needed for U2 or not? */
1191 ** Get the size of the I/O TLB for this I/O MMU.
1193 ** If spa_shift is non-zero (ie probably U2),
1194 ** then calculate the I/O TLB size using spa_shift.
1196 ** Otherwise we are supposed to get the IODC entry point ENTRY TLB
1198 ** I think only Java (K/D/R-class too?) systems don't do this.
1203 if (dev->spa_shift == 0) {
1204 panic("%s() : Can't determine I/O TLB size.\n", __func__);
1206 return (1 << dev->spa_shift);
1210 /* Uturn supports 256 TLB entries */
1231 * ccio_ioc_init - Initialize the I/O Controller
1251 ** can be outstanding based on PCI Class/sub-class. Both in ccio_ioc_init()
1253 ** Hot-Plug/Removal of PCI cards. (aka PCI OLARD). in ccio_ioc_init()
1258 /* limit IOVA space size to 1MB-1GB */ in ccio_ioc_init()
1260 if (iova_space_size < (1 << (20 - PAGE_SHIFT))) { in ccio_ioc_init()
1261 iova_space_size = 1 << (20 - PAGE_SHIFT); in ccio_ioc_init()
1263 } else if (iova_space_size > (1 << (30 - PAGE_SHIFT))) { in ccio_ioc_init()
1264 iova_space_size = 1 << (30 - PAGE_SHIFT); in ccio_ioc_init()
1277 ** since the pages must also be physically contiguous - typically in ccio_ioc_init()
1286 ioc->pdir_size = (iova_space_size / IOVP_SIZE) * sizeof(u64); in ccio_ioc_init()
1288 BUG_ON(ioc->pdir_size > 8 * 1024 * 1024); /* max pdir size <= 8MB */ in ccio_ioc_init()
1291 BUG_ON((1 << get_order(ioc->pdir_size)) != (ioc->pdir_size >> PAGE_SHIFT)); in ccio_ioc_init()
1293 DBG_INIT("%s() hpa 0x%p mem %luMB IOV %dMB (%d bits)\n", in ccio_ioc_init()
1294 __func__, ioc->ioc_regs, in ccio_ioc_init()
1295 (unsigned long) totalram_pages >> (20 - PAGE_SHIFT), in ccio_ioc_init()
1299 ioc->pdir_base = (u64 *)__get_free_pages(GFP_KERNEL, in ccio_ioc_init()
1300 get_order(ioc->pdir_size)); in ccio_ioc_init()
1301 if(NULL == ioc->pdir_base) { in ccio_ioc_init()
1304 memset(ioc->pdir_base, 0, ioc->pdir_size); in ccio_ioc_init()
1306 BUG_ON((((unsigned long)ioc->pdir_base) & PAGE_MASK) != (unsigned long)ioc->pdir_base); in ccio_ioc_init()
1307 DBG_INIT(" base %p\n", ioc->pdir_base); in ccio_ioc_init()
1310 ioc->res_size = (ioc->pdir_size / sizeof(u64)) >> 3; in ccio_ioc_init()
1311 DBG_INIT("%s() res_size 0x%x\n", __func__, ioc->res_size); in ccio_ioc_init()
1313 ioc->res_map = (u8 *)__get_free_pages(GFP_KERNEL, in ccio_ioc_init()
1314 get_order(ioc->res_size)); in ccio_ioc_init()
1315 if(NULL == ioc->res_map) { in ccio_ioc_init()
1318 memset(ioc->res_map, 0, ioc->res_size); in ccio_ioc_init()
1321 ioc->res_hint = 16; in ccio_ioc_init()
1324 spin_lock_init(&ioc->res_lock); in ccio_ioc_init()
1328 ** which TLB entry an IOVP will use. in ccio_ioc_init()
1330 ioc->chainid_shift = get_order(iova_space_size) + PAGE_SHIFT - CCIO_CHAINID_SHIFT; in ccio_ioc_init()
1331 DBG_INIT(" chainid_shift 0x%x\n", ioc->chainid_shift); in ccio_ioc_init()
1336 WRITE_U32(CCIO_CHAINID_MASK << ioc->chainid_shift, in ccio_ioc_init()
1337 &ioc->ioc_regs->io_chain_id_mask); in ccio_ioc_init()
1339 WRITE_U32(virt_to_phys(ioc->pdir_base), in ccio_ioc_init()
1340 &ioc->ioc_regs->io_pdir_base); in ccio_ioc_init()
1345 WRITE_U32(IOA_NORMAL_MODE, &ioc->ioc_regs->io_control); in ccio_ioc_init()
1348 ** Initialize all I/O TLB entries to 0 (Valid bit off). in ccio_ioc_init()
1350 WRITE_U32(0, &ioc->ioc_regs->io_tlb_entry_m); in ccio_ioc_init()
1351 WRITE_U32(0, &ioc->ioc_regs->io_tlb_entry_l); in ccio_ioc_init()
1353 for(i = 1 << CCIO_CHAINID_SHIFT; i ; i--) { in ccio_ioc_init()
1354 WRITE_U32((CMD_TLB_DIRECT_WRITE | (i << ioc->chainid_shift)), in ccio_ioc_init()
1355 &ioc->ioc_regs->io_command); in ccio_ioc_init()
1364 res->parent = NULL; in ccio_init_resource()
1365 res->flags = IORESOURCE_MEM; in ccio_init_resource()
1369 * The upper 16-bits of range registers are hardcoded to 0xffff. in ccio_init_resource()
1371 res->start = (unsigned long)((signed) READ_U32(ioaddr) << 16); in ccio_init_resource()
1372 res->end = (unsigned long)((signed) (READ_U32(ioaddr + 4) << 16) - 1); in ccio_init_resource()
1373 res->name = name; in ccio_init_resource()
1377 if (res->end + 1 == res->start) in ccio_init_resource()
1380 /* On some platforms (e.g. K-Class), we have already registered in ccio_init_resource()
1388 __func__, (unsigned long)res->start, (unsigned long)res->end); in ccio_init_resource()
1394 struct resource *res = ioc->mmio_region; in ccio_init_resources()
1397 snprintf(name, 14, "GSC Bus [%d/]", ioc->hw_path); in ccio_init_resources()
1399 ccio_init_resource(res, name, &ioc->ioc_regs->io_io_low); in ccio_init_resources()
1400 ccio_init_resource(res + 1, name, &ioc->ioc_regs->io_io_low_hv); in ccio_init_resources()
1407 return -EBUSY; in new_ioc_area()
1409 res->start = (max - size + 1) &~ (align - 1); in new_ioc_area()
1410 res->end = res->start + size; in new_ioc_area()
1419 return new_ioc_area(res, size, min, max - size, align); in new_ioc_area()
1427 if (!res->parent) in expand_ioc_area()
1430 start = (res->start - size) &~ (align - 1); in expand_ioc_area()
1431 len = res->end - start + 1; in expand_ioc_area()
1437 start = res->start; in expand_ioc_area()
1438 len = ((size + res->end + align) &~ (align - 1)) - start; in expand_ioc_area()
1444 return -EBUSY; in expand_ioc_area()
1463 parent = ioc->mmio_region; in ccio_allocate_resource()
1464 if (parent->parent && in ccio_allocate_resource()
1468 if ((parent + 1)->parent && in ccio_allocate_resource()
1474 __raw_writel(((parent->start)>>16) | 0xffff0000, in ccio_allocate_resource()
1475 &ioc->ioc_regs->io_io_low); in ccio_allocate_resource()
1476 __raw_writel(((parent->end)>>16) | 0xffff0000, in ccio_allocate_resource()
1477 &ioc->ioc_regs->io_io_high); in ccio_allocate_resource()
1480 __raw_writel(((parent->start)>>16) | 0xffff0000, in ccio_allocate_resource()
1481 &ioc->ioc_regs->io_io_low_hv); in ccio_allocate_resource()
1482 __raw_writel(((parent->end)>>16) | 0xffff0000, in ccio_allocate_resource()
1483 &ioc->ioc_regs->io_io_high_hv); in ccio_allocate_resource()
1485 return -EBUSY; in ccio_allocate_resource()
1500 } else if ((ioc->mmio_region->start <= res->start) && in ccio_request_resource()
1501 (res->end <= ioc->mmio_region->end)) { in ccio_request_resource()
1502 parent = ioc->mmio_region; in ccio_request_resource()
1503 } else if (((ioc->mmio_region + 1)->start <= res->start) && in ccio_request_resource()
1504 (res->end <= (ioc->mmio_region + 1)->end)) { in ccio_request_resource()
1505 parent = ioc->mmio_region + 1; in ccio_request_resource()
1507 return -EBUSY; in ccio_request_resource()
1511 * firmware assigned them. e.g. children of hppb.c (e.g. K-class) in ccio_request_resource()
1519 * ccio_probe - Determine if ccio should claim this device.
1534 return -ENOMEM; in ccio_probe()
1537 ioc->name = dev->id.hversion == U2_IOA_RUNWAY ? "U2" : "UTurn"; in ccio_probe()
1539 printk(KERN_INFO "Found %s at 0x%lx\n", ioc->name, in ccio_probe()
1540 (unsigned long)dev->hpa.start); in ccio_probe()
1543 ioc_p = &(*ioc_p)->next; in ccio_probe()
1547 ioc->hw_path = dev->hw_path; in ccio_probe()
1548 ioc->ioc_regs = ioremap_nocache(dev->hpa.start, 4096); in ccio_probe()
1549 if (!ioc->ioc_regs) { in ccio_probe()
1551 return -ENOMEM; in ccio_probe()
1556 dev->dev.platform_data = kzalloc(sizeof(struct pci_hba_data), GFP_KERNEL); in ccio_probe()
1559 BUG_ON(dev->dev.platform_data == NULL); in ccio_probe()
1560 HBA_DATA(dev->dev.platform_data)->iommu = ioc; in ccio_probe()
1566 proc_create_single(MODULE_NAME"-bitmap", 0, proc_runway_root, in ccio_probe()
1575 * ccio_init - ccio initialization procedure.