Index: agp.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp.c,v retrieving revision 1.24 diff -u -p -r1.24 agp.c --- agp.c 21 Jan 2003 08:56:11 -0000 1.24 +++ agp.c 7 Feb 2003 16:31:26 -0000 @@ -41,6 +41,8 @@ #include #include +#include + #include #include #include @@ -54,7 +56,6 @@ #include #include -#include #include #include @@ -162,6 +163,17 @@ agp_find_display(void) return 0; } +static void +agp_getaddr(void *p, bus_dma_segment_t *dm_segs, int nseg, int error) +{ + struct agp_gatt *gatt; + + gatt = (struct agp_gatt *)p; + if (error) + return; + gatt->ag_physical = dm_segs->ds_addr; +} + struct agp_gatt * agp_alloc_gatt(device_t dev) { @@ -179,16 +191,35 @@ agp_alloc_gatt(device_t dev) return 0; gatt->ag_entries = entries; - gatt->ag_virtual = contigmalloc(entries * sizeof(u_int32_t), M_AGP, 0, - 0, ~0, PAGE_SIZE, 0); - if (!gatt->ag_virtual) { + if (bus_dma_tag_create(NULL, PAGE_SIZE, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, entries * sizeof(u_int32_t), + 1, BUS_SPACE_MAXSIZE_32BIT, 0, &gatt->dmat) != 0) { + free(gatt, M_AGP); if (bootverbose) - device_printf(dev, "contiguous allocation failed\n"); + device_printf(dev, "bus_dma_tag_create failed\n"); + return (0); + } + if (bus_dmamem_alloc(gatt->dmat, (void **)&gatt->ag_virtual, + BUS_DMA_NOWAIT, &gatt->dmamap) != 0) { + bus_dma_tag_destroy(gatt->dmat); free(gatt, M_AGP); - return 0; + if (bootverbose) + device_printf(dev, "bus_dmamem_alloc failed\n"); + return (0); + } + if (bus_dmamap_load(gatt->dmat, gatt->dmamap, + (void *)gatt->ag_virtual, entries * sizeof(u_int32_t), + agp_getaddr, gatt, 0) != 0) { + bus_dmamem_free(gatt->dmat, gatt->dmamap, + (void *)gatt->ag_virtual); + bus_dma_tag_destroy(gatt->dmat); + bus_dmamap_destroy(gatt->dmat, gatt->dmamap); + free(gatt, M_AGP); + if (bootverbose) + device_printf(dev, "bus_dmamap_load failed\n"); + return (0); } bzero(gatt->ag_virtual, entries * sizeof(u_int32_t)); - gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual); agp_flush_cache(); return gatt; @@ -197,8 +228,10 @@ agp_alloc_gatt(device_t dev) void agp_free_gatt(struct agp_gatt *gatt) { - contigfree(gatt->ag_virtual, - gatt->ag_entries * sizeof(u_int32_t), M_AGP); + bus_dmamap_unload(gatt->dmat, gatt->dmamap); + bus_dmamem_free(gatt->dmat, gatt->dmamap, (void *)gatt->ag_virtual); + bus_dmamap_destroy(gatt->dmat, gatt->dmamap); + bus_dma_tag_destroy(gatt->dmat); free(gatt, M_AGP); } Index: agp_ali.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp_ali.c,v retrieving revision 1.5 diff -u -p -r1.5 agp_ali.c --- agp_ali.c 13 Nov 2002 17:40:15 -0000 1.5 +++ agp_ali.c 6 Feb 2003 00:55:37 -0000 @@ -38,6 +38,8 @@ #include #include +#include + #include #include #include Index: agp_amd.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp_amd.c,v retrieving revision 1.13 diff -u -p -r1.13 agp_amd.c --- agp_amd.c 13 Nov 2002 17:40:15 -0000 1.13 +++ agp_amd.c 7 Feb 2003 16:31:07 -0000 @@ -38,6 +38,8 @@ #include #include +#include + #include #include #include @@ -61,6 +63,10 @@ struct agp_amd_gatt { u_int32_t ag_entries; u_int32_t *ag_virtual; /* virtual address of gatt */ vm_offset_t ag_physical; + bus_dma_tag_t dmat; + bus_dma_tag_t dmat_vdir; + bus_dmamap_t dmamap; + bus_dmamap_t dmamap_vdir; u_int32_t *ag_vdir; /* virtual address of page dir */ vm_offset_t ag_pdir; /* physical address of page dir */ }; @@ -74,6 +80,24 @@ struct agp_amd_softc { struct agp_amd_gatt *gatt; }; +static void +agp_amd_getaddr(void *p, bus_dma_segment_t *dm_segs, int nseg, int error) +{ + struct agp_amd_gatt *gatt; + + gatt = (struct agp_amd_gatt *)p; + gatt->ag_physical = dm_segs->ds_addr; +} + +static void +agp_amd_getaddr_vdir(void *p, bus_dma_segment_t *dm_segs, int nseg, int error) +{ + struct agp_amd_gatt *gatt; + + gatt = (struct agp_amd_gatt *)p; + gatt->ag_pdir = dm_segs->ds_addr; +} + static struct agp_amd_gatt * agp_amd_alloc_gatt(device_t dev) { @@ -90,7 +114,7 @@ agp_amd_alloc_gatt(device_t dev) gatt = malloc(sizeof(struct agp_amd_gatt), M_AGP, M_NOWAIT); if (!gatt) return 0; - + bzero(gatt, sizeof(struct agp_amd_gatt)); /* * The AMD751 uses a page directory to map a non-contiguous * gatt so we don't need to use contigmalloc. @@ -98,43 +122,77 @@ agp_amd_alloc_gatt(device_t dev) * directory. */ gatt->ag_entries = entries; - gatt->ag_virtual = malloc(entries * sizeof(u_int32_t), - M_AGP, M_NOWAIT); - if (!gatt->ag_virtual) { + if (bus_dma_tag_create(NULL, PAGE_SIZE, 0, BUS_SPACE_MAXADDR, + BUS_SPACE_MAXADDR, NULL, NULL, entries * sizeof(u_int32_t), 1, + BUS_SPACE_MAXSIZE_32BIT, 0, &gatt->dmat) != 0) { + free(gatt, M_AGP); if (bootverbose) - device_printf(dev, "allocation failed\n"); + device_printf(dev, + "bus_dma_tag_create failed\n"); + return (0); + } + if (bus_dmamem_alloc(gatt->dmat, (void **)&gatt->ag_virtual, + BUS_DMA_NOWAIT, &gatt->dmamap) != 0) { + bus_dma_tag_destroy(gatt->dmat); free(gatt, M_AGP); - return 0; + if (bootverbose) + device_printf(dev, + "bus_dmamem_alloc failed\n"); + return (0); } + if (bus_dmamap_load(gatt->dmat, gatt->dmamap, + (void *)gatt->ag_virtual, entries * sizeof(u_int32_t), + agp_amd_getaddr, gatt, 0) != 0) { + bus_dmamem_free(gatt->dmat, gatt->dmamap, + (void *)gatt->ag_virtual); + bus_dma_tag_destroy(gatt->dmat); + free(gatt, M_AGP); + if (bootverbose) + device_printf(dev, + "bus_dmamap_load failed\n"); + return (0); + } + bzero(gatt->ag_virtual, entries * sizeof(u_int32_t)); /* * Allocate the page directory. */ - gatt->ag_vdir = malloc(AGP_PAGE_SIZE, M_AGP, M_NOWAIT); - if (!gatt->ag_vdir) { + if (bus_dma_tag_create(NULL, PAGE_SIZE, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, AGP_PAGE_SIZE, 1, + BUS_SPACE_MAXSIZE_32BIT, 0, &gatt->dmat_vdir) != 0) { + if (bootverbose) + device_printf(dev, + "bus_dma_tag_create failed\n"); + goto bad; + } + if (bus_dmamem_alloc(gatt->dmat_vdir, (void **)&gatt->ag_vdir, + BUS_DMA_NOWAIT, &gatt->dmamap_vdir) != 0) { if (bootverbose) device_printf(dev, - "failed to allocate page directory\n"); - free(gatt->ag_virtual, M_AGP); - free(gatt, M_AGP); - return 0; + "bus_dmamem_alloc failed\n"); + goto bad; } - bzero(gatt->ag_vdir, AGP_PAGE_SIZE); - - gatt->ag_pdir = vtophys((vm_offset_t) gatt->ag_vdir); - if(bootverbose) + if (bus_dmamap_load(gatt->dmat_vdir, gatt->dmamap_vdir, + (void *)gatt->ag_vdir, AGP_PAGE_SIZE, agp_amd_getaddr_vdir, + gatt, 0) != 0) { + if (bootverbose) + device_printf(dev, + "bus_dmamap_load failed\n"); + goto bad; + } + if(bootverbose) device_printf(dev, "gatt -> ag_pdir %#lx\n", (u_long)gatt->ag_pdir); /* * Allocate the gatt pages */ + bzero(gatt->ag_vdir, AGP_PAGE_SIZE); gatt->ag_entries = entries; if(bootverbose) device_printf(dev, "allocating GATT for %d AGP page entries\n", gatt->ag_entries); - gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual); /* * Map the pages of the GATT into the page directory. @@ -155,7 +213,7 @@ agp_amd_alloc_gatt(device_t dev) vm_offset_t pa; va = ((vm_offset_t) gatt->ag_virtual) + i * AGP_PAGE_SIZE; - pa = vtophys(va); + pa = gatt->ag_physical + i * AGP_PAGE_SIZE; gatt->ag_vdir[i + pdir_offset] = pa | 1; } @@ -165,13 +223,36 @@ agp_amd_alloc_gatt(device_t dev) agp_flush_cache(); return gatt; +bad: + if (gatt->dmamap) { + bus_dmamap_unload(gatt->dmat, gatt->dmamap); + bus_dmamem_free(gatt->dmat, gatt->dmamap, + (void *)gatt->ag_virtual); + } + if (gatt->dmamap_vdir) { + bus_dmamap_unload(gatt->dmat, gatt->dmamap_vdir); + bus_dmamem_free(gatt->dmat, gatt->dmamap_vdir, + (void *)gatt->ag_vdir); + } + if (gatt->dmat) { + bus_dma_tag_destroy(gatt->dmat); + } + if (gatt->dmat_vdir) + bus_dma_tag_destroy(gatt->dmat_vdir); + free(gatt, M_AGP); + return (0); + } static void agp_amd_free_gatt(struct agp_amd_gatt *gatt) { - free(gatt->ag_virtual, M_AGP); - free(gatt->ag_vdir, M_AGP); + bus_dmamap_unload(gatt->dmat, gatt->dmamap); + bus_dmamem_free(gatt->dmat, gatt->dmamap, (void *)gatt->ag_virtual); + bus_dmamap_unload(gatt->dmat, gatt->dmamap_vdir); + bus_dmamem_free(gatt->dmat, gatt->dmamap_vdir, (void *)gatt->ag_vdir); + bus_dma_tag_destroy(gatt->dmat); + bus_dma_tag_destroy(gatt->dmat_vdir); free(gatt, M_AGP); } Index: agp_i810.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp_i810.c,v retrieving revision 1.16 diff -u -p -r1.16 agp_i810.c --- agp_i810.c 21 Jan 2003 08:56:11 -0000 1.16 +++ agp_i810.c 7 Feb 2003 16:31:42 -0000 @@ -43,6 +43,8 @@ #include #include +#include + #include #include #include @@ -200,6 +202,15 @@ agp_i810_probe(device_t dev) return ENXIO; } +static void +agp_i810_getaddr(void *p, bus_dma_segment_t *segs, int nseg, int error) +{ + struct agp_gatt *gatt; + + gatt = (struct agp_gatt *)p; + gatt->ag_physical = segs->ds_addr; +} + static int agp_i810_attach(device_t dev) { @@ -258,18 +269,44 @@ agp_i810_attach(device_t dev) sc->dcache_size = 0; /* According to the specs the gatt on the i810 must be 64k */ - gatt->ag_virtual = contigmalloc( 64 * 1024, M_AGP, 0, - 0, ~0, PAGE_SIZE, 0); - if (!gatt->ag_virtual) { + + if (bus_dma_tag_create(NULL, PAGE_SIZE, 0, + BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, + 64 * 1024, 1, BUS_SPACE_MAXSIZE_32BIT, 0, + &gatt->dmat) != 0) { + free(gatt, M_AGP); + agp_generic_detach(dev); + if (bootverbose) + device_printf(dev, + "bus_dma_tag_create failed\n"); + return (ENOMEM); + } + if (bus_dmamem_alloc(gatt->dmat, (void **)&gatt->ag_virtual, + BUS_DMA_NOWAIT, &gatt->dmamap) != 0) { + bus_dma_tag_destroy(gatt->dmat); + free(gatt, M_AGP); + agp_generic_detach(dev); if (bootverbose) - device_printf(dev, "contiguous allocation failed\n"); + device_printf(dev, + "bus_dmamem_alloc failed\n"); + return (ENOMEM); + } + if (bus_dmamap_load(gatt->dmat, gatt->dmamap, + (void *)gatt->ag_virtual, 64*1024, + agp_i810_getaddr, gatt, 0) != 0) { + bus_dmamem_free(gatt->dmat, gatt->dmamap, + (void *)gatt->ag_virtual); + bus_dma_tag_destroy(gatt->dmat); free(gatt, M_AGP); agp_generic_detach(dev); - return ENOMEM; + if (bootverbose) + device_printf(dev, + "bus_dmamap_load failed\n"); + return (ENOMEM); } + bzero(gatt->ag_virtual, gatt->ag_entries * sizeof(u_int32_t)); - gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual); agp_flush_cache(); /* Install the GATT. */ WRITE4(AGP_I810_PGTBL_CTL, gatt->ag_physical | 1); @@ -341,7 +378,11 @@ agp_i810_detach(device_t dev) AGP_SET_APERTURE(dev, sc->initial_aperture); if ( sc->chiptype == CHIP_I810 ) { - contigfree(sc->gatt->ag_virtual, 64 * 1024, M_AGP); + bus_dmamap_unload(sc->gatt->dmat, sc->gatt->dmamap); + bus_dmamem_free(sc->gatt->dmat, sc->gatt->dmamap, + (void *)sc->gatt->ag_virtual); + bus_dma_tag_destroy(sc->gatt->dmat); + } free(sc->gatt, M_AGP); Index: agp_intel.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp_intel.c,v retrieving revision 1.11 diff -u -p -r1.11 agp_intel.c --- agp_intel.c 11 Jan 2003 20:08:28 -0000 1.11 +++ agp_intel.c 6 Feb 2003 00:55:37 -0000 @@ -38,6 +38,8 @@ #include #include +#include + #include #include #include Index: agp_sis.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp_sis.c,v retrieving revision 1.5 diff -u -p -r1.5 agp_sis.c --- agp_sis.c 13 Nov 2002 17:40:15 -0000 1.5 +++ agp_sis.c 6 Feb 2003 00:55:37 -0000 @@ -38,6 +38,8 @@ #include #include +#include + #include #include #include Index: agp_via.c =================================================================== RCS file: /home/ncvs/src/sys/pci/agp_via.c,v retrieving revision 1.6 diff -u -p -r1.6 agp_via.c --- agp_via.c 13 Nov 2002 17:40:15 -0000 1.6 +++ agp_via.c 6 Feb 2003 00:55:37 -0000 @@ -38,6 +38,8 @@ #include #include +#include + #include #include #include Index: agppriv.h =================================================================== RCS file: /home/ncvs/src/sys/pci/agppriv.h,v retrieving revision 1.3 diff -u -p -r1.3 agppriv.h --- agppriv.h 12 Jul 2000 10:13:04 -0000 1.3 +++ agppriv.h 6 Feb 2003 00:55:37 -0000 @@ -83,6 +83,8 @@ struct agp_gatt { u_int32_t ag_entries; u_int32_t *ag_virtual; vm_offset_t ag_physical; + bus_dma_tag_t dmat; + bus_dmamap_t dmamap; }; void agp_flush_cache(void);