summaryrefslogtreecommitdiff
path: root/sys/arch/amd64/pci
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/amd64/pci
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/amd64/pci')
-rw-r--r--sys/arch/amd64/pci/agp_machdep.c55
1 files changed, 54 insertions, 1 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.