xref: /netbsd/sys/arch/vax/vax/bus_mem.c (revision bf9ec67e)
1 /*	$NetBSD: bus_mem.c,v 1.9 2001/09/16 20:39:02 ragge Exp $ */
2 /*
3  * Copyright (c) 1998 Matt Thomas
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Ludd by Bertram Barth.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed at Ludd, University of
19  *	Lule}, Sweden and its contributors.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/device.h>
38 #include <sys/kernel.h>
39 #include <sys/systm.h>
40 
41 #include <uvm/uvm_extern.h>
42 
43 #include <machine/cpu.h>
44 #include <machine/pmap.h>
45 #include <machine/bus.h>
46 #include <machine/intr.h>
47 
48 static int
49 vax_mem_bus_space_map(
50 	void *t,
51 	bus_addr_t pa,
52 	bus_size_t size,
53 	int cacheable,
54 	bus_space_handle_t *bshp,
55 	int f2)
56 {
57 	vaddr_t va;
58 
59 	size += (pa & VAX_PGOFSET);	/* have to include the byte offset */
60 	va = uvm_km_valloc(kernel_map, size);
61 	if (va == 0)
62 		return (ENOMEM);
63 
64 	*bshp = (bus_space_handle_t)(va + (pa & VAX_PGOFSET));
65 
66 	ioaccess(va, pa, (size + VAX_NBPG - 1) >> VAX_PGSHIFT);
67 
68 	return 0;
69 }
70 
71 static int
72 vax_mem_bus_space_subregion(
73 	void *t,
74 	bus_space_handle_t h,
75 	bus_size_t o,
76 	bus_size_t s,
77 	bus_space_handle_t *hp)
78 {
79 	*hp = h + o;
80 	return (0);
81 }
82 
83 static void
84 vax_mem_bus_space_unmap(
85 	void *t,
86 	bus_space_handle_t h,
87 	bus_size_t size,
88 	int f)
89 {
90 	u_long va = trunc_page(h);
91 	u_long endva = round_page(h + size);
92 
93         /*
94          * Free the kernel virtual mapping.
95          */
96 	iounaccess(va, size >> VAX_PGSHIFT);
97 	uvm_km_free(kernel_map, va, endva - va);
98 }
99 
100 static int
101 vax_mem_bus_space_alloc(
102 	void *t,
103 	bus_addr_t rs,
104 	bus_addr_t re,
105 	bus_size_t s,
106 	bus_size_t a,
107 	bus_size_t b,
108 	int f,
109 	bus_addr_t *ap,
110 	bus_space_handle_t *hp)
111 {
112 	panic("vax_mem_bus_alloc not implemented");
113 }
114 
115 static void
116 vax_mem_bus_space_free(
117 	void *t,
118 	bus_space_handle_t h,
119 	bus_size_t s)
120 {
121 	panic("vax_mem_bus_free not implemented");
122 }
123 
124 static paddr_t
125 vax_mem_bus_space_mmap(void *v, bus_addr_t addr, off_t off, int prot, int flags)
126 {
127 	bus_addr_t rv;
128 
129 	rv = addr + off;
130 	return btop(rv);
131 }
132 
133 struct vax_bus_space vax_mem_bus_space = {
134 	NULL,
135 	vax_mem_bus_space_map,
136 	vax_mem_bus_space_unmap,
137 	vax_mem_bus_space_subregion,
138 	vax_mem_bus_space_alloc,
139 	vax_mem_bus_space_free,
140 	vax_mem_bus_space_mmap,
141 };
142