freebsd-dev/sys/sparc64/include/iommureg.h

213 lines
7.5 KiB
C
Raw Normal View History

/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)sbusreg.h 8.1 (Berkeley) 6/11/93
* from: NetBSD: iommureg.h,v 1.6 2001/07/20 00:07:13 eeh Exp
*
* $FreeBSD$
*/
#ifndef _MACHINE_IOMMUREG_H_
2009-12-23 21:51:41 +00:00
#define _MACHINE_IOMMUREG_H_
/*
Rototill the sparc64 nexus(4) (actually this brings in the code the sun4v nexus(4) in turn is based on): o Change nexus(4) to manage the resources of its children so the respective device drivers don't need to figure them out of OFW themselves. o Change nexus(4) to provide the ofw_bus KOBJ interface instead of using IVARs for supplying the OFW node and the subset of standard properties of its children. Together with the previous change this also allows to fully take advantage of newbus in that drivers like fhc(4), which attach on multiple parent busses, no longer require different bus front-ends as obtaining the OFW node and properties as well as resource allocation works the same for all supported busses. As such this change also is part 4/4 of allowing creator(4) to work in USIII-based machines as it allows this driver to attach on both nexus(4) and upa(4). On the other hand removing these IVARs breaks API compatibility with the powerpc nexus(4) but which isn't that bad as a) sparc64 currently doesn't share any device driver hanging off of nexus(4) with powerpc and b) they were no longer compatible regarding OFW-related extensions at the pci(4) level since quite some time. o Provide bus_get_dma_tag methods in nexus(4) and its children in order to handle DMA tags in a hierarchical way and get rid of the sparc64_root_dma_tag kludge. Together with the previous two items this changes also allows to completely get rid of the nexus(4) IVAR interface. It also includes: - pushing the constraints previously specified by the nexus_dmatag down into the DMA tags of psycho(4) and sbus(4) as it's their IOMMUs which induce these restrictions (and nothing at the nexus(4) or anything that would warrant specifying them there), - fixing some obviously wrong constraints of the psycho(4) and sbus(4) DMA tags, which happened to not actually be used with the sparc64_root_dma_tag kludge in place and therefore didn't cause problems so far, - replacing magic constants for constraints with macros as far as it is obvious as to where they come from. This doesn't include taking advantage of the newbus way to get the parent DMA tags implemented by this change in order to divorce the IOTSBs of the PCI and SBus IOMMUs or for implementing the workaround for the DMA sync bug in Sabre (and Tomatillo) bridges, yet, though. o Get rid of the notion that nexus(4) (mostly) reflects an UPA bus by replacing ofw_upa.h and with ofw_nexus.h (which was repo-copied from ofw_upa.h) and renaming its content, which actually applies to all of Fireplane/Safari, JBus and UPA (in the host bus case), as appropriate. o Just use M_DEVBUF instead of a separate M_NEXUS malloc type for allocating the device info for the children of nexus(4). This is done in order to not need to export M_NEXUS when deriving drivers for subordinate busses from the nexus(4) class. o Use the DEFINE_CLASS_0() macro to declare the nexus(4) driver so we can derive subclasses from it. o Const'ify the nexus_excl_name and nexus_excl_type arrays as well as add 'associations' and 'rsc', which are pseudo-devices without resources and therefore of no real interest for nexus(4), to the former. o Let the nexus(4) device memory rman manage the entire 64-bit address space instead of just the UPA_MEMSTART to UPA_MEMEND subregion as Fireplane/Safari- and JBus-based machines use multiple ranges, which can't be as easily divided as in the case of UPA (limiting the address space only served for sanity checking anyway). o Use M_WAITOK instead of M_NOWAIT when allocating the device info for children of nexus(4) in order to give one less opportunity for adding devices to nexus(4) to fail. o While adapting the drivers affected by the above nexus(4) changes, change them to take advantage of rman_get_rid() instead of caching the RIDs assigned to allocated resources, now that the RIDs of resources are correctly set. o In iommu(4) and nexus(4) replace hard-coded functions names, which actually became outdated in several places, in panic strings and status massages with __func__. [1] o Use driver_filter_t in prototypes where appropriate. o Add my copyright to creator(4), fhc(4), nexus(4), psycho(4) and sbus(4) as I changed considerable amounts of these drivers as well as added a bunch of new features, workarounds for silicon bugs etc. o Fix some white space nits. Due to lack of access to Exx00 hardware, these changes, i.e. central(4) and fhc(4), couldn't be runtime tested on such a machine. Exx00 are currently reported to panic before trying to attach nexus(4) anyway though. PR: 76052 [1] Approved by: re (kensmith)
2007-03-07 21:13:51 +00:00
* UltraSPARC IOMMU registers, common to both the PCI and SBus
* controllers.
*/
/* IOMMU registers */
#define IMR_CTL 0x0000 /* IOMMU control register */
#define IMR_TSB 0x0008 /* IOMMU TSB base register */
#define IMR_FLUSH 0x0010 /* IOMMU flush register */
/* The TTE Cache is Fire and Oberon only. */
#define IMR_CACHE_FLUSH 0x0100 /* IOMMU TTE cache flush address register */
#define IMR_CACHE_INVAL 0x0108 /* IOMMU TTE cache invalidate register */
/* streaming buffer registers */
#define ISR_CTL 0x0000 /* streaming buffer control reg */
#define ISR_PGFLUSH 0x0008 /* streaming buffer page flush */
#define ISR_FLUSHSYNC 0x0010 /* streaming buffer flush sync */
/* streaming buffer diagnostics registers */
#define ISD_DATA_DIAG 0x0000 /* streaming buffer data RAM diag 0..127 */
#define ISD_ERROR_DIAG 0x0400 /* streaming buffer error status diag 0..127 */
#define ISD_PG_TAG_DIAG 0x0800 /* streaming buffer page tag diag 0..15 */
#define ISD_LN_TAG_DIAG 0x0900 /* streaming buffer line tag diag 0..15 */
/* streaming buffer control register */
2009-12-23 21:51:41 +00:00
#define STRBUF_EN 0x0000000000000001UL
#define STRBUF_D 0x0000000000000002UL
#define STRBUF_RR_DIS 0x0000000000000004UL
- Divorce the IOTSBs, which so far where handled via a global list instead of per IOMMU, so we no longer need to program all of them identically in systems having multiple IOMMUs. This continues the rototilling of the nexus(4) done about 5 months ago, which amongst others changed nexus(4) and the drivers for host-to-foo bridges to provide bus_get_dma_tag methods, allowing to handle DMA tags in a hierarchical way and to link them with devices. This still doesn't move the silicon bug workarounds for Sabre (and in the uncommitted schizo(4) for Tomatillo) bridges into special bus_dma_tag_create() and bus_dmamap_sync() methods though, as w/o fully newbus'ified bus_dma_tag_create() and bus_dma_tag_destroy() this still requires too much hackery, i.e. per-child parent DMA tags in the parent driver. - Let the host-to-foo drivers supply the maximum physical address of the IOMMU accompanying the bridges. Previously iommu(4) hard- coded an upper limit of 16GB, which actually only applies to the IOMMUs of the Hummingbird and Sabre bridges. The Psycho variants as well as the U2S in fact can can translate to up to 2TB, i.e. translate to 41-bit physical addresses. According to the recently available Tomatillo documentation these bridges even translate to 43-bit physical addresses and hints at the Schizo bridges doing 43 bits as well. This fixes the issue the FreeBSD 6.0 todo list item "Max RAM on sparc64" was refering to and pretty much obsoletes the lack of support for bounce buffers on sparc64. Thanks to Nathan Whitehorn for pointing me at the Tomatillo manual. Approved by: re (kensmith)
2007-08-05 11:56:44 +00:00
#define IOMMU_MAXADDR(bits) ((1UL << (bits)) - 1)
/*
* control register bits
*/
/* Nummber of entries in the IOTSB - pre-Fire only */
#define IOMMUCR_TSBSZ_MASK 0x0000000000070000UL
#define IOMMUCR_TSBSZ_SHIFT 16
/* TSB cache snoop enable */
#define IOMMUCR_SE 0x0000000000000400UL
/* Cache modes - Fire and Oberon */
#define IOMMUCR_CM_NC_TLB_TBW 0x0000000000000000UL
#define IOMMUCR_CM_LC_NTLB_NTBW 0x0000000000000100UL
#define IOMMUCR_CM_LC_TLB_TBW 0x0000000000000200UL
#define IOMMUCR_CM_C_TLB_TBW 0x0000000000000300UL
/* IOMMU page size - pre-Fire only */
2009-12-23 21:51:41 +00:00
#define IOMMUCR_8KPG 0x0000000000000000UL
#define IOMMUCR_64KPG 0x0000000000000004UL
/* Bypass enable - Fire and Oberon */
#define IOMMUCR_BE 0x0000000000000002UL
/* Diagnostic mode enable - pre-Fire only */
2009-12-23 21:51:41 +00:00
#define IOMMUCR_DE 0x0000000000000002UL
/* IOMMU/translation enable */
2009-12-23 21:51:41 +00:00
#define IOMMUCR_EN 0x0000000000000001UL
/*
* TSB base register bits
*/
/* TSB base address */
#define IOMMUTB_TB_MASK 0x000007ffffffe000UL
#define IOMMUTB_TB_SHIFT 13
/* IOMMU page size - Fire and Oberon */
#define IOMMUTB_8KPG 0x0000000000000000UL
#define IOMMUTB_64KPG 0x0000000000000100UL
/* Nummber of entries in the IOTSB - Fire and Oberon */
#define IOMMUTB_TSBSZ_MASK 0x0000000000000004UL
#define IOMMUTB_TSBSZ_SHIFT 0
/*
* TSB size definitions for both control and TSB base register */
#define IOMMU_TSB1K 0
#define IOMMU_TSB2K 1
#define IOMMU_TSB4K 2
#define IOMMU_TSB8K 3
#define IOMMU_TSB16K 4
#define IOMMU_TSB32K 5
#define IOMMU_TSB64K 6
#define IOMMU_TSB128K 7
/* Fire and Oberon */
#define IOMMU_TSB256K 8
/* Fire and Oberon */
#define IOMMU_TSB512K 9
#define IOMMU_TSBENTRIES(tsbsz) \
((1 << (tsbsz)) << (IO_PAGE_SHIFT - IOTTE_SHIFT))
/*
* Diagnostic register definitions
*/
#define IOMMU_DTAG_VPNBITS 19
#define IOMMU_DTAG_VPNMASK ((1 << IOMMU_DTAG_VPNBITS) - 1)
#define IOMMU_DTAG_VPNSHIFT 13
2009-12-23 21:51:41 +00:00
#define IOMMU_DTAG_ERRBITS 3
#define IOMMU_DTAG_ERRSHIFT 22
2009-12-23 21:51:41 +00:00
#define IOMMU_DTAG_ERRMASK \
(((1 << IOMMU_DTAG_ERRBITS) - 1) << IOMMU_DTAG_ERRSHIFT)
#define IOMMU_DDATA_PGBITS 21
#define IOMMU_DDATA_PGMASK ((1 << IOMMU_DDATA_PGBITS) - 1)
#define IOMMU_DDATA_PGSHIFT 13
#define IOMMU_DDATA_C (1 << 28)
#define IOMMU_DDATA_V (1 << 30)
/*
* IOMMU stuff
*/
/* Entry valid */
#define IOTTE_V 0x8000000000000000UL
/* Page size - pre-Fire only */
2009-12-23 21:51:41 +00:00
#define IOTTE_64K 0x2000000000000000UL
#define IOTTE_8K 0x0000000000000000UL
/* Streamable page - streaming buffer equipped variants only */
2009-12-23 21:51:41 +00:00
#define IOTTE_STREAM 0x1000000000000000UL
/* Accesses to the same bus segment - SBus only */
#define IOTTE_LOCAL 0x0800000000000000UL
/* Physical address mask (based on Oberon) */
#define IOTTE_PAMASK 0x00007fffffffe000UL
/* Accesses to cacheable space - pre-Fire only */
2009-12-23 21:51:41 +00:00
#define IOTTE_C 0x0000000000000010UL
/* Writeable */
2009-12-23 21:51:41 +00:00
#define IOTTE_W 0x0000000000000002UL
/* log2 of the IOMMU TTE size */
#define IOTTE_SHIFT 3
/* Streaming buffer line size */
#define STRBUF_LINESZ 64
/*
* Number of bytes written by a stream buffer flushsync operation to indicate
* completion.
*/
#define STRBUF_FLUSHSYNC_NBYTES STRBUF_LINESZ
/*
Rototill the sparc64 nexus(4) (actually this brings in the code the sun4v nexus(4) in turn is based on): o Change nexus(4) to manage the resources of its children so the respective device drivers don't need to figure them out of OFW themselves. o Change nexus(4) to provide the ofw_bus KOBJ interface instead of using IVARs for supplying the OFW node and the subset of standard properties of its children. Together with the previous change this also allows to fully take advantage of newbus in that drivers like fhc(4), which attach on multiple parent busses, no longer require different bus front-ends as obtaining the OFW node and properties as well as resource allocation works the same for all supported busses. As such this change also is part 4/4 of allowing creator(4) to work in USIII-based machines as it allows this driver to attach on both nexus(4) and upa(4). On the other hand removing these IVARs breaks API compatibility with the powerpc nexus(4) but which isn't that bad as a) sparc64 currently doesn't share any device driver hanging off of nexus(4) with powerpc and b) they were no longer compatible regarding OFW-related extensions at the pci(4) level since quite some time. o Provide bus_get_dma_tag methods in nexus(4) and its children in order to handle DMA tags in a hierarchical way and get rid of the sparc64_root_dma_tag kludge. Together with the previous two items this changes also allows to completely get rid of the nexus(4) IVAR interface. It also includes: - pushing the constraints previously specified by the nexus_dmatag down into the DMA tags of psycho(4) and sbus(4) as it's their IOMMUs which induce these restrictions (and nothing at the nexus(4) or anything that would warrant specifying them there), - fixing some obviously wrong constraints of the psycho(4) and sbus(4) DMA tags, which happened to not actually be used with the sparc64_root_dma_tag kludge in place and therefore didn't cause problems so far, - replacing magic constants for constraints with macros as far as it is obvious as to where they come from. This doesn't include taking advantage of the newbus way to get the parent DMA tags implemented by this change in order to divorce the IOTSBs of the PCI and SBus IOMMUs or for implementing the workaround for the DMA sync bug in Sabre (and Tomatillo) bridges, yet, though. o Get rid of the notion that nexus(4) (mostly) reflects an UPA bus by replacing ofw_upa.h and with ofw_nexus.h (which was repo-copied from ofw_upa.h) and renaming its content, which actually applies to all of Fireplane/Safari, JBus and UPA (in the host bus case), as appropriate. o Just use M_DEVBUF instead of a separate M_NEXUS malloc type for allocating the device info for the children of nexus(4). This is done in order to not need to export M_NEXUS when deriving drivers for subordinate busses from the nexus(4) class. o Use the DEFINE_CLASS_0() macro to declare the nexus(4) driver so we can derive subclasses from it. o Const'ify the nexus_excl_name and nexus_excl_type arrays as well as add 'associations' and 'rsc', which are pseudo-devices without resources and therefore of no real interest for nexus(4), to the former. o Let the nexus(4) device memory rman manage the entire 64-bit address space instead of just the UPA_MEMSTART to UPA_MEMEND subregion as Fireplane/Safari- and JBus-based machines use multiple ranges, which can't be as easily divided as in the case of UPA (limiting the address space only served for sanity checking anyway). o Use M_WAITOK instead of M_NOWAIT when allocating the device info for children of nexus(4) in order to give one less opportunity for adding devices to nexus(4) to fail. o While adapting the drivers affected by the above nexus(4) changes, change them to take advantage of rman_get_rid() instead of caching the RIDs assigned to allocated resources, now that the RIDs of resources are correctly set. o In iommu(4) and nexus(4) replace hard-coded functions names, which actually became outdated in several places, in panic strings and status massages with __func__. [1] o Use driver_filter_t in prototypes where appropriate. o Add my copyright to creator(4), fhc(4), nexus(4), psycho(4) and sbus(4) as I changed considerable amounts of these drivers as well as added a bunch of new features, workarounds for silicon bugs etc. o Fix some white space nits. Due to lack of access to Exx00 hardware, these changes, i.e. central(4) and fhc(4), couldn't be runtime tested on such a machine. Exx00 are currently reported to panic before trying to attach nexus(4) anyway though. PR: 76052 [1] Approved by: re (kensmith)
2007-03-07 21:13:51 +00:00
* On sun4u each bus controller has a separate IOMMU. The IOMMU has
* a TSB which must be page aligned and physically contiguous. Mappings
* can be of 8K IOMMU pages or 64K IOMMU pages. We use 8K for compatibility
* with the CPU's MMU.
*
* On sysio, psycho, and psycho+, IOMMU TSBs using 8K pages can map the
* following size segments:
*
* VA size VA base TSB size tsbsize
* -------- -------- --------- -------
* 8MB ff800000 8K 0
* 16MB ff000000 16K 1
* 32MB fe000000 32K 2
* 64MB fc000000 64K 3
* 128MB f8000000 128K 4
* 256MB f0000000 256K 5
* 512MB e0000000 512K 6
* 1GB c0000000 1MB 7
*
* Unfortunately, sabres on UltraSPARC IIi and IIe processors does not use
* this scheme to determine the IOVA base address. Instead, bits 31-29 are
* used to check against the Target Address Space register in the IIi and
* the IOMMU is used if they hit. God knows what goes on in the IIe.
*
*/
#define IOTSB_BASESZ (1024 << IOTTE_SHIFT)
2009-12-23 21:51:41 +00:00
#define IOTSB_VEND (~IO_PAGE_MASK)
#define IOTSB_VSTART(sz) (u_int)(IOTSB_VEND << ((sz) + 10))
2009-12-23 21:51:41 +00:00
#define MAKEIOTTE(pa, w, c, s) \
(((pa) & IOTTE_PAMASK) | ((w) ? IOTTE_W : 0) | \
((c) ? IOTTE_C : 0) | ((s) ? IOTTE_STREAM : 0) | \
(IOTTE_V | IOTTE_8K))
2009-12-23 21:51:41 +00:00
#define IOTSBSLOT(va) \
((u_int)(((vm_offset_t)(va)) - (is->is_dvmabase)) >> IO_PAGE_SHIFT)
#endif /* !_MACHINE_IOMMUREG_H_ */