/*1* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _LAMEBUS_H_30#define _LAMEBUS_H_3132#include <cpu.h>33#include <spinlock.h>3435/*36* Linear Always Mapped Extents37*38* Machine-independent definitions.39*/404142/* Vendors */43#define LB_VENDOR_CS161 14445/* CS161 devices */46#define LBCS161_BUSCTL 147#define LBCS161_TIMER 248#define LBCS161_DISK 349#define LBCS161_SERIAL 450#define LBCS161_SCREEN 551#define LBCS161_NET 652#define LBCS161_EMUFS 753#define LBCS161_TRACE 854#define LBCS161_RANDOM 95556/* LAMEbus controller always goes in slot 31 */57#define LB_CONTROLLER_SLOT 315859/* Number of slots */60#define LB_NSLOTS 326162/* LAMEbus controller per-slot config space */63#define LB_CONFIG_SIZE 10246465/* LAMEbus controller per-cpu control space */66#define LB_CTLCPU_SIZE 10246768/* LAMEbus controller slot offset to per-cpu control space */69#define LB_CTLCPU_OFFSET 327687071/* LAMEbus mapping size per slot */72#define LB_SLOT_SIZE 655367374/* Pointer to kind of function called on interrupt */75typedef void (*lb_irqfunc)(void *devdata);7677/*78* Driver data79*/80struct lamebus_softc {81struct spinlock ls_lock;8283/* Accessed from interrupts; synchronized with ls_lock */84uint32_t ls_slotsinuse;85void *ls_devdata[LB_NSLOTS];86lb_irqfunc ls_irqfuncs[LB_NSLOTS];87};8889/*90* Allocate and set up a lamebus_softc for the system.91*/92struct lamebus_softc *lamebus_init(void);9394/*95* Search for and create cpu structures for the CPUs on the mainboard.96*/97void lamebus_find_cpus(struct lamebus_softc *lamebus);9899/*100* Start up secondary CPUs.101*/102void lamebus_start_cpus(struct lamebus_softc *lamebus);103104/*105* Look for a not-in-use slot containing a device whose vendor and device106* ids match those provided, and whose version is in the range between107* lowver and highver, inclusive.108*109* Returns a slot number (0-31) or -1 if no such device is found.110*/111int lamebus_probe(struct lamebus_softc *,112uint32_t vendorid, uint32_t deviceid,113uint32_t lowver, uint32_t highver);114115/*116* Mark a slot in-use (that is, has a device driver attached to it),117* or unmark it. It is a fatal error to mark a slot that is already118* in use, or unmark a slot that is not in use.119*/120void lamebus_mark(struct lamebus_softc *, int slot);121void lamebus_unmark(struct lamebus_softc *, int slot);122123/*124* Attach to an interrupt.125*/126void lamebus_attach_interrupt(struct lamebus_softc *, int slot,127void *devdata,128void (*irqfunc)(void *devdata));129/*130* Detach from interrupt.131*/132void lamebus_detach_interrupt(struct lamebus_softc *, int slot);133134/*135* Mask/unmask an interrupt.136*/137void lamebus_mask_interrupt(struct lamebus_softc *, int slot);138void lamebus_unmask_interrupt(struct lamebus_softc *, int slot);139140/*141* Function to call to handle a LAMEbus interrupt.142*/143void lamebus_interrupt(struct lamebus_softc *);144145/*146* Have the LAMEbus controller power the system off.147*/148void lamebus_poweroff(struct lamebus_softc *);149150/*151* Ask the bus controller how much memory we have.152*/153size_t lamebus_ramsize(void);154155/*156* Turn on or off the inter-processor interrupt line to a CPU.157*/158void lamebus_assert_ipi(struct lamebus_softc *, struct cpu *targetcpu);159void lamebus_clear_ipi(struct lamebus_softc *, struct cpu *targetcpu);160161/*162* Read/write 32-bit register at offset OFFSET within slot SLOT.163* (Machine dependent.)164*/165uint32_t lamebus_read_register(struct lamebus_softc *, int slot,166uint32_t offset);167void lamebus_write_register(struct lamebus_softc *, int slot,168uint32_t offset, uint32_t val);169170/*171* Map a buffer that starts at offset OFFSET within slot SLOT.172*/173void *lamebus_map_area(struct lamebus_softc *, int slot,174uint32_t offset);175176177#endif /* _LAMEBUS_H_ */178179180