8 #define DMA_SIZE (0x2400)
\r
9 #define DMA_ADDRESS(c) ((c)*DMA_SIZE+0x500) //Save Space for IDT and BDA
\r
11 #define LOWB(x) ((x)&0xFF)
\r
12 #define HIB(x) (((x)>>8)&0xFF)
\r
13 #define HIW(x) (((x)>>16)&0xFFFF)
\r
22 // === PROTOTYPES ===
\r
23 int DMA_Install(char **Arguments);
\r
24 void DMA_SetChannel(int Channel, int length, int read);
\r
25 int DMA_ReadData(int channel, int count, void *buffer);
\r
27 // === CONSTANTS ===
\r
28 const Uint8 cMASKPORT [8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 };
\r
29 const Uint8 cMODEPORT [8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 };
\r
30 const Uint8 cCLEARPORT[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 };
\r
31 const Uint8 cPAGEPORT [8] = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A };
\r
32 const Uint8 cADDRPORT [8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC };
\r
33 const Uint8 cCOUNTPORT[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE };
\r
36 MODULE_DEFINE(0, 0x0100, ISADMA, DMA_Install, NULL, NULL);
\r
37 char *dma_addresses[8];
\r
38 t_dmaChannel dma_channels[8];
\r
42 * \brief Initialise DMA channels
\r
43 * \param Arguments Arguments passed at boot time
\r
45 int DMA_Install(char **Arguments)
\r
50 outb( cMASKPORT[i], 0x04 | (i & 0x3) ); // mask channel
\r
51 outb( cCLEARPORT[i], 0x00 );
\r
52 outb( cMODEPORT[i], 0x48 | (i & 0x3) ); //Read Flag
\r
53 outb( 0xd8, 0xff); //Reset Flip-Flop
\r
54 outb( cADDRPORT[i], LOWB(DMA_ADDRESS(i)) ); // send address
\r
55 outb( cADDRPORT[i], HIB(DMA_ADDRESS(i)) ); // send address
\r
56 outb( 0xd8, 0xff); //Reset Flip-Flop
\r
57 outb( cCOUNTPORT[i], LOWB(DMA_SIZE) ); // send size
\r
58 outb( cCOUNTPORT[i], HIB(DMA_SIZE) ); // send size
\r
59 outb( cPAGEPORT[i], LOWB(HIW(DMA_ADDRESS(i))) ); // send page
\r
60 outb( cMASKPORT[i], i & 0x3 ); // unmask channel
\r
62 dma_channels[i].mode = 0;
\r
63 dma_addresses[i] = (char*)DMA_ADDRESS(i);
\r
64 dma_addresses[i] += KERNEL_BASE;
\r
66 return MODULE_ERR_OK;
\r
70 * \fn void DMA_SetChannel(int Channel, int length, int read)
\r
71 * \brief Set DMA Channel Length and RW
\r
73 void DMA_SetChannel(int Channel, int length, int read)
\r
75 Uint chan = Channel & 7;
\r
77 if(length > DMA_SIZE) length = DMA_SIZE;
\r
78 length --; //Adjust for DMA
\r
79 //__asm__ __volatile__ ("cli");
\r
80 outb( cMASKPORT[chan], 0x04 | (chan & 0x3) ); // mask channel
\r
81 outb( cCLEARPORT[chan], 0x00 );
\r
82 outb( cMODEPORT[chan], (0x44 + (!read)*4) | (chan & 0x3) );
\r
83 outb( cADDRPORT[chan], LOWB(DMA_ADDRESS(chan)) ); // send address
\r
84 outb( cADDRPORT[chan], HIB(DMA_ADDRESS(chan)) ); // send address
\r
85 outb( cPAGEPORT[chan], HIW(DMA_ADDRESS(chan)) ); // send page
\r
86 outb( cCOUNTPORT[chan], LOWB(length) ); // send size
\r
87 outb( cCOUNTPORT[chan], HIB(length) ); // send size
\r
88 outb( cMASKPORT[chan], chan & 0x3 ); // unmask channel
\r
89 dma_addresses[chan] = (char*)DMA_ADDRESS(chan);
\r
90 dma_addresses[chan] += KERNEL_BASE;
\r
91 //__asm__ __volatile__ ("sti");
\r
95 * \fn void DMA_ReadData(int channel, int count, void *buffer)
\r
96 * \brief Read data from a DMA buffer
\r
98 int DMA_ReadData(int channel, int count, void *buffer)
\r
100 if(channel < 0 || channel > 7)
\r
102 if(count < 0 || count > DMA_SIZE)
\r
104 //LogF("memcpy(*0x%x, dma_channels[channel].address, count)\n", buffer
\r
105 memcpy(buffer, dma_addresses[channel], count);
\r
110 * \fn void DMA_WriteData(int channel, int count, void *buffer)
\r
111 * \brief Write data to a DMA buffer
\r
113 int DMA_WriteData(int channel, int count, void *buffer)
\r
115 if(channel < 0 || channel > 7)
\r
117 if(count < 0 || count > DMA_SIZE)
\r
120 memcpy(dma_addresses[channel], buffer, count);
\r