diff --git a/src/grayspace-misc/gsdefines.h b/src/grayspace-misc/gsdefines.h index 6c4cb14..dd52b00 100755 --- a/src/grayspace-misc/gsdefines.h +++ b/src/grayspace-misc/gsdefines.h @@ -19,6 +19,8 @@ - for now, when I don't care about bit width and hwen I want just an int for example, I will just use 'int' and assume this will be the fastest type for doing math on the host CPU + + $Id$ */ #ifndef _GSDEFINES_H diff --git a/src/sys/include/deviceman/bus.h b/src/sys/include/deviceman/bus.h new file mode 100755 index 0000000..b8a5eb1 --- /dev/null +++ b/src/sys/include/deviceman/bus.h @@ -0,0 +1,20 @@ +/* + "bus.h" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 11, 2002 + + purpose: master header file for all things BUS related + + $Id$ +*/ + +#ifndef _BUS_H +#define _BUS_H + +#include "bus_resources.h" + + + +#endif /* _BUS_H */ \ No newline at end of file diff --git a/src/sys/include/deviceman/bus_resources.h b/src/sys/include/deviceman/bus_resources.h new file mode 100755 index 0000000..181dd5d --- /dev/null +++ b/src/sys/include/deviceman/bus_resources.h @@ -0,0 +1,217 @@ +/* + "bus_resources.h" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 12, 2002 + + purpose: master header file for bus resource management + + $Id$ +*/ + +#ifndef _BUS_RESOURCES_H +#define _BUS_RESOURCES_H + +/* Intel 32-bit architecture */ +#if TCPU_IA32 + +/* DMA channels */ +#define MIN_DMA_CHANNEL (0) +#define MAX_DMA_CHANNEL (7) +#define NUM_DMA_CHANNELS (MAX_DMA_CHANNEL - MIN_DMA_CHANNEL - 1) + +/* IRQs */ +#define MIN_IRQ (0) +#define MAX_IRQ (15) +#define NUM_IRQS (MAX_IRQ - MIN_IRQ - 1) + +/* Port IO Range */ +#define MIN_PORTIO_ADDR (0) +#define MAX_PORTIO_ADDR (1023) +#define MAXBITS_PORTIO_ADDR (10) + +/* NOTE: 'BI_' denotes roughly something related to BUS info */ + +/* for building/use-with device-info/bus-resource-info structures */ +#define BI_NUMBITS_IRQS (4) +#define BI_NUMBITS_DMA_CHANNELS (3) +#define BI_IRQ_BIT (0) +#define BI_DMA_CHANNEL_BIT (BI_IRQ_BIT + BI_NUMBITS_IRQS) + +#define BI_IRQ_MASK\ + MAKEMASK_GS( BI_NUMBITS_IRQS, BI_IRQ_BIT ) +#define BI_DMA_CHANNEL_MASK\ + MAKEMASK_GS( BI_NUMBITS_DMA_CHANNELS, BI_DMA_CHANNEL_BIT ) + +#define BI_NUMBITS_PORTIO_BASEADDR (16) +#define BI_NUMBITS_PORTIO_OVERADDR (16) +#define BI_PORTIO_BASEADDR_BIT (0) +#define BI_PORTIO_OVERADDR_BIT ( BI_PORTIO_BASEADDR_BIT\ + + BI_NUMBITS_PORTIO_BASEADDR ) +#define BI_PORTIO_BASEADDR_MASK\ + MAKEMASK_GS( BI_NUMBITS_PORTIO_BASEADDR, BI_PORTIO_BASEADDR_BIT ) +#define BI_PORTIO_OVERADDR_MASK\ + MAKEMASK_GS( BI_NUMBITS_PORTIO_OVERADDR, BI_PORTIO_OVERADDR_BIT ) + +/* maximum number of DMAs and IRQs a device can use + NOTE: *must* be same */ +#define BI_MAX_DMAANDIRQS (2) +#define BI_MAX_DMAS (BI_MAX_DMAANDIRQS) +#define BI_MAX_IRQS (BI_MAX_DMAANDIRQS) + +/* maximum number of Port IO ranges a device can use */ +#define BI_MAX_PORTIO_RANGES (4) + +/* structure for storing a device's bus resources */ +typedef struct tagBUS_RESOURCES +{ + /* DMA and IRQ info */ + BYTEg a_dmairq[BI_MAX_DMAANDIRQS]; + + /* + bits [0,1] number of IRQs used + bits [2,3] number of DMA channels used + bits [4,7] number of port IO ranges used + */ + BYTEg resource_counts; + + /* Port IO Ranges */ + DWORDg a_portiorange[BI_MAX_PORTIO_RANGES]; +} +BUS_RESOURCES; + +/* NOTE: 'BUS_RES' denotes interface functions/macros on + the 'BUS_RESOURCES' structure */ + +#if (BI_IRQ_BIT == 0) + /* get IRQ 'idx' from resource description 'br' */ + #define BUS_RES_GETIRQ( br, idx ) ((br).a_dmairq[(idx)]&BI_IRQ_MASK) + + /* set IRQ 'idx' in resource description 'br' to 'irq' */ + #define BUS_RES_SETIRQ( br, idx, irq )\ + (br).a_dmairq[(idx)] &= BI_IRQ_MASK;\ + (br).a_dmairq[(idx)] |= (irq) +#else + /* get IRQ 'idx' from resource description 'br' */ + #define BUS_RES_GETIRQ( br, idx )\ + GETBITVAL_GS( (br).a_dmairq[(idx)], BI_IRQ_MASK, BI_IRQ_BIT ) + + /* set IRQ 'idx' in resource description 'br' to 'irq' */ + #define BUS_RES_SETIRQ( br, idx, irq )\ + SETBITVAL_FAST_GS( (br).a_dmairq[(idx)],\ + BI_IRQ_MASK,\ + BI_IRQ_BIT,\ + (irq) ) +#endif + +/* get DMA 'idx' from resource description 'br' */ +#define BUS_RES_GETDMA( br, idx )\ + GETBITVAL_GS( (br).a_dmairq[(idx)], BI_DMA_MASK, BI_DMA_BIT ) + +/* set DMA 'idx' in resource description 'br' to 'dma' */ +#define BUS_RES_SETDMA( br, idx, dma )\ + SETBITVAL_FAST_GS( (br).a_dmairq[(idx)],\ + BI_DMA_MASK,\ + BI_DMA_BIT,\ + (dma) ) + +#if (BI_PORTIO_BASEADDR_BIT == 0) && (BI_PORTIO_OVERADDR_BIT == BI_NUMBITS_PORTIO_BASEADDR ) + /* get port IO base address 'idx' from resource description 'br' */ + #define BUS_RES_GETPORTIOBASE( br, idx )\ + ((br).a_portiorange[(idx)]&BI_PORTIO_BASEADDR_MASK) + + /* get port IO 'over' address 'idx' from resource description 'br' */ + #define BUS_RES_GETPORTIOOVER( br, idx )\ + ((br).a_portiorange[(idx)]>>BI_PORTIO_OVERADDR_BIT) + + /* get port IO range 'idx' from resource description 'br' + into 'baseaddr_o' and 'overaddr_o' */ + #define BUS_RES_GETPORTIORANGE( br, idx, baseaddr_o, overaddr_o )\ + (baseaddr_o)\ + = ((br).a_portiorange[(idx)] & BI_PORTIO_BASEADDR_MASK);\ + (overaddr_o)\ + = ((br).a_portiorange[(idx)] >> BI_PORTIO_OVERADDR_BIT) + + /* set port IO range 'idx' in resource description 'br' + to 'baseaddr' and 'overaddr' */ + #define BUS_RES_SETPORTIORANGE( br, idx, baseaddr, overaddr )\ + ((br).a_portiorange[(idx)]\ + = ((overaddr)<>2) +/* set number of IRQs used/assign-to device */ +#define BUS_RES_SETIRQSUSED( br, irqsused )\ + (br).resource_counts &= ~0x0C;\ + (br).resource_counts |= ((irqsused)<<2) + +/* get number of DMAs used/assign-to device */ +#define BUS_RES_GETDMASUSED( br )\ + ((br).resource_counts & 3) +/* set number of DMAs used/assign-to device */ +#define BUS_RES_SETDMASUSED( br, dmasused )\ + (br).resource_counts &= ~3;\ + (br).resource_counts |= (dmasused) + +/* get number of port IO ranges used/assign-to device */ +#define BUS_RES_GETPORTIORANGESUSED( br )\ + (((br).resource_counts)>>4) +/* get number of port IO ranges used/assign-to device */ +#define BUS_RES_SETPORTIORANGESUSED( br, rangesused )\ + (br).resource_counts &= 0x0F;\ + (br).resource_counts |= ((rangesused)<<4) + +#else /* #if TCPU_IA32 */ + +#error unknown target CPU!!! + +#endif /* #if TCPU_??? */ + +#endif /* _BUS_RESOURCES_H */ \ No newline at end of file diff --git a/src/sys/include/deviceman/bus_resources_portio.h b/src/sys/include/deviceman/bus_resources_portio.h new file mode 100755 index 0000000..59d34d6 --- /dev/null +++ b/src/sys/include/deviceman/bus_resources_portio.h @@ -0,0 +1,47 @@ +/* + "bus_resources_portio.h" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 12, 2002 + + purpose: for port IO resource management + + $Id$ +*/ + +#ifndef _BUS_RESOURCES_PORTIO_H +#define _BUS_RESOURCES_PORTIO_H + +/* for managing port IO ranges */ +typedef struct tagBUS_PORTIO_POOL +{ + DWORDg a_addrs[(1<<(MAXBITS_PORTIO_ADDR-5))]; +} +BUS_PORTIO_POOL; + +/* checks a range of port addresses + returns: + - 1 if the range is comptetely empty + - 0 otherwise */ +int BUS_PORTIO_CheckRange( BUS_PORTIO_POOL * p_bpp, + DWORDg baseaddr, + DWORDg overaddr ); + +/* allocates a range of port addresses + returns: + - 1 on success + - 0 on failure */ +int BUS_PORTIO_AllocateRange( BUS_PORTIO_POOL * p_bpp, + DWORDg baseaddr, + DWORDg overaddr ); + +/* frees a range of port addresses + returns: + - 1 if any port addresses in the range were allocated + - 0 otherwise */ +int BUS_PORTIO_FreeRange( BUS_PORTIO_POOL * p_bpp, + DWORDg baseaddr, + DWORDg overaddr ); + +#endif /* _BUS_RESOURCES_PORTIO_H */ \ No newline at end of file diff --git a/src/sys/include/deviceman/device.h b/src/sys/include/deviceman/device.h new file mode 100755 index 0000000..dde9881 --- /dev/null +++ b/src/sys/include/deviceman/device.h @@ -0,0 +1,88 @@ +/* + "device.h" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 11, 2002 + + purpose: master header file for all things device related + + $Id$ +*/ + +#ifndef _DEVICE_H +#define _DEVICE_H + +// maximum length of a device's name +#define MAX_DEVICE_NAMELEN (16) + +// maximum number of bus devices allowed +#define MAX_BUS_DEVICES (16) + +/* device types (for now, only bus devices allowed) */ +#define DEVICE_TYPE_UNKNOWN (0) +#define DEVICE_TYPE_BUS_ISA (1) +#define DEVICE_TYPE_BUS_PCI (2) + +/* device ISR or pseudo ISR */ +typedef int (* DEVICE_ISR)( void * p ); + +/* device IO routine */ +typedef int (* DEVICE_IO_RTN)( void * p ); + +/* device control routine */ +typedef int (* DEVICE_CTRL_RTN)( void * p ); + +/* ISA bus device structure */ +typedef struct tagDEVICE_ISA +{ + /* bus resources assigned to device */ + BUS_RESOURCES br; + + /* ISRs for device */ + DEVICE_ISR * apfn_isr[BI_MAX_IRQS]; + + /* device IO routine (kernel/driver use only) */ + DEVICE_IO_RTN pfn_io; + + /* device control routine (kernel/driver use only) */ + DEVICE_CTRL_RTN pfn_ctrl; +} +DEVICE_BUS_ISA; + +/* PCI bus device structure */ +/* TODO */ +typedef struct tagDEVICE_BUS_PCI +{ + int dummy; +} +DEVICE_PCI; + +/* bus device structure */ +typedef union tagDEVICE_BUS +{ + DEVICE_BUS_ISA isa; + DEVICE_BUS_PCI pci; +} +DEVICE_BUS; + +/* device structure */ +typedef struct tagDEVICE +{ + /* type of device */ + BYTEg type; + + /* pointer to actual device specific structure */ + void * p; +} +DEVICE; + +/* global kernel structure for device information */ +typedef struct tagDEVICES +{ + /* bus devices */ + DEVICE a_isa[MAX_BUS_DEVICES]; +} +DEVICES; + +#endif /* _DEVICE_H */ \ No newline at end of file diff --git a/src/sys/include/deviceman/isapnp.h b/src/sys/include/deviceman/isapnp.h new file mode 100755 index 0000000..50b8abb --- /dev/null +++ b/src/sys/include/deviceman/isapnp.h @@ -0,0 +1,29 @@ +/* + "isapnp.h" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 12, 2002 + + Purpose: ISA PNP support + + $Id$ +*/ + +#ifndef _ISAPNP_H +#define _ISAPNP_H + +#define ACCESS_FUNC_PORT "movl %edx, $0x279\n\t" +#define ACCESS_DATA_PORT "movl %edx, $0x2A9\n\t" +#define FUNC_SETREADPORT "movb $0x00, %al\n\toutb %dx, %al\n\t" +#define FUNC_ISOLATION "movb $0x01, %al\n\toutb %dx, %al\n\t" +#define FUNC_CONFIGCONTROL "movb $0x02, %al\n\toutb %dx, %al\n\t" +#define FUNC_WAKEUP "movb $0x03, %al\n\toutb %dx, %al\n\t" +#define FUNC_RESOURCEDATA "movb $0x04, %al\n\toutb %dx, %al\n\t" +#define FUNC_STATUS "movb $0x05, %al\n\toutb %dx, %al\n\t" +#define FUNC_SETCARDNUM "movb $0x06, %al\n\toutb %dx, %al\n\t" +#define FUNC_SETDEVICENUM "movb $0x07, %al\n\toutb %dx, %al\n\t" +#define FUNC_ACTIVATEADDR "movb $0x1E, %al\n\toutb %dx, %al\n\t" +#define FUNC_IORANGECHECK "movb $0x1F, %al\n\toutb %dx, %al\n\t" + +#endif // _ISAPNP_H \ No newline at end of file diff --git a/src/sys/include/misc/misc_bit_array.h b/src/sys/include/misc/misc_bit_array.h new file mode 100755 index 0000000..2906148 --- /dev/null +++ b/src/sys/include/misc/misc_bit_array.h @@ -0,0 +1,46 @@ +/* + "misc_bit_array.h" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 12, 2002 + + purpose: functions for dealing with bit arrays + + $Id$ +*/ + +#ifndef _MISC_BIT_ARRAY_H +#define _MISC_BIT_ARRAY_H + +typedef struct tagBIT_ARRAY_RANGE_PARAMS +{ + DWORDg * p_curdw; + DWORDg * p_firstdw; + DWORDg * p_overdw; + DWORDg premask; + DWORDg postmask; +} +BIT_ARRAY_RANGE_PARAMS; + +// returns: +// - 1 if the given range of bits is empty +// - 0 otherwise +int BIT_ARRAY_IsRangeEmpty( BIT_ARRAY_RANGE_PARAMS * p_rp ); + +// set the given range of bits to all 1s +void BIT_ARRAY_SetRange( BIT_ARRAY_RANGE_PARAMS * p_rp ); + +// set the given range of bits to all 0s +void BIT_ARRAY_ResetRange( BIT_ARRAY_RANGE_PARAMS * p_rp ); + +// builds a structure for use with the other functions +#define BIT_ARRAY_MAKERANGEPARAMS( rp, p_basedw, firstbit, overbit )\ + (rp).premask = ((32-(firstbit))&31);\ + (rp).p_firstdw = (p_basedw) + ((firstbit)>>5);\ + (rp).postmask = ((overbit)&31);\ + (rp).p_overdw = (p_basedw) + ((overbit)>>5);\ + (rp).premask = MAKEMASK_GS( (rp).premask, (32 - (rp).premask) );\ + (rp).postmask = MAKEMASK_GS( (rp).postmask, 0 ) + +#endif // _MISC_BIT_ARRAY_H \ No newline at end of file