summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2010-05-10 22:06:05 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2010-05-10 22:06:05 +0000
commitd9d23b0b11c7a51da943ddc4f3f8830d25a9a736 (patch)
tree3212c1bf78d2c943e10fb1278f71eda2c0b01090 /sys/arch
parent3904221c8b5efb0b07a4c465b2c0f8131e09fe2a (diff)
Continue with the horrible habit of using agp_machdep.c for agp related MD
things that there really isn't a decent api for elsewhere. Since on recent intel IGPs the gtt aperture is too big (256meg is not uncommon) to be mapped on a kva-constrained arch like i386, introduce an agp mapping api that does things depending on arch. On amd64 which can afford the space (and will use the direct mapping again soon)just do bus_space_map() on init, then parcels things out using bus_space_subregion(), thus avoiding map/unmap overhead on every call (this is how inteldrm does things right now). On i386, we do bus_space_map() and bus_space_unmap as appropriate. Linux has some tricks here involving ``atomic'' maps that are on only one cpu and that you may not sleep with to avoid the ipi overhead for tlb flushing. For now we don't go down that route but it is being considered. I am also considering if it is worth abstracting this a little more, improving the api and making it a general MD interface. Tested by myself on i386 and amd64 and by drahn@ (who has one of the machines with an aperture that is too big) on i386.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/amd64/pci/agp_machdep.c55
-rw-r--r--sys/arch/i386/pci/agp_machdep.c96
2 files changed, 149 insertions, 2 deletions
diff --git a/sys/arch/amd64/pci/agp_machdep.c b/sys/arch/amd64/pci/agp_machdep.c
index 5e320e95293..94a94d5fdb7 100644
--- a/sys/arch/amd64/pci/agp_machdep.c
+++ b/sys/arch/amd64/pci/agp_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: agp_machdep.c,v 1.5 2010/04/08 01:26:44 oga Exp $ */
+/* $OpenBSD: agp_machdep.c,v 1.6 2010/05/10 22:06:04 oga Exp $ */
/*
* Copyright (c) 2008 - 2009 Owain G. Ainsworth <oga@openbsd.org>
@@ -174,6 +174,59 @@ agp_bus_dma_set_alignment(bus_dma_tag_t tag, bus_dmamap_t dmam,
sg_dmamap_set_alignment(tag, dmam, alignment);
}
+struct agp_map {
+ bus_space_tag_t bst;
+ bus_space_handle_t bsh;
+ bus_size_t size;
+};
+
+int
+agp_init_map(bus_space_tag_t tag, bus_addr_t address, bus_size_t size,
+ int flags, struct agp_map **mapp)
+{
+ struct agp_map *map;
+ int err;
+
+ map = malloc(sizeof(*map), M_AGP, M_WAITOK | M_CANFAIL);
+ if (map == NULL)
+ return (ENOMEM);
+
+ map->bst = tag;
+ map->size = size;
+
+ if ((err = bus_space_map(tag, address, size, flags, &map->bsh)) != 0) {
+ free(map, M_AGP);
+ return (err);
+ }
+ *mapp = map;
+ return (0);
+}
+
+void
+agp_destroy_map(struct agp_map *map)
+{
+ bus_space_unmap(map->bst, map->bsh, map->size);
+ free(map, M_AGP);
+}
+
+
+int
+agp_map_subregion(struct agp_map *map, bus_size_t offset, bus_size_t size,
+ bus_space_handle_t *bshp)
+{
+ if (offset > map->size || size > map->size || offset + size > map->size)
+ return (EINVAL);
+ return (bus_space_subregion(map->bst, map->bsh, offset, size, bshp));
+
+}
+
+void
+agp_unmap_subregion(struct agp_map *map, bus_space_handle_t bsh,
+ bus_size_t size)
+{
+ /* subregion doesn't need unmapping, do nothing */
+}
+
/*
* ick ick ick. However, the rest of this driver is supposedly MI (though
* they only exist on x86), so this can't be in dev/pci.
diff --git a/sys/arch/i386/pci/agp_machdep.c b/sys/arch/i386/pci/agp_machdep.c
index e63e00cc243..e6eaa41a00c 100644
--- a/sys/arch/i386/pci/agp_machdep.c
+++ b/sys/arch/i386/pci/agp_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: agp_machdep.c,v 1.11 2010/04/08 01:26:44 oga Exp $ */
+/* $OpenBSD: agp_machdep.c,v 1.12 2010/05/10 22:06:04 oga Exp $ */
/*
* Copyright (c) 2008 - 2009 Owain G. Ainsworth <oga@openbsd.org>
@@ -174,6 +174,100 @@ agp_bus_dma_set_alignment(bus_dma_tag_t tag, bus_dmamap_t dmam,
sg_dmamap_set_alignment(tag, dmam, alignment);
}
+struct agp_map {
+ bus_space_tag_t bst;
+ bus_addr_t addr;
+ bus_size_t size;
+ int flags;
+};
+
+extern struct extent *ioport_ex;
+extern struct extent *iomem_ex;
+
+int
+agp_init_map(bus_space_tag_t tag, bus_addr_t address, bus_size_t size,
+ int flags, struct agp_map **mapp)
+{
+ struct extent *ex;
+ struct agp_map *map;
+ int error;
+
+ switch (tag) {
+ case I386_BUS_SPACE_IO:
+ ex = ioport_ex;
+ if (flags & BUS_SPACE_MAP_LINEAR)
+ return (EINVAL);
+ break;
+
+ case I386_BUS_SPACE_MEM:
+ ex = iomem_ex;
+ break;
+
+ default:
+ panic("agp_init_map: bad bus space tag");
+ }
+ /*
+ * We grab the extent out of the bus region ourselves
+ * so we don't need to do these allocations every time.
+ */
+ error = extent_alloc_region(ex, address, size,
+ EX_NOWAIT | EX_MALLOCOK);
+ if (error)
+ return (error);
+
+ map = malloc(sizeof(*map), M_AGP, M_WAITOK | M_CANFAIL);
+ if (map == NULL)
+ return (ENOMEM);
+
+ map->bst = tag;
+ map->addr = address;
+ map->size = size;
+ map->flags = flags;
+
+ *mapp = map;
+ return (0);
+}
+
+void
+agp_destroy_map(struct agp_map *map)
+{
+ struct extent *ex;
+
+ switch (map->bst) {
+ case I386_BUS_SPACE_IO:
+ ex = ioport_ex;
+ break;
+
+ case I386_BUS_SPACE_MEM:
+ ex = iomem_ex;
+ break;
+
+ default:
+ panic("agp_destroy_map: bad bus space tag");
+ }
+
+ if (extent_free(ex, map->addr, map->size,
+ EX_NOWAIT | EX_MALLOCOK ))
+ printf("agp_destroy_map: can't free region\n");
+ free(map, M_AGP);
+}
+
+
+int
+agp_map_subregion(struct agp_map *map, bus_size_t offset, bus_size_t size,
+ bus_space_handle_t *bshp)
+{
+ return (_bus_space_map(map->bst, map->addr + offset, size,
+ map->flags, bshp));
+}
+
+void
+agp_unmap_subregion(struct agp_map *map, bus_space_handle_t bsh,
+ bus_size_t size)
+{
+ return (_bus_space_unmap(map->bst, bsh, size, NULL));
+}
+
/*
* ick ick ick. However, the rest of this driver is supposedly MI (though
* they only exist on x86), so this can't be in dev/pci.