1 /* $NetBSD: alpha_bus_window.c,v 1.2 2001/07/17 17:46:42 thorpej Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Support for mapping Alpha bus windows. This is currently used to
34 * provide bus space mapping support for XFree86. In a perfect world,
35 * this would go away in favor of a real bus space mapping framework.
38 #include <sys/types.h>
41 #include <machine/sysarch.h>
50 alpha_bus_getwindows(int type
, struct alpha_bus_window
**abwp
)
52 struct alpha_bus_get_window_count_args count_args
;
53 struct alpha_bus_get_window_args window_args
;
54 struct alpha_bus_window
*abw
;
57 count_args
.type
= type
;
58 if (sysarch(ALPHA_BUS_GET_WINDOW_COUNT
, &count_args
) != 0)
61 abw
= malloc(sizeof(*abw
) * count_args
.count
);
64 memset(abw
, 0, sizeof(*abw
) * count_args
.count
);
66 for (i
= 0; i
< count_args
.count
; i
++) {
67 window_args
.type
= type
;
68 window_args
.window
= i
;
69 window_args
.translation
= &abw
[i
].abw_abst
;
70 if (sysarch(ALPHA_BUS_GET_WINDOW
, &window_args
) != 0) {
77 return (count_args
.count
);
81 alpha_bus_mapwindow(struct alpha_bus_window
*abw
)
83 struct alpha_bus_space_translation
*abst
= &abw
->abw_abst
;
88 fd
= open(_PATH_MEM
, O_RDWR
, 0600);
92 size
= ((abst
->abst_bus_end
- abst
->abst_bus_start
) + 1) <<
93 abst
->abst_addr_shift
;
95 addr
= mmap(NULL
, size
, PROT_READ
|PROT_WRITE
, MAP_FILE
|MAP_SHARED
,
96 fd
, (off_t
) abst
->abst_sys_start
);
100 if (addr
== MAP_FAILED
)
103 abw
->abw_addr
= addr
;
104 abw
->abw_size
= size
;
110 alpha_bus_unmapwindow(struct alpha_bus_window
*abw
)
113 (void) munmap(abw
->abw_addr
, abw
->abw_size
);