/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved.
*/
/*
* PCI iommu initialization and configuration
*/
#include <sys/sysmacros.h>
#include <sys/ddi_impldefs.h>
#include <sys/iommutsb.h>
/*LINTLIBRARY*/
void
{
uintptr_t a;
/*
* Allocate iommu state structure and link it to the
* pci state structure.
*/
/*
* chip specific dvma_end, tsb_size & context support
*/
a = pci_iommu_setup(iommu_p);
/*
* Determine the virtual address of iommu registers.
*/
(uint64_t *)(a + COMMON_IOMMU_CTRL_REG_OFFSET);
(uint64_t *)(a + COMMON_IOMMU_FLUSH_PAGE_REG_OFFSET);
/*
* Configure the rest of the iommu parameters according to:
* tsb_size and dvma_end
*/
- (tsb_entries * IOMMU_PAGE_SIZE);
/*
* export "virtual-dma" software property to support
* child devices needing to know DVMA range
*/
sizeof (pci_dvma_range));
"iommu_create: tsb size=%x, tsb entries=%x, dvma base=%x\n",
"iommu_create: dvma_cache_locks=%x cache_entries=%x\n",
/*
* zero out the area to be used for iommu tsb
*/
/*
* Create a virtual memory map for dvma address space.
* Reserve 'size' bytes of low dvma space for fast track cache.
*/
cache_size - 1;
/*
* On detach, the TSB Base Address Register gets set to zero,
* so if its zero here, there is no need to preserve TTEs.
*/
}
void
{
#ifdef DEBUG
#endif
/*
* Disable the IOMMU by setting the TSB Base Address to zero
* and the TSB Table size to the smallest possible.
*/
*iommu_p->iommu_tsb_base_addr_reg = 0;
/*
* Return the boot time allocated tsb.
*/
/*
* Teardown any implementation-specific structures set up in
* pci_iommu_setup.
*/
if (DVMA_DBG_ON(iommu_p))
/*
* Free the dvma resource map.
*/
/*
* Free the iommu state structure.
*/
}
/*
* re-program iommu on the fly while preserving on-going dma
* transactions on the PCI bus.
*/
void
{
(0 /* 8k page */ << COMMON_IOMMU_CTRL_TBW_SZ_SHIFT) |
(pci_lock_tlb ? COMMON_IOMMU_CTRL_LCK_ENABLE : 0));
goto config;
}
int reg_len;
continue;
break;
}
}
void
{
int i;
#ifdef DEBUG
#endif
"iommu_map_pages:%x+%x=%x npages=0x%x pfn_index=0x%x\n",
"iommu_map_pages: pg_index=%x tte=%08x.%08x\n",
#ifdef DEBUG
if (pfn == 0 && pci_warn_pp0)
#endif
}
#ifdef DEBUG
if (HAS_REDZONE(mp)) {
pg_index);
}
#endif
if (DVMA_DBG_ON(iommu_p))
}
/*
* iommu_map_window - map a dvma window into the iommu
*
* used by: pci_dma_win(), pci_dma_ctlops() - DDI_DMA_MOVWIN
*
* return value: none
*/
/*ARGSUSED*/
void
{
return;
}
void
{
if (!tm_mtlb_gc)
}
}
void
{
}
/*
* iommu_unmap_window
*
* This routine is called to break down the iommu mappings to a dvma window.
* Non partial mappings are viewed as single window mapping.
*
* used by: pci_dma_unbindhdl(), pci_dma_window(),
* and pci_dma_ctlops() - DDI_DMA_FREE, DDI_DMA_MOVWIN, DDI_DMA_NEXTWIN
*
* return value: none
*/
/*ARGSUSED*/
void
{
#ifdef DEBUG
#endif
/*
* Invalidate each page of the mapping in the tsb and flush
* it from the tlb.
*/
}
} else
if (DVMA_DBG_ON(iommu_p))
}
int
{
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
void
{
}
#if 0
/*
* The following data structure is used to map a tsb size
* to a tsb size configuration parameter in the iommu
* control register.
* This is a hardware table. It is here for reference only.
*/
static int pci_iommu_tsb_sizes[] = {
0x2000, /* 0 - 8 mb */
0x4000, /* 1 - 16 mb */
0x8000, /* 2 - 32 mb */
0x10000, /* 3 - 64 mb */
0x20000, /* 4 - 128 mb */
0x40000, /* 5 - 256 mb */
0x80000, /* 6 - 512 mb */
0x100000 /* 7 - 1 gb */
};
#endif
{
uint_t i;
/* empty */;
return (i);
}
/*
* invalidate IOMMU TLB entries through diagnostic registers.
*/
static void
{
int i;
for (i = 0; i < IOMMU_TLB_ENTRIES; i++)
}
static void
{
#ifdef DEBUG
#endif
"iommu_tsb_base_addr_reg=0x%08x (0x%08x.0x%08x)\n",
/*
* old darwin prom does not set tsb size correctly, bail out.
*/
if ((obp_tsb_size == IOMMU_DARWIN_BOGUS_TSBSIZE) &&
return;
"iommu_tsb_vaddr=%08x copy to base_tte_addr=%08x "
"obp_tsb_entries=0x%x obp_tsb_pa=%08x.%08x\n", obp_tsb_entries,
for (i = 0; i < obp_tsb_entries; i++) {
if (TTE_IS_INVALID(tte)) {
continue;
}
base_tte_addr[i] = tte;
"\npreserve_tsb: (%x)=%08x.%08x\n", base_tte_addr + i,
/*
* permanantly reserve this page from dvma address space
* resource map
*/
}
}