rbus.h revision 1.1 1 /*
2 * Copyright (c) 1999
3 * HAYAKAWA Koichi. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the author.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32 /* $Id: rbus.h,v 1.1 1999/10/15 06:07:25 haya Exp $ */
33
34 /*
35 * This file defines rbus (pseudo) class
36 *
37 * What is rbus?
38 *
39 * Ths rbus is a recursive bus-space administrator. This means a
40 * parent bus-space administrator, which usually belongs to a bus
41 * bridge, makes some child bus-space administorators and gives
42 * (restricted) bus-space for children. There are a root bus-space
43 * administrator which maintains whole bus-space.
44 *
45 * Why recursive?
46 *
47 * The recursive bus-space administration has two virtues. The
48 * former is this modelling matches the actual memory and io space
49 * management of bridge devices well. The latter is the rbus is
50 * distributed management system, so it matches well with
51 * multi-thread kernel.
52 *
53 * Abstraction
54 *
55 * The rbus models bus-to-bus bridge into three way: dedicate, share
56 * and slave. Dedicate means that the bridge has dedicate bus space.
57 * Share means that the bridge has bus space, but this bus space is
58 * shared with other bus bridges. Slave means the bus bridge which
59 * does not have it own bus space and ask a parent bus bridge for bus
60 * space when a client requests bus space to the bridge.
61 */
62
63
64 #if !defined SYS_DEV_CARDBUS_RBUS_H
65 #define SYS_DEV_CARDBUS_RBUS_H
66
67 /* require sys/extent.h */
68 /* require machine/bus.h */
69
70 #define rbus 1
71
72
73 struct extent;
74
75
76 /*
77 * General rule
78 *
79 * 1) When a rbustag has no space for child (it means rb_extent is
80 * NULL), ask bus-space for parent through rb_parent.
81 *
82 * 2) When a rbustag has its own space (whether shared or dedicated),
83 * allocate from rb_ext.
84 */
85 struct rbustag {
86 bus_space_tag_t rb_bt;
87 struct rbustag *rb_parent;
88 struct extent *rb_ext;
89 bus_addr_t rb_start;
90 bus_addr_t rb_end;
91 bus_addr_t rb_offset;
92 #if notyet
93 int (*rb_space_alloc) __P((struct rbustag *,
94 bus_addr_t start, bus_addr_t end,
95 bus_addr_t addr, bus_size_t size,
96 bus_addr_t mask, bus_addr_t align,
97 int flags,
98 bus_addr_t *addrp, bus_space_handle_t *bshp));
99 int (*rbus_space_free) __P((struct rbustag *, bus_space_handle_t,
100 bus_size_t size, bus_addr_t *addrp));
101 #endif
102 int rb_flags;
103 #define RBUS_SPACE_INVALID 0x00
104 #define RBUS_SPACE_SHARE 0x01
105 #define RBUS_SPACE_DEDICATE 0x02
106 #define RBUS_SPACE_MASK 0x03
107 #define RBUS_SPACE_ASK_PARENT 0x04
108 /* your own data below */
109 void *rb_md;
110 };
111
112 typedef struct rbustag *rbus_tag_t;
113
114
115
116
117 /*
118 * These functions sugarcoat rbus interface to make rbus being used
119 * easier. These functions should be member functions of rbus
120 * `class'.
121 */
122 int rbus_space_alloc __P((rbus_tag_t,
123 bus_addr_t addr, bus_size_t size, bus_addr_t mask,
124 bus_addr_t align, int flags,
125 bus_addr_t *addrp, bus_space_handle_t *bshp));
126
127 int rbus_space_alloc_subregion __P((rbus_tag_t,
128 bus_addr_t start, bus_addr_t end,
129 bus_addr_t addr, bus_size_t size,
130 bus_addr_t mask, bus_addr_t align,
131 int flags,
132 bus_addr_t *addrp, bus_space_handle_t *bshp));
133
134 int rbus_space_free __P((rbus_tag_t, bus_space_handle_t, bus_size_t size,
135 bus_addr_t *addrp));
136
137
138 /*
139 * These functions create rbus instance. These functions are
140 * so-called-as a constructor of rbus.
141 *
142 * rbus_new is a constructor which make an rbus instance from a parent
143 * rbus.
144 */
145 rbus_tag_t rbus_new __P((rbus_tag_t parent, bus_addr_t start, bus_size_t size,
146 bus_addr_t offset, int flags));
147
148 rbus_tag_t rbus_new_root_delegate __P((bus_space_tag_t, bus_addr_t, bus_size_t,
149 bus_addr_t offset));
150 rbus_tag_t rbus_new_root_share __P((bus_space_tag_t, struct extent *,
151 bus_addr_t, bus_size_t,bus_addr_t offset));
152
153 /*
154 * This function release bus-space used by the argument. This
155 * function is so-called-as a destructor.
156 */
157 int rbus_delete __P((rbus_tag_t));
158
159
160 /*
161 * Machine-dependent definitions.
162 */
163 #include <machine/rbus_machdep.h>
164
165 #endif /* SYS_DEV_CARDBUS_RBUS_H */
166