| 1 | /* $NetBSD: rbus.h,v 1.11 2009/12/15 22:17:12 snj Exp $ */ |
| 2 | |
| 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 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 20 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 24 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 25 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef _DEV_CARDBUS_RBUS_H_ |
| 30 | #define _DEV_CARDBUS_RBUS_H_ |
| 31 | |
| 32 | /* |
| 33 | * This file defines the rbus (pseudo) class |
| 34 | * |
| 35 | * What is rbus? |
| 36 | * |
| 37 | * The rbus is a recursive bus-space administrator. This means a |
| 38 | * parent bus-space administrator, which usually belongs to a bus |
| 39 | * bridge, makes some child bus-space administrators and gives |
| 40 | * (restricted) bus-space to the children. There is a root bus-space |
| 41 | * administrator which maintains the whole bus-space. |
| 42 | * |
| 43 | * Why recursive? |
| 44 | * |
| 45 | * The recursive bus-space administration has two virtues. The |
| 46 | * former is this modelling matches the actual memory and io space |
| 47 | * management of bridge devices well. The latter is that the rbus is a |
| 48 | * distributed management system, so it matches well with a |
| 49 | * multi-thread kernel. |
| 50 | * |
| 51 | * Abstraction |
| 52 | * |
| 53 | * The rbus models bus-to-bus bridges into three types: dedicated, shared, |
| 54 | * and slave. Dedicated means that the bridge has dedicated bus space. |
| 55 | * Shared means that the bridge has bus space, but this bus space is |
| 56 | * shared with other bus bridges. Slave means a bus bridge which |
| 57 | * does not have it own bus space and asks a parent bus bridge for bus |
| 58 | * space when a client requests bus space from the bridge. |
| 59 | */ |
| 60 | |
| 61 | |
| 62 | /* require sys/extent.h */ |
| 63 | /* require sys/bus.h */ |
| 64 | |
| 65 | #define rbus 1 |
| 66 | |
| 67 | |
| 68 | struct extent; |
| 69 | |
| 70 | |
| 71 | /* |
| 72 | * General rule |
| 73 | * |
| 74 | * 1) When a rbustag has no space for child (it means rb_extent is |
| 75 | * NULL), ask bus-space for parent through rb_parent. |
| 76 | * |
| 77 | * 2) When a rbustag has its own space (whether shared or dedicated), |
| 78 | * allocate from rb_ext. |
| 79 | */ |
| 80 | struct rbustag { |
| 81 | bus_space_tag_t rb_bt; |
| 82 | struct rbustag *rb_parent; |
| 83 | struct extent *rb_ext; |
| 84 | bus_addr_t rb_start; |
| 85 | bus_addr_t rb_end; |
| 86 | bus_addr_t rb_offset; |
| 87 | #if notyet |
| 88 | int (*rb_space_alloc)(struct rbustag *, bus_addr_t, bus_addr_t, |
| 89 | bus_addr_t, bus_size_t, bus_addr_t, bus_addr_t, |
| 90 | int, bus_addr_t *, bus_space_handle_t *); |
| 91 | int (*rbus_space_free)(struct rbustag *, bus_space_handle_t, |
| 92 | bus_size_t, bus_addr_t *); |
| 93 | #endif |
| 94 | int rb_flags; |
| 95 | #define RBUS_SPACE_INVALID 0x00 |
| 96 | #define RBUS_SPACE_SHARE 0x01 |
| 97 | #define RBUS_SPACE_DEDICATE 0x02 |
| 98 | #define RBUS_SPACE_MASK 0x03 |
| 99 | #define RBUS_SPACE_ASK_PARENT 0x04 |
| 100 | /* your own data below */ |
| 101 | void *rb_md; |
| 102 | }; |
| 103 | |
| 104 | typedef struct rbustag *rbus_tag_t; |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | /* |
| 110 | * These functions sugarcoat rbus interface to make rbus being used |
| 111 | * easier. These functions should be member functions of rbus |
| 112 | * `class'. |
| 113 | */ |
| 114 | int rbus_space_alloc(rbus_tag_t, bus_addr_t, bus_size_t, bus_addr_t, |
| 115 | bus_addr_t, int, bus_addr_t *, bus_space_handle_t *); |
| 116 | |
| 117 | int rbus_space_alloc_subregion(rbus_tag_t, bus_addr_t, bus_addr_t, |
| 118 | bus_addr_t, bus_size_t, bus_addr_t, bus_addr_t, int, |
| 119 | bus_addr_t *, bus_space_handle_t *); |
| 120 | |
| 121 | int rbus_space_free(rbus_tag_t, bus_space_handle_t, bus_size_t, |
| 122 | bus_addr_t *); |
| 123 | |
| 124 | |
| 125 | /* |
| 126 | * These functions create rbus instance. These functions are |
| 127 | * so-called-as a constructor of rbus. |
| 128 | * |
| 129 | * rbus_new is a constructor which make an rbus instance from a parent |
| 130 | * rbus. |
| 131 | */ |
| 132 | rbus_tag_t rbus_new(rbus_tag_t, bus_addr_t, bus_size_t, bus_addr_t, int); |
| 133 | |
| 134 | rbus_tag_t rbus_new_root_delegate(bus_space_tag_t, bus_addr_t, bus_size_t, |
| 135 | bus_addr_t); |
| 136 | rbus_tag_t rbus_new_root_share(bus_space_tag_t, struct extent *, |
| 137 | bus_addr_t, bus_size_t, bus_addr_t); |
| 138 | |
| 139 | /* |
| 140 | * This function release bus-space used by the argument. This |
| 141 | * function is so-called-as a destructor. |
| 142 | */ |
| 143 | int rbus_delete(rbus_tag_t); |
| 144 | |
| 145 | |
| 146 | /* |
| 147 | * Machine-dependent definitions. |
| 148 | */ |
| 149 | #include <machine/rbus_machdep.h> |
| 150 | |
| 151 | #endif /* !_DEV_CARDBUS_RBUS_H_ */ |
| 152 | |