/*
 * isa_dma.h
 *
 * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <common.h>

#define ISA_DMA_MEM_START 0x200000
#define ISA_DMA_MEM_END 0x280000
#define ISA_DMA_MEM_ALIGNMENT 0x10000
#define ISA_DMA_MEM_BLOCKS ((ISA_DMA_MEM_END - ISA_DMA_MEM_START) / ISA_DMA_MEM_ALIGNMENT)

#define ISA_DMA_MASK_ON (1 << 2)

#define ISA_DMA_SAR(x) (((x) < 4) ? ((x) << 1) : (0xC0 + (((x) - 4) << 2)))
#define ISA_DMA_CNT(x) (((x) < 4) ? (((x) << 1) + 1) : (0xC2 + (((x) - 4) << 2)))
#define ISA_DMA_FIRST_PAR(x) (((x) == 0) ? 0x87 : (((x) == 1) ? 0x83 : (0x7F + (x))))
#define ISA_DMA_PAR(x) (((x) < 4) ? ISA_DMA_FIRST_PAR(x) : (ISA_DMA_FIRST_PAR((x) - 4) | 0x08))
#define ISA_DMA_STATUS_REG(x) (((x) < 4) ? 0x08 : 0xD0)
#define ISA_DMA_COMMAND_REG(x) (((x) < 4) ? 0x08 : 0xD0)
#define ISA_DMA_SINGLE_MASK_REG(x) (((x) < 4) ? 0x0A : 0xD4)
#define ISA_DMA_MODE_REG(x) (((x) < 4) ? 0x0B : 0xD6)
#define ISA_DMA_FF_RESET_REG(x) (((x) < 4) ? 0x0C : 0xD8)
#define ISA_DMA_MASTER_RESET_REG(x) (((x) < 4) ? 0x0D : 0xDA)
#define ISA_DMA_MASK_RESET_REG(x) (((x) < 4) ? 0x0E : 0xDC)
#define ISA_DMA_MULTI_MASK_REG(x) (((x) < 4) ? 0x0F : 0xDE)

void *isa_dma_alloc(void);
void isa_dma_free(void *dma_buffer);
void isa_dma_read(dword_t channel, void *buffer, word_t count);
void isa_dma_write(dword_t channel, void *buffer, dword_t count);
