luxos/Kernel/drivers/dma/dma.c

112 lines
2.6 KiB
C
Raw Permalink Normal View History

/*
* dma.c
*
* Created on: Aug 20, 2011
* Author: Tiberiu
*/
#include <stdio.h>
#include "dma.h"
void DmaSetAddress (uint8 channel, uint8 low, uint8 high)
{
uint16 port = 0;
switch (channel)
{
case 0: port = DmaRegisterChannel0Address; break;
case 1: port = DmaRegisterChannel1Address; break;
case 2: port = DmaRegisterChannel2Address; break;
case 3: port = DmaRegisterChannel3Address; break;
case 4: port = DmaRegisterChannel4Address; break;
case 5: port = DmaRegisterChannel5Address; break;
case 6: port = DmaRegisterChannel6Address; break;
case 7: port = DmaRegisterChannel7Address; break;
default: return;
}
outportb(port, low); iowait();
outportb(port, high);
}
void DmaSetCount (uint8 channel, uint8 low, uint8 high)
{
uint16 port = 0;
switch (channel)
{
case 0: port = DmaRegisterChannel0Count; break;
case 1: port = DmaRegisterChannel1Count; break;
case 2: port = DmaRegisterChannel2Count; break;
case 3: port = DmaRegisterChannel3Count; break;
case 4: port = DmaRegisterChannel4Count; break;
case 5: port = DmaRegisterChannel5Count; break;
case 6: port = DmaRegisterChannel6Count; break;
case 7: port = DmaRegisterChannel7Count; break;
default: return;
}
outportb(port, low); iowait();
outportb(port, high);
}
void DmaSetExternalPageRegisters (uint8 channel, uint8 val)
{
uint16 port = 0;
switch (channel)
{
case 1: port = DmaRegisterChannel1PageAddress; break;
case 2: port = DmaRegisterChannel2PageAddress; break;
case 3: port = DmaRegisterChannel3PageAddress; break;
case 5: port = DmaRegisterChannel5PageAddress; break;
case 6: port = DmaRegisterChannel6PageAddress; break;
case 7: port = DmaRegisterChannel7PageAddress; break;
default: return;
}
outportb(port, val);
}
void DmaResetFlipFlop (uint8 channel)
{
uint16 port = (channel < 4) ? DmaRegisterFlipFlopReset : 2*DmaRegisterFlipFlopReset+0xC0;
outportb(port, 0);
}
void DmaReset ()
{
outportb(DmaRegisterMasterReset, 0);
}
void DmaUnmaskAll()
{
outportb(DmaRegisterMaskReset, 0);
}
void DmaMaskChannel(uint8 channel)
{
if (channel >= 8) return;
uint16 port = (channel < 4) ? (DmaRegisterSingleChannelMask) : (2*DmaRegisterSingleChannelMask + 0xC0);
outportb(port, channel%4 | 4);
}
void DmaUnmaskChannel (uint8 channel)
{
if (channel >= 8) return;
uint16 port = (channel < 4) ? (DmaRegisterSingleChannelMask) : (2*DmaRegisterSingleChannelMask + 0xC0);
outportb(port, channel%4);
}
void DmaSetMode (uint8 channel, uint8 mode)
{
if (channel >= 8) return;
uint16 port = (channel < 4) ? (DmaRegisterMode) : (2*DmaRegisterMode + 0xC0);
DmaMaskChannel(channel);
outportb(port, (channel%4) | mode );
DmaUnmaskAll();
}