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