162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* iommu.h: Definitions for the sun4m IOMMU. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#ifndef _SPARC_IOMMU_H 762306a36Sopenharmony_ci#define _SPARC_IOMMU_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <asm/page.h> 1062306a36Sopenharmony_ci#include <asm/bitext.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci/* The iommu handles all virtual to physical address translations 1362306a36Sopenharmony_ci * that occur between the SBUS and physical memory. Access by 1462306a36Sopenharmony_ci * the cpu to IO registers and similar go over the mbus so are 1562306a36Sopenharmony_ci * translated by the on chip SRMMU. The iommu and the srmmu do 1662306a36Sopenharmony_ci * not need to have the same translations at all, in fact most 1762306a36Sopenharmony_ci * of the time the translations they handle are a disjunct set. 1862306a36Sopenharmony_ci * Basically the iommu handles all dvma sbus activity. 1962306a36Sopenharmony_ci */ 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* The IOMMU registers occupy three pages in IO space. */ 2262306a36Sopenharmony_cistruct iommu_regs { 2362306a36Sopenharmony_ci /* First page */ 2462306a36Sopenharmony_ci volatile unsigned long control; /* IOMMU control */ 2562306a36Sopenharmony_ci volatile unsigned long base; /* Physical base of iopte page table */ 2662306a36Sopenharmony_ci volatile unsigned long _unused1[3]; 2762306a36Sopenharmony_ci volatile unsigned long tlbflush; /* write only */ 2862306a36Sopenharmony_ci volatile unsigned long pageflush; /* write only */ 2962306a36Sopenharmony_ci volatile unsigned long _unused2[1017]; 3062306a36Sopenharmony_ci /* Second page */ 3162306a36Sopenharmony_ci volatile unsigned long afsr; /* Async-fault status register */ 3262306a36Sopenharmony_ci volatile unsigned long afar; /* Async-fault physical address */ 3362306a36Sopenharmony_ci volatile unsigned long _unused3[2]; 3462306a36Sopenharmony_ci volatile unsigned long sbuscfg0; /* SBUS configuration registers, per-slot */ 3562306a36Sopenharmony_ci volatile unsigned long sbuscfg1; 3662306a36Sopenharmony_ci volatile unsigned long sbuscfg2; 3762306a36Sopenharmony_ci volatile unsigned long sbuscfg3; 3862306a36Sopenharmony_ci volatile unsigned long mfsr; /* Memory-fault status register */ 3962306a36Sopenharmony_ci volatile unsigned long mfar; /* Memory-fault physical address */ 4062306a36Sopenharmony_ci volatile unsigned long _unused4[1014]; 4162306a36Sopenharmony_ci /* Third page */ 4262306a36Sopenharmony_ci volatile unsigned long mid; /* IOMMU module-id */ 4362306a36Sopenharmony_ci}; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define IOMMU_CTRL_IMPL 0xf0000000 /* Implementation */ 4662306a36Sopenharmony_ci#define IOMMU_CTRL_VERS 0x0f000000 /* Version */ 4762306a36Sopenharmony_ci#define IOMMU_CTRL_RNGE 0x0000001c /* Mapping RANGE */ 4862306a36Sopenharmony_ci#define IOMMU_RNGE_16MB 0x00000000 /* 0xff000000 -> 0xffffffff */ 4962306a36Sopenharmony_ci#define IOMMU_RNGE_32MB 0x00000004 /* 0xfe000000 -> 0xffffffff */ 5062306a36Sopenharmony_ci#define IOMMU_RNGE_64MB 0x00000008 /* 0xfc000000 -> 0xffffffff */ 5162306a36Sopenharmony_ci#define IOMMU_RNGE_128MB 0x0000000c /* 0xf8000000 -> 0xffffffff */ 5262306a36Sopenharmony_ci#define IOMMU_RNGE_256MB 0x00000010 /* 0xf0000000 -> 0xffffffff */ 5362306a36Sopenharmony_ci#define IOMMU_RNGE_512MB 0x00000014 /* 0xe0000000 -> 0xffffffff */ 5462306a36Sopenharmony_ci#define IOMMU_RNGE_1GB 0x00000018 /* 0xc0000000 -> 0xffffffff */ 5562306a36Sopenharmony_ci#define IOMMU_RNGE_2GB 0x0000001c /* 0x80000000 -> 0xffffffff */ 5662306a36Sopenharmony_ci#define IOMMU_CTRL_ENAB 0x00000001 /* IOMMU Enable */ 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define IOMMU_AFSR_ERR 0x80000000 /* LE, TO, or BE asserted */ 5962306a36Sopenharmony_ci#define IOMMU_AFSR_LE 0x40000000 /* SBUS reports error after transaction */ 6062306a36Sopenharmony_ci#define IOMMU_AFSR_TO 0x20000000 /* Write access took more than 12.8 us. */ 6162306a36Sopenharmony_ci#define IOMMU_AFSR_BE 0x10000000 /* Write access received error acknowledge */ 6262306a36Sopenharmony_ci#define IOMMU_AFSR_SIZE 0x0e000000 /* Size of transaction causing error */ 6362306a36Sopenharmony_ci#define IOMMU_AFSR_S 0x01000000 /* Sparc was in supervisor mode */ 6462306a36Sopenharmony_ci#define IOMMU_AFSR_RESV 0x00f00000 /* Reserver, forced to 0x8 by hardware */ 6562306a36Sopenharmony_ci#define IOMMU_AFSR_ME 0x00080000 /* Multiple errors occurred */ 6662306a36Sopenharmony_ci#define IOMMU_AFSR_RD 0x00040000 /* A read operation was in progress */ 6762306a36Sopenharmony_ci#define IOMMU_AFSR_FAV 0x00020000 /* IOMMU afar has valid contents */ 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#define IOMMU_SBCFG_SAB30 0x00010000 /* Phys-address bit 30 when bypass enabled */ 7062306a36Sopenharmony_ci#define IOMMU_SBCFG_BA16 0x00000004 /* Slave supports 16 byte bursts */ 7162306a36Sopenharmony_ci#define IOMMU_SBCFG_BA8 0x00000002 /* Slave supports 8 byte bursts */ 7262306a36Sopenharmony_ci#define IOMMU_SBCFG_BYPASS 0x00000001 /* Bypass IOMMU, treat all addresses 7362306a36Sopenharmony_ci produced by this device as pure 7462306a36Sopenharmony_ci physical. */ 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#define IOMMU_MFSR_ERR 0x80000000 /* One or more of PERR1 or PERR0 */ 7762306a36Sopenharmony_ci#define IOMMU_MFSR_S 0x01000000 /* Sparc was in supervisor mode */ 7862306a36Sopenharmony_ci#define IOMMU_MFSR_CPU 0x00800000 /* CPU transaction caused parity error */ 7962306a36Sopenharmony_ci#define IOMMU_MFSR_ME 0x00080000 /* Multiple parity errors occurred */ 8062306a36Sopenharmony_ci#define IOMMU_MFSR_PERR 0x00006000 /* high bit indicates parity error occurred 8162306a36Sopenharmony_ci on the even word of the access, low bit 8262306a36Sopenharmony_ci indicated odd word caused the parity error */ 8362306a36Sopenharmony_ci#define IOMMU_MFSR_BM 0x00001000 /* Error occurred while in boot mode */ 8462306a36Sopenharmony_ci#define IOMMU_MFSR_C 0x00000800 /* Address causing error was marked cacheable */ 8562306a36Sopenharmony_ci#define IOMMU_MFSR_RTYP 0x000000f0 /* Memory request transaction type */ 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#define IOMMU_MID_SBAE 0x001f0000 /* SBus arbitration enable */ 8862306a36Sopenharmony_ci#define IOMMU_MID_SE 0x00100000 /* Enables SCSI/ETHERNET arbitration */ 8962306a36Sopenharmony_ci#define IOMMU_MID_SB3 0x00080000 /* Enable SBUS device 3 arbitration */ 9062306a36Sopenharmony_ci#define IOMMU_MID_SB2 0x00040000 /* Enable SBUS device 2 arbitration */ 9162306a36Sopenharmony_ci#define IOMMU_MID_SB1 0x00020000 /* Enable SBUS device 1 arbitration */ 9262306a36Sopenharmony_ci#define IOMMU_MID_SB0 0x00010000 /* Enable SBUS device 0 arbitration */ 9362306a36Sopenharmony_ci#define IOMMU_MID_MID 0x0000000f /* Module-id, hardcoded to 0x8 */ 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci/* The format of an iopte in the page tables */ 9662306a36Sopenharmony_ci#define IOPTE_PAGE 0x07ffff00 /* Physical page number (PA[30:12]) */ 9762306a36Sopenharmony_ci#define IOPTE_CACHE 0x00000080 /* Cached (in vme IOCACHE or Viking/MXCC) */ 9862306a36Sopenharmony_ci#define IOPTE_WRITE 0x00000004 /* Writeable */ 9962306a36Sopenharmony_ci#define IOPTE_VALID 0x00000002 /* IOPTE is valid */ 10062306a36Sopenharmony_ci#define IOPTE_WAZ 0x00000001 /* Write as zeros */ 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_cistruct iommu_struct { 10362306a36Sopenharmony_ci struct iommu_regs __iomem *regs; 10462306a36Sopenharmony_ci iopte_t *page_table; 10562306a36Sopenharmony_ci /* For convenience */ 10662306a36Sopenharmony_ci unsigned long start; /* First managed virtual address */ 10762306a36Sopenharmony_ci unsigned long end; /* Last managed virtual address */ 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci struct bit_map usemap; 11062306a36Sopenharmony_ci}; 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_cistatic inline void iommu_invalidate(struct iommu_regs __iomem *regs) 11362306a36Sopenharmony_ci{ 11462306a36Sopenharmony_ci sbus_writel(0, ®s->tlbflush); 11562306a36Sopenharmony_ci} 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_cistatic inline void iommu_invalidate_page(struct iommu_regs __iomem *regs, unsigned long ba) 11862306a36Sopenharmony_ci{ 11962306a36Sopenharmony_ci sbus_writel(ba & PAGE_MASK, ®s->pageflush); 12062306a36Sopenharmony_ci} 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci#endif /* !(_SPARC_IOMMU_H) */ 123