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