xref: /openbsd-src/sys/arch/amd64/pci/agp_machdep.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: agp_machdep.c,v 1.14 2015/03/14 03:38:46 jsg Exp $	*/
2 
3 /*
4  * Copyright (c) 2008 - 2009 Owain G. Ainsworth <oga@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 /*
19  * Copyright (c) 2002 Michael Shalayeff
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the above copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
32  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
35  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
41  * THE POSSIBILITY OF SUCH DAMAGE.
42  */
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/malloc.h>
47 #include <sys/rwlock.h>
48 
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pcireg.h>
51 #include <dev/pci/pcidevs.h>
52 
53 #include <uvm/uvm_extern.h>
54 
55 #include <machine/cpufunc.h>
56 #include <machine/bus.h>
57 #include <machine/pmap.h>
58 
59 void
60 agp_flush_cache(void)
61 {
62 	wbinvd();
63 }
64 
65 void
66 agp_flush_cache_range(vaddr_t va, vsize_t sz)
67 {
68 	pmap_flush_cache(va, sz);
69 }
70 
71 struct agp_map {
72 	bus_space_tag_t		bst;
73 	bus_space_handle_t	bsh;
74 	bus_size_t		size;
75 };
76 
77 int
78 agp_init_map(bus_space_tag_t tag, bus_addr_t address, bus_size_t size,
79     int flags, struct agp_map **mapp)
80 {
81 	struct agp_map	*map;
82 	int		 err;
83 
84 	map = malloc(sizeof(*map), M_AGP, M_WAITOK | M_CANFAIL);
85 	if (map == NULL)
86 		return (ENOMEM);
87 
88 	map->bst = tag;
89 	map->size = size;
90 
91 	if ((err = bus_space_map(tag, address, size, flags, &map->bsh)) != 0) {
92 		free(map, M_AGP, sizeof(*map));
93 		return (err);
94 	}
95 	*mapp = map;
96 	return (0);
97 }
98 
99 void
100 agp_destroy_map(struct agp_map *map)
101 {
102 	bus_space_unmap(map->bst, map->bsh, map->size);
103 	free(map, M_AGP, sizeof(*map));
104 }
105 
106 
107 int
108 agp_map_subregion(struct agp_map *map, bus_size_t offset, bus_size_t size,
109     bus_space_handle_t *bshp)
110 {
111 	return (bus_space_subregion(map->bst, map->bsh, offset, size, bshp));
112 }
113 
114 void
115 agp_unmap_subregion(struct agp_map *map, bus_space_handle_t bsh,
116     bus_size_t size)
117 {
118 	/* subregion doesn't need unmapping, do nothing */
119 }
120 
121 void
122 agp_map_atomic(struct agp_map *map, bus_size_t offset,
123     bus_space_handle_t *bshp)
124 {
125 	agp_map_subregion(map, offset, PAGE_SIZE, bshp);
126 }
127 
128 void
129 agp_unmap_atomic(struct agp_map *map, bus_space_handle_t bsh)
130 {
131 	/* subregion doesn't need unmapping, do nothing */
132 }
133