162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * include/asm-m68k/dma.h 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright 1995 (C) David S. Miller (davem@caip.rutgers.edu) 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Hacked to fit Sun3x needs by Thomas Bogendoerfer 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef __M68K_DVMA_H 1162306a36Sopenharmony_ci#define __M68K_DVMA_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define DVMA_PAGE_SHIFT 13 1562306a36Sopenharmony_ci#define DVMA_PAGE_SIZE (1UL << DVMA_PAGE_SHIFT) 1662306a36Sopenharmony_ci#define DVMA_PAGE_MASK (~(DVMA_PAGE_SIZE-1)) 1762306a36Sopenharmony_ci#define DVMA_PAGE_ALIGN(addr) ALIGN(addr, DVMA_PAGE_SIZE) 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciextern void dvma_init(void); 2062306a36Sopenharmony_ciextern int dvma_map_iommu(unsigned long kaddr, unsigned long baddr, 2162306a36Sopenharmony_ci int len); 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define dvma_malloc(x) dvma_malloc_align(x, 0) 2462306a36Sopenharmony_ci#define dvma_map(x, y) dvma_map_align(x, y, 0) 2562306a36Sopenharmony_ci#define dvma_map_vme(x, y) (dvma_map(x, y) & 0xfffff) 2662306a36Sopenharmony_ci#define dvma_map_align_vme(x, y, z) (dvma_map_align (x, y, z) & 0xfffff) 2762306a36Sopenharmony_ciextern unsigned long dvma_map_align(unsigned long kaddr, int len, 2862306a36Sopenharmony_ci int align); 2962306a36Sopenharmony_ciextern void *dvma_malloc_align(unsigned long len, unsigned long align); 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciextern void dvma_unmap(void *baddr); 3262306a36Sopenharmony_ciextern void dvma_free(void *vaddr); 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#ifdef CONFIG_SUN3 3662306a36Sopenharmony_ci/* sun3 dvma page support */ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* memory and pmegs potentially reserved for dvma */ 3962306a36Sopenharmony_ci#define DVMA_PMEG_START 10 4062306a36Sopenharmony_ci#define DVMA_PMEG_END 16 4162306a36Sopenharmony_ci#define DVMA_START 0xf00000 4262306a36Sopenharmony_ci#define DVMA_END 0xfe0000 4362306a36Sopenharmony_ci#define DVMA_SIZE (DVMA_END-DVMA_START) 4462306a36Sopenharmony_ci#define IOMMU_TOTAL_ENTRIES 128 4562306a36Sopenharmony_ci#define IOMMU_ENTRIES 120 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/* empirical kludge -- dvma regions only seem to work right on 0x10000 4862306a36Sopenharmony_ci byte boundaries */ 4962306a36Sopenharmony_ci#define DVMA_REGION_SIZE 0x10000 5062306a36Sopenharmony_ci#define DVMA_ALIGN(addr) (((addr)+DVMA_REGION_SIZE-1) & \ 5162306a36Sopenharmony_ci ~(DVMA_REGION_SIZE-1)) 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci/* virt <-> phys conversions */ 5462306a36Sopenharmony_ci#define dvma_vtop(x) ((unsigned long)(x) & 0xffffff) 5562306a36Sopenharmony_ci#define dvma_ptov(x) ((unsigned long)(x) | 0xf000000) 5662306a36Sopenharmony_ci#define dvma_vtovme(x) ((unsigned long)(x) & 0x00fffff) 5762306a36Sopenharmony_ci#define dvma_vmetov(x) ((unsigned long)(x) | 0xff00000) 5862306a36Sopenharmony_ci#define dvma_vtob(x) dvma_vtop(x) 5962306a36Sopenharmony_ci#define dvma_btov(x) dvma_ptov(x) 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_cistatic inline int dvma_map_cpu(unsigned long kaddr, unsigned long vaddr, 6262306a36Sopenharmony_ci int len) 6362306a36Sopenharmony_ci{ 6462306a36Sopenharmony_ci return 0; 6562306a36Sopenharmony_ci} 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#else /* Sun3x */ 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci/* sun3x dvma page support */ 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#define DVMA_START 0x0 7262306a36Sopenharmony_ci#define DVMA_END 0xf00000 7362306a36Sopenharmony_ci#define DVMA_SIZE (DVMA_END-DVMA_START) 7462306a36Sopenharmony_ci#define IOMMU_TOTAL_ENTRIES 2048 7562306a36Sopenharmony_ci/* the prom takes the top meg */ 7662306a36Sopenharmony_ci#define IOMMU_ENTRIES (IOMMU_TOTAL_ENTRIES - 0x80) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#define dvma_vtob(x) ((unsigned long)(x) & 0x00ffffff) 7962306a36Sopenharmony_ci#define dvma_btov(x) ((unsigned long)(x) | 0xff000000) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciextern int dvma_map_cpu(unsigned long kaddr, unsigned long vaddr, int len); 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* everything below this line is specific to dma used for the onboard 8662306a36Sopenharmony_ci ESP scsi on sun3x */ 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/* Structure to describe the current status of DMA registers on the Sparc */ 8962306a36Sopenharmony_cistruct sparc_dma_registers { 9062306a36Sopenharmony_ci __volatile__ unsigned long cond_reg; /* DMA condition register */ 9162306a36Sopenharmony_ci __volatile__ unsigned long st_addr; /* Start address of this transfer */ 9262306a36Sopenharmony_ci __volatile__ unsigned long cnt; /* How many bytes to transfer */ 9362306a36Sopenharmony_ci __volatile__ unsigned long dma_test; /* DMA test register */ 9462306a36Sopenharmony_ci}; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/* DVMA chip revisions */ 9762306a36Sopenharmony_cienum dvma_rev { 9862306a36Sopenharmony_ci dvmarev0, 9962306a36Sopenharmony_ci dvmaesc1, 10062306a36Sopenharmony_ci dvmarev1, 10162306a36Sopenharmony_ci dvmarev2, 10262306a36Sopenharmony_ci dvmarev3, 10362306a36Sopenharmony_ci dvmarevplus, 10462306a36Sopenharmony_ci dvmahme 10562306a36Sopenharmony_ci}; 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#define DMA_HASCOUNT(rev) ((rev)==dvmaesc1) 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci/* Linux DMA information structure, filled during probe. */ 11062306a36Sopenharmony_cistruct Linux_SBus_DMA { 11162306a36Sopenharmony_ci struct Linux_SBus_DMA *next; 11262306a36Sopenharmony_ci struct linux_sbus_device *SBus_dev; 11362306a36Sopenharmony_ci struct sparc_dma_registers *regs; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci /* Status, misc info */ 11662306a36Sopenharmony_ci int node; /* Prom node for this DMA device */ 11762306a36Sopenharmony_ci int running; /* Are we doing DMA now? */ 11862306a36Sopenharmony_ci int allocated; /* Are we "owned" by anyone yet? */ 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci /* Transfer information. */ 12162306a36Sopenharmony_ci unsigned long addr; /* Start address of current transfer */ 12262306a36Sopenharmony_ci int nbytes; /* Size of current transfer */ 12362306a36Sopenharmony_ci int realbytes; /* For splitting up large transfers, etc. */ 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci /* DMA revision */ 12662306a36Sopenharmony_ci enum dvma_rev revision; 12762306a36Sopenharmony_ci}; 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ciextern struct Linux_SBus_DMA *dma_chain; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci/* Broken hardware... */ 13262306a36Sopenharmony_ci#define DMA_ISBROKEN(dma) ((dma)->revision == dvmarev1) 13362306a36Sopenharmony_ci#define DMA_ISESC1(dma) ((dma)->revision == dvmaesc1) 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/* Fields in the cond_reg register */ 13662306a36Sopenharmony_ci/* First, the version identification bits */ 13762306a36Sopenharmony_ci#define DMA_DEVICE_ID 0xf0000000 /* Device identification bits */ 13862306a36Sopenharmony_ci#define DMA_VERS0 0x00000000 /* Sunray DMA version */ 13962306a36Sopenharmony_ci#define DMA_ESCV1 0x40000000 /* DMA ESC Version 1 */ 14062306a36Sopenharmony_ci#define DMA_VERS1 0x80000000 /* DMA rev 1 */ 14162306a36Sopenharmony_ci#define DMA_VERS2 0xa0000000 /* DMA rev 2 */ 14262306a36Sopenharmony_ci#define DMA_VERHME 0xb0000000 /* DMA hme gate array */ 14362306a36Sopenharmony_ci#define DMA_VERSPLUS 0x90000000 /* DMA rev 1 PLUS */ 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci#define DMA_HNDL_INTR 0x00000001 /* An IRQ needs to be handled */ 14662306a36Sopenharmony_ci#define DMA_HNDL_ERROR 0x00000002 /* We need to take an error */ 14762306a36Sopenharmony_ci#define DMA_FIFO_ISDRAIN 0x0000000c /* The DMA FIFO is draining */ 14862306a36Sopenharmony_ci#define DMA_INT_ENAB 0x00000010 /* Turn on interrupts */ 14962306a36Sopenharmony_ci#define DMA_FIFO_INV 0x00000020 /* Invalidate the FIFO */ 15062306a36Sopenharmony_ci#define DMA_ACC_SZ_ERR 0x00000040 /* The access size was bad */ 15162306a36Sopenharmony_ci#define DMA_FIFO_STDRAIN 0x00000040 /* DMA_VERS1 Drain the FIFO */ 15262306a36Sopenharmony_ci#define DMA_RST_SCSI 0x00000080 /* Reset the SCSI controller */ 15362306a36Sopenharmony_ci#define DMA_RST_ENET DMA_RST_SCSI /* Reset the ENET controller */ 15462306a36Sopenharmony_ci#define DMA_ST_WRITE 0x00000100 /* write from device to memory */ 15562306a36Sopenharmony_ci#define DMA_ENABLE 0x00000200 /* Fire up DMA, handle requests */ 15662306a36Sopenharmony_ci#define DMA_PEND_READ 0x00000400 /* DMA_VERS1/0/PLUS Pending Read */ 15762306a36Sopenharmony_ci#define DMA_ESC_BURST 0x00000800 /* 1=16byte 0=32byte */ 15862306a36Sopenharmony_ci#define DMA_READ_AHEAD 0x00001800 /* DMA read ahead partial longword */ 15962306a36Sopenharmony_ci#define DMA_DSBL_RD_DRN 0x00001000 /* No EC drain on slave reads */ 16062306a36Sopenharmony_ci#define DMA_BCNT_ENAB 0x00002000 /* If on, use the byte counter */ 16162306a36Sopenharmony_ci#define DMA_TERM_CNTR 0x00004000 /* Terminal counter */ 16262306a36Sopenharmony_ci#define DMA_CSR_DISAB 0x00010000 /* No FIFO drains during csr */ 16362306a36Sopenharmony_ci#define DMA_SCSI_DISAB 0x00020000 /* No FIFO drains during reg */ 16462306a36Sopenharmony_ci#define DMA_DSBL_WR_INV 0x00020000 /* No EC inval. on slave writes */ 16562306a36Sopenharmony_ci#define DMA_ADD_ENABLE 0x00040000 /* Special ESC DVMA optimization */ 16662306a36Sopenharmony_ci#define DMA_E_BURST8 0x00040000 /* ENET: SBUS r/w burst size */ 16762306a36Sopenharmony_ci#define DMA_BRST_SZ 0x000c0000 /* SCSI: SBUS r/w burst size */ 16862306a36Sopenharmony_ci#define DMA_BRST64 0x00080000 /* SCSI: 64byte bursts (HME on UltraSparc only) */ 16962306a36Sopenharmony_ci#define DMA_BRST32 0x00040000 /* SCSI: 32byte bursts */ 17062306a36Sopenharmony_ci#define DMA_BRST16 0x00000000 /* SCSI: 16byte bursts */ 17162306a36Sopenharmony_ci#define DMA_BRST0 0x00080000 /* SCSI: no bursts (non-HME gate arrays) */ 17262306a36Sopenharmony_ci#define DMA_ADDR_DISAB 0x00100000 /* No FIFO drains during addr */ 17362306a36Sopenharmony_ci#define DMA_2CLKS 0x00200000 /* Each transfer = 2 clock ticks */ 17462306a36Sopenharmony_ci#define DMA_3CLKS 0x00400000 /* Each transfer = 3 clock ticks */ 17562306a36Sopenharmony_ci#define DMA_EN_ENETAUI DMA_3CLKS /* Put lance into AUI-cable mode */ 17662306a36Sopenharmony_ci#define DMA_CNTR_DISAB 0x00800000 /* No IRQ when DMA_TERM_CNTR set */ 17762306a36Sopenharmony_ci#define DMA_AUTO_NADDR 0x01000000 /* Use "auto nxt addr" feature */ 17862306a36Sopenharmony_ci#define DMA_SCSI_ON 0x02000000 /* Enable SCSI dma */ 17962306a36Sopenharmony_ci#define DMA_PARITY_OFF 0x02000000 /* HME: disable parity checking */ 18062306a36Sopenharmony_ci#define DMA_LOADED_ADDR 0x04000000 /* Address has been loaded */ 18162306a36Sopenharmony_ci#define DMA_LOADED_NADDR 0x08000000 /* Next address has been loaded */ 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci/* Values describing the burst-size property from the PROM */ 18462306a36Sopenharmony_ci#define DMA_BURST1 0x01 18562306a36Sopenharmony_ci#define DMA_BURST2 0x02 18662306a36Sopenharmony_ci#define DMA_BURST4 0x04 18762306a36Sopenharmony_ci#define DMA_BURST8 0x08 18862306a36Sopenharmony_ci#define DMA_BURST16 0x10 18962306a36Sopenharmony_ci#define DMA_BURST32 0x20 19062306a36Sopenharmony_ci#define DMA_BURST64 0x40 19162306a36Sopenharmony_ci#define DMA_BURSTBITS 0x7f 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci/* Determine highest possible final transfer address given a base */ 19462306a36Sopenharmony_ci#define DMA_MAXEND(addr) (0x01000000UL-(((unsigned long)(addr))&0x00ffffffUL)) 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci/* Yes, I hack a lot of elisp in my spare time... */ 19762306a36Sopenharmony_ci#define DMA_ERROR_P(regs) ((((regs)->cond_reg) & DMA_HNDL_ERROR)) 19862306a36Sopenharmony_ci#define DMA_IRQ_P(regs) ((((regs)->cond_reg) & (DMA_HNDL_INTR | DMA_HNDL_ERROR))) 19962306a36Sopenharmony_ci#define DMA_WRITE_P(regs) ((((regs)->cond_reg) & DMA_ST_WRITE)) 20062306a36Sopenharmony_ci#define DMA_OFF(regs) ((((regs)->cond_reg) &= (~DMA_ENABLE))) 20162306a36Sopenharmony_ci#define DMA_INTSOFF(regs) ((((regs)->cond_reg) &= (~DMA_INT_ENAB))) 20262306a36Sopenharmony_ci#define DMA_INTSON(regs) ((((regs)->cond_reg) |= (DMA_INT_ENAB))) 20362306a36Sopenharmony_ci#define DMA_PUNTFIFO(regs) ((((regs)->cond_reg) |= DMA_FIFO_INV)) 20462306a36Sopenharmony_ci#define DMA_SETSTART(regs, addr) ((((regs)->st_addr) = (char *) addr)) 20562306a36Sopenharmony_ci#define DMA_BEGINDMA_W(regs) \ 20662306a36Sopenharmony_ci ((((regs)->cond_reg |= (DMA_ST_WRITE|DMA_ENABLE|DMA_INT_ENAB)))) 20762306a36Sopenharmony_ci#define DMA_BEGINDMA_R(regs) \ 20862306a36Sopenharmony_ci ((((regs)->cond_reg |= ((DMA_ENABLE|DMA_INT_ENAB)&(~DMA_ST_WRITE))))) 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci/* For certain DMA chips, we need to disable ints upon irq entry 21162306a36Sopenharmony_ci * and turn them back on when we are done. So in any ESP interrupt 21262306a36Sopenharmony_ci * handler you *must* call DMA_IRQ_ENTRY upon entry and DMA_IRQ_EXIT 21362306a36Sopenharmony_ci * when leaving the handler. You have been warned... 21462306a36Sopenharmony_ci */ 21562306a36Sopenharmony_ci#define DMA_IRQ_ENTRY(dma, dregs) do { \ 21662306a36Sopenharmony_ci if(DMA_ISBROKEN(dma)) DMA_INTSOFF(dregs); \ 21762306a36Sopenharmony_ci } while (0) 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci#define DMA_IRQ_EXIT(dma, dregs) do { \ 22062306a36Sopenharmony_ci if(DMA_ISBROKEN(dma)) DMA_INTSON(dregs); \ 22162306a36Sopenharmony_ci } while(0) 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci/* Reset the friggin' thing... */ 22462306a36Sopenharmony_ci#define DMA_RESET(dma) do { \ 22562306a36Sopenharmony_ci struct sparc_dma_registers *regs = dma->regs; \ 22662306a36Sopenharmony_ci /* Let the current FIFO drain itself */ \ 22762306a36Sopenharmony_ci sparc_dma_pause(regs, (DMA_FIFO_ISDRAIN)); \ 22862306a36Sopenharmony_ci /* Reset the logic */ \ 22962306a36Sopenharmony_ci regs->cond_reg |= (DMA_RST_SCSI); /* assert */ \ 23062306a36Sopenharmony_ci __delay(400); /* let the bits set ;) */ \ 23162306a36Sopenharmony_ci regs->cond_reg &= ~(DMA_RST_SCSI); /* de-assert */ \ 23262306a36Sopenharmony_ci sparc_dma_enable_interrupts(regs); /* Re-enable interrupts */ \ 23362306a36Sopenharmony_ci /* Enable FAST transfers if available */ \ 23462306a36Sopenharmony_ci if(dma->revision>dvmarev1) regs->cond_reg |= DMA_3CLKS; \ 23562306a36Sopenharmony_ci dma->running = 0; \ 23662306a36Sopenharmony_ci} while(0) 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci#endif /* !CONFIG_SUN3 */ 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci#endif /* !(__M68K_DVMA_H) */ 242