X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdrv%2Fdma.c;h=56ab7e54db2f583b0ce2f8f9aafd3f0715ec7b22;hb=a928d1d2a70761eece125cdbe9950ec0b1112ce3;hp=0fae172bf709c33f535c21753fba51690ba924bd;hpb=15e56ad3bfa5a55e213fb4e70e05d398523d3bcd;p=tpg%2Facess2.git diff --git a/Kernel/drv/dma.c b/Kernel/drv/dma.c index 0fae172b..56ab7e54 100644 --- a/Kernel/drv/dma.c +++ b/Kernel/drv/dma.c @@ -2,7 +2,8 @@ * AcessOS 1.0 * DMA Driver */ -#include +#include +#include #define DMA_SIZE (0x2400) #define DMA_ADDRESS(c) ((c)*DMA_SIZE+0x500) //Save Space for IDT and BDA @@ -11,11 +12,19 @@ #define HIB(x) (((x)>>8)&0xFF) #define HIW(x) (((x)>>16)&0xFFFF) -typedef struct { - int mode; +// === TYPES === +typedef struct +{ + int mode; char *address; } t_dmaChannel; +// === PROTOTYPES === + int DMA_Install(char **Arguments); +void DMA_SetChannel(int Channel, int length, int read); + int DMA_ReadData(int channel, int count, void *buffer); + +// === CONSTANTS === const Uint8 cMASKPORT [8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 }; const Uint8 cMODEPORT [8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 }; const Uint8 cCLEARPORT[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 }; @@ -23,16 +32,19 @@ const Uint8 cPAGEPORT [8] = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A }; const Uint8 cADDRPORT [8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC }; const Uint8 cCOUNTPORT[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE }; +// === GLOBALS === +MODULE_DEFINE(0, 0x0100, ISADMA, DMA_Install, NULL, NULL); char *dma_addresses[8]; t_dmaChannel dma_channels[8]; +// === CODE === /** - * \fn void DMA_Install() + * \fn int DMA_Install(void) * \brief Initialise DMA channels */ -void DMA_Install() +int DMA_Install(char **Arguments) { - int i; + Uint i; for(i=8;i--;) { outb( cMASKPORT[i], 0x04 | (i & 0x3) ); // mask channel @@ -49,32 +61,33 @@ void DMA_Install() dma_channels[i].mode = 0; dma_addresses[i] = (char*)DMA_ADDRESS(i); - dma_addresses[i] += 0xC0000000; + dma_addresses[i] += KERNEL_BASE; } + return MODULE_ERR_OK; } /** - * \fn void DMA_SetChannel(int channel, int length, int read) + * \fn void DMA_SetChannel(int Channel, int length, int read) * \brief Set DMA Channel Length and RW */ -void DMA_SetChannel(int channel, int length, int read) +void DMA_SetChannel(int Channel, int length, int read) { - channel &= 7; - read = read && 1; + Uint chan = Channel & 7; + read = !!read; if(length > DMA_SIZE) length = DMA_SIZE; length --; //Adjust for DMA //__asm__ __volatile__ ("cli"); - outb( cMASKPORT[channel], 0x04 | (channel & 0x3) ); // mask channel - outb( cCLEARPORT[channel], 0x00 ); - outb( cMODEPORT[channel], (0x44 + (!read)*4) | (channel & 0x3) ); - outb( cADDRPORT[channel], LOWB(DMA_ADDRESS(channel)) ); // send address - outb( cADDRPORT[channel], HIB(DMA_ADDRESS(channel)) ); // send address - outb( cPAGEPORT[channel], HIW(DMA_ADDRESS(channel)) ); // send page - outb( cCOUNTPORT[channel], LOWB(length) ); // send size - outb( cCOUNTPORT[channel], HIB(length) ); // send size - outb( cMASKPORT[channel], channel & 0x3 ); // unmask channel - dma_addresses[channel] = (char*)DMA_ADDRESS(channel); - dma_addresses[channel] += 0xC0000000; + outb( cMASKPORT[chan], 0x04 | (chan & 0x3) ); // mask channel + outb( cCLEARPORT[chan], 0x00 ); + outb( cMODEPORT[chan], (0x44 + (!read)*4) | (chan & 0x3) ); + outb( cADDRPORT[chan], LOWB(DMA_ADDRESS(chan)) ); // send address + outb( cADDRPORT[chan], HIB(DMA_ADDRESS(chan)) ); // send address + outb( cPAGEPORT[chan], HIW(DMA_ADDRESS(chan)) ); // send page + outb( cCOUNTPORT[chan], LOWB(length) ); // send size + outb( cCOUNTPORT[chan], HIB(length) ); // send size + outb( cMASKPORT[chan], chan & 0x3 ); // unmask channel + dma_addresses[chan] = (char*)DMA_ADDRESS(chan); + dma_addresses[chan] += KERNEL_BASE; //__asm__ __volatile__ ("sti"); } @@ -92,3 +105,19 @@ int DMA_ReadData(int channel, int count, void *buffer) memcpy(buffer, dma_addresses[channel], count); return 0; } + +/** + * \fn void DMA_WriteData(int channel, int count, void *buffer) + * \brief Write data to a DMA buffer + */ +int DMA_WriteData(int channel, int count, void *buffer) +{ + if(channel < 0 || channel > 7) + return -1; + if(count < 0 || count > DMA_SIZE) + return -2; + + memcpy(dma_addresses[channel], buffer, count); + + return 0; +}