Module Name:    src
Committed By:   riastradh
Date:           Sun Sep  8 16:19:15 UTC 2013

Modified Files:
        src/sys/external/bsd/drm2/include/linux [riastradh-drm2]: io-mapping.h

Log Message:
Just use bus_space_map for io-mapping, and limit to one at a time.

Reserving the whole region interferes with other parts of the driver
which want to map it in different ways.  It also horrifically wastes
space when actually mapped, because there's no way to map a subregion
of a reservation.  And the bus_space_reservation API is x86-only at
the moment.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 \
    src/sys/external/bsd/drm2/include/linux/io-mapping.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/include/linux/io-mapping.h
diff -u src/sys/external/bsd/drm2/include/linux/io-mapping.h:1.1.2.2 src/sys/external/bsd/drm2/include/linux/io-mapping.h:1.1.2.3
--- src/sys/external/bsd/drm2/include/linux/io-mapping.h:1.1.2.2	Wed Jul 24 03:17:48 2013
+++ src/sys/external/bsd/drm2/include/linux/io-mapping.h	Sun Sep  8 16:19:15 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: io-mapping.h,v 1.1.2.2 2013/07/24 03:17:48 riastradh Exp $	*/
+/*	$NetBSD: io-mapping.h,v 1.1.2.3 2013/09/08 16:19:15 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -36,19 +36,13 @@
 #include <sys/kmem.h>
 #include <sys/systm.h>
 
-/*
- * XXX This uses NetBSD bus space reservations, which are currently
- * implemented only for x86.
- */
-
 struct io_mapping {
 	bus_space_tag_t		diom_bst;
 	bus_addr_t		diom_addr;
-	bus_addr_t		diom_size;
+	bus_size_t		diom_size;
 	int			diom_flags;
-	bus_space_reservation_t	diom_bsr;
-	bool			diom_mapped;
 	bus_space_handle_t	diom_bsh;
+	void			*diom_vaddr;
 };
 
 static inline struct io_mapping *
@@ -63,13 +57,15 @@ bus_space_io_mapping_create_wc(bus_space
 	mapping->diom_flags = 0;
 	mapping->diom_flags |= BUS_SPACE_MAP_LINEAR;
 	mapping->diom_flags |= BUS_SPACE_MAP_PREFETCHABLE;
-	mapping->diom_mapped = false;
+	mapping->diom_vaddr = NULL;
 
-	if (bus_space_reserve(mapping->diom_bst, addr, size,
-		mapping->diom_flags, &mapping->diom_bsr)) {
+	bus_space_handle_t bsh;
+	if (bus_space_map(mapping->diom_bst, addr, PAGE_SIZE,
+		mapping->diom_flags, &bsh)) {
 		kmem_free(mapping, sizeof(*mapping));
 		return NULL;
 	}
+	bus_space_unmap(mapping->diom_bst, bsh, PAGE_SIZE);
 
 	return mapping;
 }
@@ -78,8 +74,7 @@ static inline void
 io_mapping_free(struct io_mapping *mapping)
 {
 
-	KASSERT(!mapping->diom_mapped);
-	bus_space_release(mapping->diom_bst, &mapping->diom_bsr);
+	KASSERT(mapping->diom_vaddr == NULL);
 	kmem_free(mapping, sizeof(*mapping));
 }
 
@@ -87,25 +82,24 @@ static inline void *
 io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset)
 {
 
-	KASSERT(!mapping->diom_mapped);
+	KASSERT(mapping->diom_vaddr == NULL);
 	KASSERT(ISSET(mapping->diom_flags, BUS_SPACE_MAP_LINEAR));
-	if (bus_space_reservation_map(mapping->diom_bst, &mapping->diom_bsr,
-		mapping->diom_flags, &mapping->diom_bsh))
+	if (bus_space_map(mapping->diom_bst, (mapping->diom_addr + offset),
+		PAGE_SIZE, mapping->diom_flags, &mapping->diom_bsh))
 		panic("Unable to make I/O mapping!"); /* XXX */
-	mapping->diom_mapped = true;
+	mapping->diom_vaddr = bus_space_vaddr(mapping->diom_bst,
+	    mapping->diom_bsh);
 
-	return (char *)bus_space_vaddr(mapping->diom_bst, mapping->diom_bsh)
-	    + offset;		/* XXX arithmetic overflow */
+	return mapping->diom_vaddr;
 }
 
 static inline void
 io_mapping_unmap(struct io_mapping *mapping, void *vaddr __unused)
 {
 
-	KASSERT(mapping->diom_mapped);
-	bus_space_reservation_unmap(mapping->diom_bst, mapping->diom_bsh,
-	    mapping->diom_size);
-	mapping->diom_mapped = false;
+	KASSERT(mapping->diom_vaddr == vaddr);
+	bus_space_unmap(mapping->diom_bst, mapping->diom_bsh, PAGE_SIZE);
+	mapping->diom_vaddr = NULL;
 }
 
 static inline void *

Reply via email to