os161-1.99
 All Data Structures
lamebus.h
00001 /*
00002  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _LAMEBUS_H_
00031 #define _LAMEBUS_H_
00032 
00033 #include <cpu.h>
00034 #include <spinlock.h>
00035 
00036 /*
00037  * Linear Always Mapped Extents
00038  *
00039  * Machine-independent definitions.
00040  */
00041 
00042 
00043 /* Vendors */
00044 #define LB_VENDOR_CS161      1
00045 
00046 /* CS161 devices */
00047 #define LBCS161_BUSCTL       1
00048 #define LBCS161_TIMER        2
00049 #define LBCS161_DISK         3
00050 #define LBCS161_SERIAL       4
00051 #define LBCS161_SCREEN       5
00052 #define LBCS161_NET          6
00053 #define LBCS161_EMUFS        7
00054 #define LBCS161_TRACE        8
00055 #define LBCS161_RANDOM       9
00056 
00057 /* LAMEbus controller always goes in slot 31 */
00058 #define LB_CONTROLLER_SLOT   31
00059 
00060 /* Number of slots */
00061 #define LB_NSLOTS            32
00062 
00063 /* LAMEbus controller per-slot config space */
00064 #define LB_CONFIG_SIZE       1024
00065 
00066 /* LAMEbus controller per-cpu control space */
00067 #define LB_CTLCPU_SIZE       1024
00068 
00069 /* LAMEbus controller slot offset to per-cpu control space */
00070 #define LB_CTLCPU_OFFSET     32768
00071 
00072 /* LAMEbus mapping size per slot */
00073 #define LB_SLOT_SIZE         65536
00074 
00075 /* Pointer to kind of function called on interrupt */
00076 typedef void (*lb_irqfunc)(void *devdata);
00077 
00078 /*
00079  * Driver data
00080  */
00081 struct lamebus_softc {
00082         struct spinlock ls_lock;
00083 
00084         /* Accessed from interrupts; synchronized with ls_lock */ 
00085         uint32_t     ls_slotsinuse;
00086         void        *ls_devdata[LB_NSLOTS];
00087         lb_irqfunc   ls_irqfuncs[LB_NSLOTS];
00088 };
00089 
00090 /*
00091  * Allocate and set up a lamebus_softc for the system.
00092  */
00093 struct lamebus_softc *lamebus_init(void);
00094 
00095 /*
00096  * Search for and create cpu structures for the CPUs on the mainboard.
00097  */
00098 void lamebus_find_cpus(struct lamebus_softc *lamebus);
00099 
00100 /*
00101  * Start up secondary CPUs.
00102  */
00103 void lamebus_start_cpus(struct lamebus_softc *lamebus);
00104 
00105 /*
00106  * Look for a not-in-use slot containing a device whose vendor and device 
00107  * ids match those provided, and whose version is in the range between
00108  * lowver and highver, inclusive.
00109  *
00110  * Returns a slot number (0-31) or -1 if no such device is found.
00111  */
00112 int lamebus_probe(struct lamebus_softc *, 
00113                   uint32_t vendorid, uint32_t deviceid, 
00114                   uint32_t lowver, uint32_t highver);
00115 
00116 /*
00117  * Mark a slot in-use (that is, has a device driver attached to it),
00118  * or unmark it. It is a fatal error to mark a slot that is already 
00119  * in use, or unmark a slot that is not in use.
00120  */
00121 void lamebus_mark(struct lamebus_softc *, int slot);
00122 void lamebus_unmark(struct lamebus_softc *, int slot);
00123 
00124 /*
00125  * Attach to an interrupt.
00126  */
00127 void lamebus_attach_interrupt(struct lamebus_softc *, int slot,
00128                               void *devdata, 
00129                               void (*irqfunc)(void *devdata));
00130 /*
00131  * Detach from interrupt.
00132  */
00133 void lamebus_detach_interrupt(struct lamebus_softc *, int slot);
00134 
00135 /*
00136  * Mask/unmask an interrupt.
00137  */
00138 void lamebus_mask_interrupt(struct lamebus_softc *, int slot);
00139 void lamebus_unmask_interrupt(struct lamebus_softc *, int slot);
00140 
00141 /*
00142  * Function to call to handle a LAMEbus interrupt.
00143  */
00144 void lamebus_interrupt(struct lamebus_softc *);
00145 
00146 /*
00147  * Have the LAMEbus controller power the system off.
00148  */
00149 void lamebus_poweroff(struct lamebus_softc *);
00150 
00151 /*
00152  * Ask the bus controller how much memory we have.
00153  */
00154 size_t lamebus_ramsize(void);
00155 
00156 /*
00157  * Turn on or off the inter-processor interrupt line to a CPU.
00158  */
00159 void lamebus_assert_ipi(struct lamebus_softc *, struct cpu *targetcpu);
00160 void lamebus_clear_ipi(struct lamebus_softc *, struct cpu *targetcpu);
00161 
00162 /*
00163  * Read/write 32-bit register at offset OFFSET within slot SLOT.
00164  * (Machine dependent.)
00165  */
00166 uint32_t lamebus_read_register(struct lamebus_softc *, int slot,
00167                                uint32_t offset);
00168 void lamebus_write_register(struct lamebus_softc *, int slot,
00169                             uint32_t offset, uint32_t val);
00170 
00171 /*
00172  * Map a buffer that starts at offset OFFSET within slot SLOT.
00173  */
00174 void *lamebus_map_area(struct lamebus_softc *, int slot,
00175                        uint32_t offset);
00176 
00177 
00178 #endif /* _LAMEBUS_H_ */
 All Data Structures