Date: Tue, 11 Apr 2006 09:47:42 GMT From: Kip Macy <kmacy@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 94981 for review Message-ID: <200604110947.k3B9lg7i057078@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=94981 Change 94981 by kmacy@kmacy_storage:sun4v_rwbuf on 2006/04/11 09:46:41 fix a number of small API misuses allowing us to get to single-user Affected files ... .. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/hviommu.c#10 edit Differences ... ==== //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/hviommu.c#10 (text+ko) ==== @@ -134,6 +134,7 @@ #define round_io_page(x) round_page(x) #define trunc_io_page(x) trunc_page(x) + MALLOC_DEFINE(M_HVIOMMU, "hviommu", "HyperVisor IOMMU"); TAILQ_HEAD(hviommu_maplruq_head, bus_dmamap); @@ -151,6 +152,12 @@ #define VA_TO_TSBID(him, va) ((va - (him)->him_dvmabase) >> IO_PAGE_SHIFT) +#ifdef IOMMU_DEBUG +#define DPRINTF printf +#else +#define DPRINTF(...) +#endif + /* * Always overallocate one page; this is needed to handle alignment of the * buffer, so it makes sense using a lazy allocation scheme. @@ -238,6 +245,7 @@ KASSERT(va + len >= va, ("%s: va 0x%lx + len 0x%lx wraps", __func__, (long)va, (long)len)); va = trunc_io_page(va); + len = round_page(len); while (len > 0) { if ((error = hvio_iommu_demap(him->him_handle, VA_TO_TSBID(him, va), len >> IO_PAGE_SHIFT, &demapped))) { @@ -534,27 +542,39 @@ static void hviommu_map_pages(struct hviommu *him, bus_addr_t dvmaddr, uint64_t *iottes, pages_t iottecnt) { - uint64_t iotteaddr[IOTTE_CNT]; uint64_t err; +#ifdef IOMMU_DEBUG + bus_addr_t ra; + io_attributes_t ioattr; +#endif pages_t mapcnt; int cntdone; int i; - for (i = 0; i < iottecnt; i++) - iotteaddr[i] = pmap_kextract((vm_offset_t)&iottes[i]); + DPRINTF("mapping: dh: %#lx, dvmaddr: %#lx, tsbid: %#lx, cnt: %d\n", + him->him_handle, dvmaddr, VA_TO_TSBID(him, dvmaddr), iottecnt); + for (i = 0; i < iottecnt; i++) { + DPRINTF("iotte:%#lx\n", iottes[i]); + } /* push tte's */ cntdone = 0; while (cntdone < iottecnt) { if ((err = hvio_iommu_map(him->him_handle, VA_TO_TSBID(him, dvmaddr), iottecnt, PCI_MAP_ATTR_READ | PCI_MAP_ATTR_WRITE, - (io_page_list_t *)pmap_kextract((vm_offset_t)&iotteaddr[0]), + (io_page_list_t *)pmap_kextract((vm_offset_t)&iottes[0]), &mapcnt))) { - printf("iommu_map: err: %ld\n", err); + DPRINTF("iommu_map: err: %ld\n", err); mapcnt = 1; } cntdone += mapcnt; } + for (i = 0; i < iottecnt; i++) { + DPRINTF("err: %ld", hvio_iommu_getmap(him->him_handle, + VA_TO_TSBID(him, dvmaddr + i * IO_PAGE_SIZE), + &ioattr, &ra)); + DPRINTF(", ioattr: %d, raddr: %#lx\n", ioattr, ra); + } } /* @@ -591,6 +611,8 @@ if (error != 0) return (error); + DPRINTF("vallocseg: dvmaddr: %#lx, voffs: %#lx, buflen: %#lx\n", + dvmaddr, voffs, buflen); sgcnt = *segp; firstpg = 1; iottecnt = 0; @@ -620,7 +642,9 @@ #else if (iottecnt == 0) iottebase = trunc_io_page(dvmaddr); - iottes[iottecnt] = MAKEIOTTE(trunc_io_page(curaddr), 1, 0, 0); + DPRINTF("adding: %#lx\n", trunc_io_page(curaddr)); + iottes[iottecnt++] = trunc_io_page(curaddr); + if (iottecnt >= IOTTE_CNT) { hviommu_map_pages(him, iottebase, iottes, iottecnt); iottecnt = 0; @@ -885,42 +909,56 @@ size_t synced; bus_addr_t ra; uint64_t err; - uint32_t ioattr; + io_attributes_t ioattr; + vm_paddr_t raddr; io_sync_direction_t iodir; if ((map->dm_flags & DMF_LOADED) == 0) return; - /* XXX This is probably bogus. */ + iodir = 0; - if (op & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_POSTREAD)) + + if (op & (BUS_DMASYNC_POSTREAD)) iodir |= IO_SYNC_CPU; - if (op & (BUS_DMASYNC_PREWRITE|BUS_DMASYNC_POSTWRITE)) + if (op & (BUS_DMASYNC_PREWRITE)) iodir |= IO_SYNC_DEVICE; - if ((op & BUS_DMASYNC_PREREAD) != 0) + if ((op & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_POSTWRITE)) != 0) membar(Sync); + + /* nothing to be done */ + if (!iodir) + return; + HIM_LOCK(him); SLIST_FOREACH(r, &map->dm_reslist, dr_link) { va = (vm_offset_t)BDR_START(r) + r->dr_offset; len = r->dr_used; while (len > 0) { if ((err = hvio_iommu_getmap(him->him_handle, - VA_TO_TSBID(him, va), &ra, &ioattr))) { - printf("failed to _getmap: err: %ld, handle: %#lx, tsbid: %#lx", err, him->him_handle, VA_TO_TSBID(him, va)); + VA_TO_TSBID(him, va), &ioattr, &ra))) { + printf("failed to _getmap: err: %ld, handle: %#lx, tsbid: %#lx", + err, him->him_handle, VA_TO_TSBID(him, va)); continue; } if ((err = hvio_dma_sync(him->him_handle, ra, - min(len, (trunc_io_page(ra) + IO_PAGE_SIZE) - ra), + ulmin(len, (trunc_io_page(ra) + IO_PAGE_SIZE) - ra), iodir, &synced))) { - printf("failed to dma_sync: err: %ld, handle: %#lx, va: %#lx, len: %#lx, dir: %d\n", - err, him->him_handle, va, len, iodir); - synced = 1; + printf("failed to dma_sync: err: %ld, handle: %#lx, ra: %#lx, len: %#lx, dir: %d\n", + err, him->him_handle, ra, ulmin(len, + (trunc_io_page(ra) + IO_PAGE_SIZE) - ra), + iodir); + synced = ulmin(len, (trunc_io_page(ra) + IO_PAGE_SIZE) - ra); + printf("err: %ld", hvio_iommu_getmap(him->him_handle, VA_TO_TSBID(him, va), + &ioattr, &raddr)); + printf(", ioattr: %d, raddr: %#lx\n", ioattr, raddr); } va += synced; len -= synced; } } HIM_UNLOCK(him); + if ((op & BUS_DMASYNC_PREWRITE) != 0) membar(Sync); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604110947.k3B9lg7i057078>