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