/*1* include/asm-alpha/dma.h2*3* This is essentially the same as the i386 DMA stuff, as the AlphaPCs4* use ISA-compatible dma. The only extension is support for high-page5* registers that allow to set the top 8 bits of a 32-bit DMA address.6* This register should be written last when setting up a DMA address7* as this will also enable DMA across 64 KB boundaries.8*/910/* $Id: dma.h,v 1.7 1992/12/14 00:29:34 root Exp root $11* linux/include/asm/dma.h: Defines for using and allocating dma channels.12* Written by Hennus Bergman, 1992.13* High DMA channel support & info by Hannu Savolainen14* and John Boyd, Nov. 1992.15*/1617#ifndef _ASM_DMA_H18#define _ASM_DMA_H1920#include <linux/spinlock.h>21#include <asm/io.h>2223#define dma_outb outb24#define dma_inb inb2526/*27* NOTES about DMA transfers:28*29* controller 1: channels 0-3, byte operations, ports 00-1F30* controller 2: channels 4-7, word operations, ports C0-DF31*32* - ALL registers are 8 bits only, regardless of transfer size33* - channel 4 is not used - cascades 1 into 2.34* - channels 0-3 are byte - addresses/counts are for physical bytes35* - channels 5-7 are word - addresses/counts are for physical words36* - transfers must not cross physical 64K (0-3) or 128K (5-7) boundaries37* - transfer count loaded to registers is 1 less than actual count38* - controller 2 offsets are all even (2x offsets for controller 1)39* - page registers for 5-7 don't use data bit 0, represent 128K pages40* - page registers for 0-3 use bit 0, represent 64K pages41*42* DMA transfers are limited to the lower 16MB of _physical_ memory.43* Note that addresses loaded into registers must be _physical_ addresses,44* not logical addresses (which may differ if paging is active).45*46* Address mapping for channels 0-3:47*48* A23 ... A16 A15 ... A8 A7 ... A0 (Physical addresses)49* | ... | | ... | | ... |50* | ... | | ... | | ... |51* | ... | | ... | | ... |52* P7 ... P0 A7 ... A0 A7 ... A053* | Page | Addr MSB | Addr LSB | (DMA registers)54*55* Address mapping for channels 5-7:56*57* A23 ... A17 A16 A15 ... A9 A8 A7 ... A1 A0 (Physical addresses)58* | ... | \ \ ... \ \ \ ... \ \59* | ... | \ \ ... \ \ \ ... \ (not used)60* | ... | \ \ ... \ \ \ ... \61* P7 ... P1 (0) A7 A6 ... A0 A7 A6 ... A062* | Page | Addr MSB | Addr LSB | (DMA registers)63*64* Again, channels 5-7 transfer _physical_ words (16 bits), so addresses65* and counts _must_ be word-aligned (the lowest address bit is _ignored_ at66* the hardware level, so odd-byte transfers aren't possible).67*68* Transfer count (_not # bytes_) is limited to 64K, represented as actual69* count - 1 : 64K => 0xFFFF, 1 => 0x0000. Thus, count is always 1 or more,70* and up to 128K bytes may be transferred on channels 5-7 in one operation.71*72*/7374#define MAX_DMA_CHANNELS 87576/*77ISA DMA limitations on Alpha platforms,7879These may be due to SIO (PCI<->ISA bridge) chipset limitation, or80just a wiring limit.81*/8283/* The maximum address for ISA DMA transfer on Alpha XL, due to an84hardware SIO limitation, is 64MB.85*/86#define ALPHA_XL_MAX_ISA_DMA_ADDRESS 0x04000000UL8788/* The maximum address for ISA DMA transfer on RUFFIAN,89due to an hardware SIO limitation, is 16MB.90*/91#define ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS 0x01000000UL9293/* The maximum address for ISA DMA transfer on SABLE, and some ALCORs,94due to an hardware SIO chip limitation, is 2GB.95*/96#define ALPHA_SABLE_MAX_ISA_DMA_ADDRESS 0x80000000UL97#define ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS 0x80000000UL9899/*100Maximum address for all the others is the complete 32-bit bus101address space.102*/103#define ALPHA_MAX_ISA_DMA_ADDRESS 0x100000000UL104105#ifdef CONFIG_ALPHA_GENERIC106# define MAX_ISA_DMA_ADDRESS (alpha_mv.max_isa_dma_address)107#else108# if defined(CONFIG_ALPHA_XL)109# define MAX_ISA_DMA_ADDRESS ALPHA_XL_MAX_ISA_DMA_ADDRESS110# elif defined(CONFIG_ALPHA_RUFFIAN)111# define MAX_ISA_DMA_ADDRESS ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS112# elif defined(CONFIG_ALPHA_SABLE)113# define MAX_ISA_DMA_ADDRESS ALPHA_SABLE_MAX_ISA_DMA_ADDRESS114# elif defined(CONFIG_ALPHA_ALCOR)115# define MAX_ISA_DMA_ADDRESS ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS116# else117# define MAX_ISA_DMA_ADDRESS ALPHA_MAX_ISA_DMA_ADDRESS118# endif119#endif120121/* If we have the iommu, we don't have any address limitations on DMA.122Otherwise (Nautilus, RX164), we have to have 0-16 Mb DMA zone123like i386. */124#define MAX_DMA_ADDRESS (alpha_mv.mv_pci_tbi ? \125~0UL : IDENT_ADDR + 0x01000000)126127/* 8237 DMA controllers */128#define IO_DMA1_BASE 0x00 /* 8 bit slave DMA, channels 0..3 */129#define IO_DMA2_BASE 0xC0 /* 16 bit master DMA, ch 4(=slave input)..7 */130131/* DMA controller registers */132#define DMA1_CMD_REG 0x08 /* command register (w) */133#define DMA1_STAT_REG 0x08 /* status register (r) */134#define DMA1_REQ_REG 0x09 /* request register (w) */135#define DMA1_MASK_REG 0x0A /* single-channel mask (w) */136#define DMA1_MODE_REG 0x0B /* mode register (w) */137#define DMA1_CLEAR_FF_REG 0x0C /* clear pointer flip-flop (w) */138#define DMA1_TEMP_REG 0x0D /* Temporary Register (r) */139#define DMA1_RESET_REG 0x0D /* Master Clear (w) */140#define DMA1_CLR_MASK_REG 0x0E /* Clear Mask */141#define DMA1_MASK_ALL_REG 0x0F /* all-channels mask (w) */142#define DMA1_EXT_MODE_REG (0x400 | DMA1_MODE_REG)143144#define DMA2_CMD_REG 0xD0 /* command register (w) */145#define DMA2_STAT_REG 0xD0 /* status register (r) */146#define DMA2_REQ_REG 0xD2 /* request register (w) */147#define DMA2_MASK_REG 0xD4 /* single-channel mask (w) */148#define DMA2_MODE_REG 0xD6 /* mode register (w) */149#define DMA2_CLEAR_FF_REG 0xD8 /* clear pointer flip-flop (w) */150#define DMA2_TEMP_REG 0xDA /* Temporary Register (r) */151#define DMA2_RESET_REG 0xDA /* Master Clear (w) */152#define DMA2_CLR_MASK_REG 0xDC /* Clear Mask */153#define DMA2_MASK_ALL_REG 0xDE /* all-channels mask (w) */154#define DMA2_EXT_MODE_REG (0x400 | DMA2_MODE_REG)155156#define DMA_ADDR_0 0x00 /* DMA address registers */157#define DMA_ADDR_1 0x02158#define DMA_ADDR_2 0x04159#define DMA_ADDR_3 0x06160#define DMA_ADDR_4 0xC0161#define DMA_ADDR_5 0xC4162#define DMA_ADDR_6 0xC8163#define DMA_ADDR_7 0xCC164165#define DMA_CNT_0 0x01 /* DMA count registers */166#define DMA_CNT_1 0x03167#define DMA_CNT_2 0x05168#define DMA_CNT_3 0x07169#define DMA_CNT_4 0xC2170#define DMA_CNT_5 0xC6171#define DMA_CNT_6 0xCA172#define DMA_CNT_7 0xCE173174#define DMA_PAGE_0 0x87 /* DMA page registers */175#define DMA_PAGE_1 0x83176#define DMA_PAGE_2 0x81177#define DMA_PAGE_3 0x82178#define DMA_PAGE_5 0x8B179#define DMA_PAGE_6 0x89180#define DMA_PAGE_7 0x8A181182#define DMA_HIPAGE_0 (0x400 | DMA_PAGE_0)183#define DMA_HIPAGE_1 (0x400 | DMA_PAGE_1)184#define DMA_HIPAGE_2 (0x400 | DMA_PAGE_2)185#define DMA_HIPAGE_3 (0x400 | DMA_PAGE_3)186#define DMA_HIPAGE_4 (0x400 | DMA_PAGE_4)187#define DMA_HIPAGE_5 (0x400 | DMA_PAGE_5)188#define DMA_HIPAGE_6 (0x400 | DMA_PAGE_6)189#define DMA_HIPAGE_7 (0x400 | DMA_PAGE_7)190191#define DMA_MODE_READ 0x44 /* I/O to memory, no autoinit, increment, single mode */192#define DMA_MODE_WRITE 0x48 /* memory to I/O, no autoinit, increment, single mode */193#define DMA_MODE_CASCADE 0xC0 /* pass thru DREQ->HRQ, DACK<-HLDA only */194195#define DMA_AUTOINIT 0x10196197extern spinlock_t dma_spin_lock;198199static __inline__ unsigned long claim_dma_lock(void)200{201unsigned long flags;202spin_lock_irqsave(&dma_spin_lock, flags);203return flags;204}205206static __inline__ void release_dma_lock(unsigned long flags)207{208spin_unlock_irqrestore(&dma_spin_lock, flags);209}210211/* enable/disable a specific DMA channel */212static __inline__ void enable_dma(unsigned int dmanr)213{214if (dmanr<=3)215dma_outb(dmanr, DMA1_MASK_REG);216else217dma_outb(dmanr & 3, DMA2_MASK_REG);218}219220static __inline__ void disable_dma(unsigned int dmanr)221{222if (dmanr<=3)223dma_outb(dmanr | 4, DMA1_MASK_REG);224else225dma_outb((dmanr & 3) | 4, DMA2_MASK_REG);226}227228/* Clear the 'DMA Pointer Flip Flop'.229* Write 0 for LSB/MSB, 1 for MSB/LSB access.230* Use this once to initialize the FF to a known state.231* After that, keep track of it. :-)232* --- In order to do that, the DMA routines below should ---233* --- only be used while interrupts are disabled! ---234*/235static __inline__ void clear_dma_ff(unsigned int dmanr)236{237if (dmanr<=3)238dma_outb(0, DMA1_CLEAR_FF_REG);239else240dma_outb(0, DMA2_CLEAR_FF_REG);241}242243/* set mode (above) for a specific DMA channel */244static __inline__ void set_dma_mode(unsigned int dmanr, char mode)245{246if (dmanr<=3)247dma_outb(mode | dmanr, DMA1_MODE_REG);248else249dma_outb(mode | (dmanr&3), DMA2_MODE_REG);250}251252/* set extended mode for a specific DMA channel */253static __inline__ void set_dma_ext_mode(unsigned int dmanr, char ext_mode)254{255if (dmanr<=3)256dma_outb(ext_mode | dmanr, DMA1_EXT_MODE_REG);257else258dma_outb(ext_mode | (dmanr&3), DMA2_EXT_MODE_REG);259}260261/* Set only the page register bits of the transfer address.262* This is used for successive transfers when we know the contents of263* the lower 16 bits of the DMA current address register.264*/265static __inline__ void set_dma_page(unsigned int dmanr, unsigned int pagenr)266{267switch(dmanr) {268case 0:269dma_outb(pagenr, DMA_PAGE_0);270dma_outb((pagenr >> 8), DMA_HIPAGE_0);271break;272case 1:273dma_outb(pagenr, DMA_PAGE_1);274dma_outb((pagenr >> 8), DMA_HIPAGE_1);275break;276case 2:277dma_outb(pagenr, DMA_PAGE_2);278dma_outb((pagenr >> 8), DMA_HIPAGE_2);279break;280case 3:281dma_outb(pagenr, DMA_PAGE_3);282dma_outb((pagenr >> 8), DMA_HIPAGE_3);283break;284case 5:285dma_outb(pagenr & 0xfe, DMA_PAGE_5);286dma_outb((pagenr >> 8), DMA_HIPAGE_5);287break;288case 6:289dma_outb(pagenr & 0xfe, DMA_PAGE_6);290dma_outb((pagenr >> 8), DMA_HIPAGE_6);291break;292case 7:293dma_outb(pagenr & 0xfe, DMA_PAGE_7);294dma_outb((pagenr >> 8), DMA_HIPAGE_7);295break;296}297}298299300/* Set transfer address & page bits for specific DMA channel.301* Assumes dma flipflop is clear.302*/303static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)304{305if (dmanr <= 3) {306dma_outb( a & 0xff, ((dmanr&3)<<1) + IO_DMA1_BASE );307dma_outb( (a>>8) & 0xff, ((dmanr&3)<<1) + IO_DMA1_BASE );308} else {309dma_outb( (a>>1) & 0xff, ((dmanr&3)<<2) + IO_DMA2_BASE );310dma_outb( (a>>9) & 0xff, ((dmanr&3)<<2) + IO_DMA2_BASE );311}312set_dma_page(dmanr, a>>16); /* set hipage last to enable 32-bit mode */313}314315316/* Set transfer size (max 64k for DMA1..3, 128k for DMA5..7) for317* a specific DMA channel.318* You must ensure the parameters are valid.319* NOTE: from a manual: "the number of transfers is one more320* than the initial word count"! This is taken into account.321* Assumes dma flip-flop is clear.322* NOTE 2: "count" represents _bytes_ and must be even for channels 5-7.323*/324static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)325{326count--;327if (dmanr <= 3) {328dma_outb( count & 0xff, ((dmanr&3)<<1) + 1 + IO_DMA1_BASE );329dma_outb( (count>>8) & 0xff, ((dmanr&3)<<1) + 1 + IO_DMA1_BASE );330} else {331dma_outb( (count>>1) & 0xff, ((dmanr&3)<<2) + 2 + IO_DMA2_BASE );332dma_outb( (count>>9) & 0xff, ((dmanr&3)<<2) + 2 + IO_DMA2_BASE );333}334}335336337/* Get DMA residue count. After a DMA transfer, this338* should return zero. Reading this while a DMA transfer is339* still in progress will return unpredictable results.340* If called before the channel has been used, it may return 1.341* Otherwise, it returns the number of _bytes_ left to transfer.342*343* Assumes DMA flip-flop is clear.344*/345static __inline__ int get_dma_residue(unsigned int dmanr)346{347unsigned int io_port = (dmanr<=3)? ((dmanr&3)<<1) + 1 + IO_DMA1_BASE348: ((dmanr&3)<<2) + 2 + IO_DMA2_BASE;349350/* using short to get 16-bit wrap around */351unsigned short count;352353count = 1 + dma_inb(io_port);354count += dma_inb(io_port) << 8;355356return (dmanr<=3)? count : (count<<1);357}358359360/* These are in kernel/dma.c: */361extern int request_dma(unsigned int dmanr, const char * device_id); /* reserve a DMA channel */362extern void free_dma(unsigned int dmanr); /* release it again */363#define KERNEL_HAVE_CHECK_DMA364extern int check_dma(unsigned int dmanr);365366/* From PCI */367368#ifdef CONFIG_PCI369extern int isa_dma_bridge_buggy;370#else371#define isa_dma_bridge_buggy (0)372#endif373374375#endif /* _ASM_DMA_H */376377378