18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * include/asm-m68k/dma.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 1995 (C) David S. Miller (davem@caip.rutgers.edu) 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Hacked to fit Sun3x needs by Thomas Bogendoerfer 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef __M68K_DVMA_H 118c2ecf20Sopenharmony_ci#define __M68K_DVMA_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define DVMA_PAGE_SHIFT 13 158c2ecf20Sopenharmony_ci#define DVMA_PAGE_SIZE (1UL << DVMA_PAGE_SHIFT) 168c2ecf20Sopenharmony_ci#define DVMA_PAGE_MASK (~(DVMA_PAGE_SIZE-1)) 178c2ecf20Sopenharmony_ci#define DVMA_PAGE_ALIGN(addr) ALIGN(addr, DVMA_PAGE_SIZE) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciextern void dvma_init(void); 208c2ecf20Sopenharmony_ciextern int dvma_map_iommu(unsigned long kaddr, unsigned long baddr, 218c2ecf20Sopenharmony_ci int len); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define dvma_malloc(x) dvma_malloc_align(x, 0) 248c2ecf20Sopenharmony_ci#define dvma_map(x, y) dvma_map_align(x, y, 0) 258c2ecf20Sopenharmony_ci#define dvma_map_vme(x, y) (dvma_map(x, y) & 0xfffff) 268c2ecf20Sopenharmony_ci#define dvma_map_align_vme(x, y, z) (dvma_map_align (x, y, z) & 0xfffff) 278c2ecf20Sopenharmony_ciextern unsigned long dvma_map_align(unsigned long kaddr, int len, 288c2ecf20Sopenharmony_ci int align); 298c2ecf20Sopenharmony_ciextern void *dvma_malloc_align(unsigned long len, unsigned long align); 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciextern void dvma_unmap(void *baddr); 328c2ecf20Sopenharmony_ciextern void dvma_free(void *vaddr); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#ifdef CONFIG_SUN3 368c2ecf20Sopenharmony_ci/* sun3 dvma page support */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* memory and pmegs potentially reserved for dvma */ 398c2ecf20Sopenharmony_ci#define DVMA_PMEG_START 10 408c2ecf20Sopenharmony_ci#define DVMA_PMEG_END 16 418c2ecf20Sopenharmony_ci#define DVMA_START 0xf00000 428c2ecf20Sopenharmony_ci#define DVMA_END 0xfe0000 438c2ecf20Sopenharmony_ci#define DVMA_SIZE (DVMA_END-DVMA_START) 448c2ecf20Sopenharmony_ci#define IOMMU_TOTAL_ENTRIES 128 458c2ecf20Sopenharmony_ci#define IOMMU_ENTRIES 120 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* empirical kludge -- dvma regions only seem to work right on 0x10000 488c2ecf20Sopenharmony_ci byte boundaries */ 498c2ecf20Sopenharmony_ci#define DVMA_REGION_SIZE 0x10000 508c2ecf20Sopenharmony_ci#define DVMA_ALIGN(addr) (((addr)+DVMA_REGION_SIZE-1) & \ 518c2ecf20Sopenharmony_ci ~(DVMA_REGION_SIZE-1)) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* virt <-> phys conversions */ 548c2ecf20Sopenharmony_ci#define dvma_vtop(x) ((unsigned long)(x) & 0xffffff) 558c2ecf20Sopenharmony_ci#define dvma_ptov(x) ((unsigned long)(x) | 0xf000000) 568c2ecf20Sopenharmony_ci#define dvma_vtovme(x) ((unsigned long)(x) & 0x00fffff) 578c2ecf20Sopenharmony_ci#define dvma_vmetov(x) ((unsigned long)(x) | 0xff00000) 588c2ecf20Sopenharmony_ci#define dvma_vtob(x) dvma_vtop(x) 598c2ecf20Sopenharmony_ci#define dvma_btov(x) dvma_ptov(x) 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistatic inline int dvma_map_cpu(unsigned long kaddr, unsigned long vaddr, 628c2ecf20Sopenharmony_ci int len) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci return 0; 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#else /* Sun3x */ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* sun3x dvma page support */ 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define DVMA_START 0x0 728c2ecf20Sopenharmony_ci#define DVMA_END 0xf00000 738c2ecf20Sopenharmony_ci#define DVMA_SIZE (DVMA_END-DVMA_START) 748c2ecf20Sopenharmony_ci#define IOMMU_TOTAL_ENTRIES 2048 758c2ecf20Sopenharmony_ci/* the prom takes the top meg */ 768c2ecf20Sopenharmony_ci#define IOMMU_ENTRIES (IOMMU_TOTAL_ENTRIES - 0x80) 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define dvma_vtob(x) ((unsigned long)(x) & 0x00ffffff) 798c2ecf20Sopenharmony_ci#define dvma_btov(x) ((unsigned long)(x) | 0xff000000) 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ciextern int dvma_map_cpu(unsigned long kaddr, unsigned long vaddr, int len); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* everything below this line is specific to dma used for the onboard 868c2ecf20Sopenharmony_ci ESP scsi on sun3x */ 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* Structure to describe the current status of DMA registers on the Sparc */ 898c2ecf20Sopenharmony_cistruct sparc_dma_registers { 908c2ecf20Sopenharmony_ci __volatile__ unsigned long cond_reg; /* DMA condition register */ 918c2ecf20Sopenharmony_ci __volatile__ unsigned long st_addr; /* Start address of this transfer */ 928c2ecf20Sopenharmony_ci __volatile__ unsigned long cnt; /* How many bytes to transfer */ 938c2ecf20Sopenharmony_ci __volatile__ unsigned long dma_test; /* DMA test register */ 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* DVMA chip revisions */ 978c2ecf20Sopenharmony_cienum dvma_rev { 988c2ecf20Sopenharmony_ci dvmarev0, 998c2ecf20Sopenharmony_ci dvmaesc1, 1008c2ecf20Sopenharmony_ci dvmarev1, 1018c2ecf20Sopenharmony_ci dvmarev2, 1028c2ecf20Sopenharmony_ci dvmarev3, 1038c2ecf20Sopenharmony_ci dvmarevplus, 1048c2ecf20Sopenharmony_ci dvmahme 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define DMA_HASCOUNT(rev) ((rev)==dvmaesc1) 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* Linux DMA information structure, filled during probe. */ 1108c2ecf20Sopenharmony_cistruct Linux_SBus_DMA { 1118c2ecf20Sopenharmony_ci struct Linux_SBus_DMA *next; 1128c2ecf20Sopenharmony_ci struct linux_sbus_device *SBus_dev; 1138c2ecf20Sopenharmony_ci struct sparc_dma_registers *regs; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci /* Status, misc info */ 1168c2ecf20Sopenharmony_ci int node; /* Prom node for this DMA device */ 1178c2ecf20Sopenharmony_ci int running; /* Are we doing DMA now? */ 1188c2ecf20Sopenharmony_ci int allocated; /* Are we "owned" by anyone yet? */ 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci /* Transfer information. */ 1218c2ecf20Sopenharmony_ci unsigned long addr; /* Start address of current transfer */ 1228c2ecf20Sopenharmony_ci int nbytes; /* Size of current transfer */ 1238c2ecf20Sopenharmony_ci int realbytes; /* For splitting up large transfers, etc. */ 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci /* DMA revision */ 1268c2ecf20Sopenharmony_ci enum dvma_rev revision; 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ciextern struct Linux_SBus_DMA *dma_chain; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/* Broken hardware... */ 1328c2ecf20Sopenharmony_ci#define DMA_ISBROKEN(dma) ((dma)->revision == dvmarev1) 1338c2ecf20Sopenharmony_ci#define DMA_ISESC1(dma) ((dma)->revision == dvmaesc1) 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci/* Fields in the cond_reg register */ 1368c2ecf20Sopenharmony_ci/* First, the version identification bits */ 1378c2ecf20Sopenharmony_ci#define DMA_DEVICE_ID 0xf0000000 /* Device identification bits */ 1388c2ecf20Sopenharmony_ci#define DMA_VERS0 0x00000000 /* Sunray DMA version */ 1398c2ecf20Sopenharmony_ci#define DMA_ESCV1 0x40000000 /* DMA ESC Version 1 */ 1408c2ecf20Sopenharmony_ci#define DMA_VERS1 0x80000000 /* DMA rev 1 */ 1418c2ecf20Sopenharmony_ci#define DMA_VERS2 0xa0000000 /* DMA rev 2 */ 1428c2ecf20Sopenharmony_ci#define DMA_VERHME 0xb0000000 /* DMA hme gate array */ 1438c2ecf20Sopenharmony_ci#define DMA_VERSPLUS 0x90000000 /* DMA rev 1 PLUS */ 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci#define DMA_HNDL_INTR 0x00000001 /* An IRQ needs to be handled */ 1468c2ecf20Sopenharmony_ci#define DMA_HNDL_ERROR 0x00000002 /* We need to take an error */ 1478c2ecf20Sopenharmony_ci#define DMA_FIFO_ISDRAIN 0x0000000c /* The DMA FIFO is draining */ 1488c2ecf20Sopenharmony_ci#define DMA_INT_ENAB 0x00000010 /* Turn on interrupts */ 1498c2ecf20Sopenharmony_ci#define DMA_FIFO_INV 0x00000020 /* Invalidate the FIFO */ 1508c2ecf20Sopenharmony_ci#define DMA_ACC_SZ_ERR 0x00000040 /* The access size was bad */ 1518c2ecf20Sopenharmony_ci#define DMA_FIFO_STDRAIN 0x00000040 /* DMA_VERS1 Drain the FIFO */ 1528c2ecf20Sopenharmony_ci#define DMA_RST_SCSI 0x00000080 /* Reset the SCSI controller */ 1538c2ecf20Sopenharmony_ci#define DMA_RST_ENET DMA_RST_SCSI /* Reset the ENET controller */ 1548c2ecf20Sopenharmony_ci#define DMA_ST_WRITE 0x00000100 /* write from device to memory */ 1558c2ecf20Sopenharmony_ci#define DMA_ENABLE 0x00000200 /* Fire up DMA, handle requests */ 1568c2ecf20Sopenharmony_ci#define DMA_PEND_READ 0x00000400 /* DMA_VERS1/0/PLUS Pending Read */ 1578c2ecf20Sopenharmony_ci#define DMA_ESC_BURST 0x00000800 /* 1=16byte 0=32byte */ 1588c2ecf20Sopenharmony_ci#define DMA_READ_AHEAD 0x00001800 /* DMA read ahead partial longword */ 1598c2ecf20Sopenharmony_ci#define DMA_DSBL_RD_DRN 0x00001000 /* No EC drain on slave reads */ 1608c2ecf20Sopenharmony_ci#define DMA_BCNT_ENAB 0x00002000 /* If on, use the byte counter */ 1618c2ecf20Sopenharmony_ci#define DMA_TERM_CNTR 0x00004000 /* Terminal counter */ 1628c2ecf20Sopenharmony_ci#define DMA_CSR_DISAB 0x00010000 /* No FIFO drains during csr */ 1638c2ecf20Sopenharmony_ci#define DMA_SCSI_DISAB 0x00020000 /* No FIFO drains during reg */ 1648c2ecf20Sopenharmony_ci#define DMA_DSBL_WR_INV 0x00020000 /* No EC inval. on slave writes */ 1658c2ecf20Sopenharmony_ci#define DMA_ADD_ENABLE 0x00040000 /* Special ESC DVMA optimization */ 1668c2ecf20Sopenharmony_ci#define DMA_E_BURST8 0x00040000 /* ENET: SBUS r/w burst size */ 1678c2ecf20Sopenharmony_ci#define DMA_BRST_SZ 0x000c0000 /* SCSI: SBUS r/w burst size */ 1688c2ecf20Sopenharmony_ci#define DMA_BRST64 0x00080000 /* SCSI: 64byte bursts (HME on UltraSparc only) */ 1698c2ecf20Sopenharmony_ci#define DMA_BRST32 0x00040000 /* SCSI: 32byte bursts */ 1708c2ecf20Sopenharmony_ci#define DMA_BRST16 0x00000000 /* SCSI: 16byte bursts */ 1718c2ecf20Sopenharmony_ci#define DMA_BRST0 0x00080000 /* SCSI: no bursts (non-HME gate arrays) */ 1728c2ecf20Sopenharmony_ci#define DMA_ADDR_DISAB 0x00100000 /* No FIFO drains during addr */ 1738c2ecf20Sopenharmony_ci#define DMA_2CLKS 0x00200000 /* Each transfer = 2 clock ticks */ 1748c2ecf20Sopenharmony_ci#define DMA_3CLKS 0x00400000 /* Each transfer = 3 clock ticks */ 1758c2ecf20Sopenharmony_ci#define DMA_EN_ENETAUI DMA_3CLKS /* Put lance into AUI-cable mode */ 1768c2ecf20Sopenharmony_ci#define DMA_CNTR_DISAB 0x00800000 /* No IRQ when DMA_TERM_CNTR set */ 1778c2ecf20Sopenharmony_ci#define DMA_AUTO_NADDR 0x01000000 /* Use "auto nxt addr" feature */ 1788c2ecf20Sopenharmony_ci#define DMA_SCSI_ON 0x02000000 /* Enable SCSI dma */ 1798c2ecf20Sopenharmony_ci#define DMA_PARITY_OFF 0x02000000 /* HME: disable parity checking */ 1808c2ecf20Sopenharmony_ci#define DMA_LOADED_ADDR 0x04000000 /* Address has been loaded */ 1818c2ecf20Sopenharmony_ci#define DMA_LOADED_NADDR 0x08000000 /* Next address has been loaded */ 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci/* Values describing the burst-size property from the PROM */ 1848c2ecf20Sopenharmony_ci#define DMA_BURST1 0x01 1858c2ecf20Sopenharmony_ci#define DMA_BURST2 0x02 1868c2ecf20Sopenharmony_ci#define DMA_BURST4 0x04 1878c2ecf20Sopenharmony_ci#define DMA_BURST8 0x08 1888c2ecf20Sopenharmony_ci#define DMA_BURST16 0x10 1898c2ecf20Sopenharmony_ci#define DMA_BURST32 0x20 1908c2ecf20Sopenharmony_ci#define DMA_BURST64 0x40 1918c2ecf20Sopenharmony_ci#define DMA_BURSTBITS 0x7f 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci/* Determine highest possible final transfer address given a base */ 1948c2ecf20Sopenharmony_ci#define DMA_MAXEND(addr) (0x01000000UL-(((unsigned long)(addr))&0x00ffffffUL)) 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci/* Yes, I hack a lot of elisp in my spare time... */ 1978c2ecf20Sopenharmony_ci#define DMA_ERROR_P(regs) ((((regs)->cond_reg) & DMA_HNDL_ERROR)) 1988c2ecf20Sopenharmony_ci#define DMA_IRQ_P(regs) ((((regs)->cond_reg) & (DMA_HNDL_INTR | DMA_HNDL_ERROR))) 1998c2ecf20Sopenharmony_ci#define DMA_WRITE_P(regs) ((((regs)->cond_reg) & DMA_ST_WRITE)) 2008c2ecf20Sopenharmony_ci#define DMA_OFF(regs) ((((regs)->cond_reg) &= (~DMA_ENABLE))) 2018c2ecf20Sopenharmony_ci#define DMA_INTSOFF(regs) ((((regs)->cond_reg) &= (~DMA_INT_ENAB))) 2028c2ecf20Sopenharmony_ci#define DMA_INTSON(regs) ((((regs)->cond_reg) |= (DMA_INT_ENAB))) 2038c2ecf20Sopenharmony_ci#define DMA_PUNTFIFO(regs) ((((regs)->cond_reg) |= DMA_FIFO_INV)) 2048c2ecf20Sopenharmony_ci#define DMA_SETSTART(regs, addr) ((((regs)->st_addr) = (char *) addr)) 2058c2ecf20Sopenharmony_ci#define DMA_BEGINDMA_W(regs) \ 2068c2ecf20Sopenharmony_ci ((((regs)->cond_reg |= (DMA_ST_WRITE|DMA_ENABLE|DMA_INT_ENAB)))) 2078c2ecf20Sopenharmony_ci#define DMA_BEGINDMA_R(regs) \ 2088c2ecf20Sopenharmony_ci ((((regs)->cond_reg |= ((DMA_ENABLE|DMA_INT_ENAB)&(~DMA_ST_WRITE))))) 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* For certain DMA chips, we need to disable ints upon irq entry 2118c2ecf20Sopenharmony_ci * and turn them back on when we are done. So in any ESP interrupt 2128c2ecf20Sopenharmony_ci * handler you *must* call DMA_IRQ_ENTRY upon entry and DMA_IRQ_EXIT 2138c2ecf20Sopenharmony_ci * when leaving the handler. You have been warned... 2148c2ecf20Sopenharmony_ci */ 2158c2ecf20Sopenharmony_ci#define DMA_IRQ_ENTRY(dma, dregs) do { \ 2168c2ecf20Sopenharmony_ci if(DMA_ISBROKEN(dma)) DMA_INTSOFF(dregs); \ 2178c2ecf20Sopenharmony_ci } while (0) 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci#define DMA_IRQ_EXIT(dma, dregs) do { \ 2208c2ecf20Sopenharmony_ci if(DMA_ISBROKEN(dma)) DMA_INTSON(dregs); \ 2218c2ecf20Sopenharmony_ci } while(0) 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci/* Reset the friggin' thing... */ 2248c2ecf20Sopenharmony_ci#define DMA_RESET(dma) do { \ 2258c2ecf20Sopenharmony_ci struct sparc_dma_registers *regs = dma->regs; \ 2268c2ecf20Sopenharmony_ci /* Let the current FIFO drain itself */ \ 2278c2ecf20Sopenharmony_ci sparc_dma_pause(regs, (DMA_FIFO_ISDRAIN)); \ 2288c2ecf20Sopenharmony_ci /* Reset the logic */ \ 2298c2ecf20Sopenharmony_ci regs->cond_reg |= (DMA_RST_SCSI); /* assert */ \ 2308c2ecf20Sopenharmony_ci __delay(400); /* let the bits set ;) */ \ 2318c2ecf20Sopenharmony_ci regs->cond_reg &= ~(DMA_RST_SCSI); /* de-assert */ \ 2328c2ecf20Sopenharmony_ci sparc_dma_enable_interrupts(regs); /* Re-enable interrupts */ \ 2338c2ecf20Sopenharmony_ci /* Enable FAST transfers if available */ \ 2348c2ecf20Sopenharmony_ci if(dma->revision>dvmarev1) regs->cond_reg |= DMA_3CLKS; \ 2358c2ecf20Sopenharmony_ci dma->running = 0; \ 2368c2ecf20Sopenharmony_ci} while(0) 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci#endif /* !CONFIG_SUN3 */ 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci#endif /* !(__M68K_DVMA_H) */ 242