/**************************************************************************************
Copyright (c) 2002 The UbixOS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are prohibited.
$Id$
**************************************************************************************/
#include <ubixos/dma.h>
#include <ubixos/io.h>
#include <ubixos/types.h>
#define lowByte(x) (x & 0x00FF)
#define highByte(x) ((x & 0xFF00) >> 8)
uChar maskReg[8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 };
uChar clearReg[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 };
uChar modeReg[8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 };
uChar addrPort[8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC };
uChar pagePort[8] = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A };
uChar countPort[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE };
void dmaXfer(uChar channel,uLong address,uInt length,uChar read) {
unsigned char page=0, mode=0;
unsigned int offset = 0;
if (read) {
mode = 0x48 + channel;
}
else {
mode = 0x44 + channel;
}
page = address >> 16;
offset = address & 0xFFFF;
length--;
_dmaXfer(channel, page, offset, length, mode);
}
void _dmaXfer(uChar dmaChannel,uChar page,uInt offset,uInt length,uChar mode) {
asm("cli");
outportByte(maskReg[dmaChannel], 0x04 | dmaChannel);
outportByte(clearReg[dmaChannel], 0x00);
outportByte(modeReg[dmaChannel], mode);
outportByte(addrPort[dmaChannel], lowByte(offset));
outportByte(addrPort[dmaChannel], highByte(offset));
outportByte(pagePort[dmaChannel], page);
outportByte(countPort[dmaChannel], lowByte(length));
outportByte(countPort[dmaChannel], highByte(length));
outportByte(maskReg[dmaChannel], dmaChannel);
asm("sti");
}