xref: /netbsd-src/sys/arch/ia64/ia64/bus_space.c (revision 1e72df6a037fdd3c6d3014a2679ffff7daab84ca)
1 /*	$NetBSD: bus_space.c,v 1.2 2019/12/15 16:48:26 tsutsui Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9  * Simulation Facility, NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.2 2019/12/15 16:48:26 tsutsui Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 
39 #include <machine/bus.h>
40 
41 
42 int
ia64_bus_space_map(bus_space_tag_t t,bus_addr_t addr,bus_size_t size,int flags,bus_space_handle_t * bshp)43 ia64_bus_space_map(bus_space_tag_t t, bus_addr_t addr,
44     bus_size_t size, int flags, bus_space_handle_t *bshp)
45 {
46 	if (t == IA64_BUS_SPACE_IO) {
47 		if (addr > 0xffff)
48 			return 1;
49 		*bshp = addr;
50 	} else {
51 		/* t == IA64_BUS_SPACE_MEM */
52 
53 		if (flags & BUS_SPACE_MAP_CACHEABLE)
54 			*bshp = addr + IA64_RR_BASE(7);
55 		else
56 			*bshp = addr + IA64_RR_BASE(6);
57 	}
58 
59 	return 0;
60 }
61 
62 void
ia64_bus_space_unmap(bus_space_tag_t t,bus_space_handle_t bsh,bus_size_t size)63 ia64_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
64     bus_size_t size)
65 {
66 	/* nop */
67 }
68 
69 int
ia64_bus_space_subregion(bus_space_tag_t t,bus_space_handle_t bsh,bus_size_t offset,bus_size_t size,bus_space_handle_t * bshp)70 ia64_bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
71     bus_size_t offset, bus_size_t size, bus_space_handle_t *bshp)
72 {
73 	*bshp = bsh + offset;
74 	return 0;
75 }
76 
77 paddr_t
ia64_bus_space_mmap(bus_space_tag_t t,bus_addr_t addr,off_t offset,int prot,int flags)78 ia64_bus_space_mmap(bus_space_tag_t t, bus_addr_t addr, off_t offset,
79     int prot, int flags)
80 {
81 	/* Can't mmap I/O space */
82 	if (t == IA64_BUS_SPACE_IO)
83 		return -1;
84 
85 	return addr + offset;
86 }
87 
88 int
ia64_bus_space_alloc(bus_space_tag_t t,bus_addr_t reg_start,bus_addr_t reg_end,bus_size_t size,bus_size_t alignment,bus_size_t boundary,int flags,bus_addr_t * addrp,bus_space_handle_t * bshp)89 ia64_bus_space_alloc(bus_space_tag_t t, bus_addr_t reg_start,
90     bus_addr_t reg_end, bus_size_t size, bus_size_t alignment,
91     bus_size_t boundary, int flags, bus_addr_t *addrp, bus_space_handle_t *bshp)
92 {
93 	bus_addr_t addr;
94 
95 	addr = (reg_start + PAGE_SIZE - 1) & ~PAGE_MASK;
96 
97 	if ((addr % alignment) == 0) {
98 		*addrp = addr;
99 		*bshp = (bus_space_handle_t)addr;
100 		return 0;
101 	} else {
102 		return 1;
103 	}
104 }
105 
106 void
ia64_bus_space_free(bus_space_tag_t t,bus_space_handle_t handle,bus_size_t size)107 ia64_bus_space_free(bus_space_tag_t t, bus_space_handle_t handle,
108     bus_size_t size)
109 {
110 	/* nop */
111 }
112