// SPDX-License-Identifier: GPL-2.0-or-later /* ** ccio-dma.c: ** DMA management routines for first generation cache-coherent machines. ** Program U2/Uturn in "Virtual Mode" and use the I/O MMU. ** ** (c) Copyright 2000 Grant Grundler ** (c) Copyright 2000 Ryan Bradetich ** (c) Copyright 2000 Hewlett-Packard Company ** ** "Real Mode" operation refers to U2/Uturn chip operation. ** U2/Uturn were designed to perform coherency checks w/o using ** the I/O MMU - basically what x86 does. ** ** Drawbacks of using Real Mode are: ** o outbound DMA is slower - U2 won't prefetch data (GSC+ XQL signal). ** o Inbound DMA less efficient - U2 can't use DMA_FAST attribute. ** o Ability to do scatter/gather in HW is lost. ** o Doesn't work under PCX-U/U+ machines since they didn't follow ** the coherency design originally worked out. Only PCX-W does.
*/
/* ** IOA Registers ** ------------- ** ** Runway IO_CONTROL Register (+0x38) ** ** The Runway IO_CONTROL register controls the forwarding of transactions. ** ** | 0 ... 13 | 14 15 | 16 ... 21 | 22 | 23 24 | 25 ... 31 | ** | HV | TLB | reserved | HV | mode | reserved | ** ** o mode field indicates the address translation of transactions ** forwarded from Runway to GSC+: ** Mode Name Value Definition ** Off (default) 0 Opaque to matching addresses. ** Include 1 Transparent for matching addresses. ** Peek 3 Map matching addresses. ** ** + "Off" mode: Runway transactions which match the I/O range ** specified by the IO_IO_LOW/IO_IO_HIGH registers will be ignored. ** + "Include" mode: all addresses within the I/O range specified ** by the IO_IO_LOW and IO_IO_HIGH registers are transparently ** forwarded. This is the I/O Adapter's normal operating mode. ** + "Peek" mode: used during system configuration to initialize the ** GSC+ bus. Runway Write_Shorts in the address range specified by ** IO_IO_LOW and IO_IO_HIGH are forwarded through the I/O Adapter ** *AND* the GSC+ address is remapped to the Broadcast Physical ** Address space by setting the 14 high order address bits of the ** 32 bit GSC+ address to ones. ** ** o TLB field affects transactions which are forwarded from GSC+ to Runway. ** "Real" mode is the poweron default. ** ** TLB Mode Value Description ** Real 0 No TLB translation. Address is directly mapped and the ** virtual address is composed of selected physical bits. ** Error 1 Software fills the TLB manually. ** Normal 2 IOA fetches IO TLB misses from IO PDIR (in host memory). ** ** ** IO_IO_LOW_HV +0x60 (HV dependent) ** IO_IO_HIGH_HV +0x64 (HV dependent) ** IO_IO_LOW +0x78 (Architected register) ** IO_IO_HIGH +0x7c (Architected register) ** ** IO_IO_LOW and IO_IO_HIGH set the lower and upper bounds of the ** I/O Adapter address space, respectively. ** ** 0 ... 7 | 8 ... 15 | 16 ... 31 | ** 11111111 | 11111111 | address | ** ** Each LOW/HIGH pair describes a disjoint address space region. ** (2 per GSC+ port). Each incoming Runway transaction address is compared ** with both sets of LOW/HIGH registers. If the address is in the range ** greater than or equal to IO_IO_LOW and less than IO_IO_HIGH the transaction ** for forwarded to the respective GSC+ bus. ** Specify IO_IO_LOW equal to or greater than IO_IO_HIGH to avoid specifying ** an address space region. ** ** In order for a Runway address to reside within GSC+ extended address space: ** Runway Address [0:7] must identically compare to 8'b11111111 ** Runway Address [8:11] must be equal to IO_IO_LOW(_HV)[16:19] ** Runway Address [12:23] must be greater than or equal to ** IO_IO_LOW(_HV)[20:31] and less than IO_IO_HIGH(_HV)[20:31]. ** Runway Address [24:39] is not used in the comparison. ** ** When the Runway transaction is forwarded to GSC+, the GSC+ address is ** as follows: ** GSC+ Address[0:3] 4'b1111 ** GSC+ Address[4:29] Runway Address[12:37] ** GSC+ Address[30:31] 2'b00 ** ** All 4 Low/High registers must be initialized (by PDC) once the lower bus ** is interrogated and address space is defined. The operating system will ** modify the architectural IO_IO_LOW and IO_IO_HIGH registers following ** the PDC initialization. However, the hardware version dependent IO_IO_LOW ** and IO_IO_HIGH registers should not be subsequently altered by the OS. ** ** Writes to both sets of registers will take effect immediately, bypassing ** the queues, which ensures that subsequent Runway transactions are checked ** against the updated bounds values. However reads are queued, introducing ** the possibility of a read being bypassed by a subsequent write to the same ** register. This sequence can be avoided by having software wait for read ** returns before issuing subsequent writes.
*/
struct ioc { struct ioa_registers __iomem *ioc_regs; /* I/O MMU base address */
u8 *res_map; /* resource map, bit == pdir entry */
__le64 *pdir_base; /* physical base address */
u32 pdir_size; /* bytes, function of IOV Space size */
u32 res_hint; /* next available IOVP -
circular search */
u32 res_size; /* size of resource map in bytes */
spinlock_t res_lock;
/* STUFF We don't need in performance path */
u32 chainid_shift; /* specify bit location of chain_id */ struct ioc *next; /* Linked list of discovered iocs */ constchar *name; /* device name from firmware */ unsignedint hw_path; /* the hardware path this ioc is associatd with */ struct pci_dev *fake_pci_dev; /* the fake pci_dev for non-pci devs */ struct resource mmio_region[2]; /* The "routed" MMIO regions */
};
staticstruct ioc *ioc_list; staticint ioc_count;
/************************************************************** * * I/O Pdir Resource Management * * Bits set in the resource map are in use. * Each bit can represent a number of pages. * LSbs represent lower addresses (IOVA's). * * This was copied from sba_iommu.c. Don't try to unify * the two resource managers unless a way to have different * allocation policies is also adjusted. We'd like to avoid * I/O TLB thrashing by having resource allocation policy * match the I/O TLB replacement policy. *
***************************************************************/ #define IOVP_SIZE PAGE_SIZE #define IOVP_SHIFT PAGE_SHIFT #define IOVP_MASK PAGE_MASK
/* Convert from IOVP to IOVA and vice versa. */ #define CCIO_IOVA(iovp,offset) ((iovp) | (offset)) #define CCIO_IOVP(iova) ((iova) & IOVP_MASK)
/* ** Find available bit in this ioa's resource map. ** Use a "circular" search: ** o Most IOVA's are "temporary" - avg search time should be small. ** o keep a history of what happened for debugging ** o KISS. ** ** Perf optimizations: ** o search for log2(size) bits at a time. ** o search for available resource bits using byte/word/whatever. ** o use different search for "large" (eg > 4 pages) or "very large" ** (eg > 16 pages) mappings.
*/
/** * ccio_alloc_range - Allocate pages in the ioc's resource map. * @ioc: The I/O Controller. * @dev: The PCI device. * @size: The requested number of bytes to be mapped into the * I/O Pdir... * * This function searches the resource map of the ioc to locate a range * of available pages for the requested size.
*/ staticint
ccio_alloc_range(struct ioc *ioc, struct device *dev, size_t size)
{ unsignedint pages_needed = size >> IOVP_SHIFT; unsignedint res_idx; unsignedlong boundary_size; #ifdef CCIO_COLLECT_STATS unsignedlong cr_start = mfctl(16); #endif
if (pages_needed <= 8) { /* * LAN traffic will not thrash the TLB IFF the same NIC * uses 8 adjacent pages to map separate payload data. * ie the same byte in the resource bit map.
*/ #if 0 /* FIXME: bit search should shift it's way through * an unsigned long - not byte at a time. As it is now, * we effectively allocate this byte to this mapping.
*/ unsignedlong mask = ~(~0UL >> pages_needed);
CCIO_FIND_FREE_MAPPING(ioc, res_idx, mask, 8); #else
CCIO_FIND_FREE_MAPPING(ioc, res_idx, 0xff, 8); #endif
} elseif (pages_needed <= 16) {
CCIO_FIND_FREE_MAPPING(ioc, res_idx, 0xffff, 16);
} elseif (pages_needed <= 32) {
CCIO_FIND_FREE_MAPPING(ioc, res_idx, ~(unsignedint)0, 32); #ifdef __LP64__
} elseif (pages_needed <= 64) {
CCIO_FIND_FREE_MAPPING(ioc, res_idx, ~0UL, 64); #endif
} else {
panic("%s: %s() Too many pages to map. pages_needed: %u\n",
__FILE__, __func__, pages_needed);
}
panic("%s: %s() I/O MMU is out of mapping resources.\n", __FILE__,
__func__);
/** * ccio_free_range - Free pages from the ioc's resource map. * @ioc: The I/O Controller. * @iova: The I/O Virtual Address. * @pages_mapped: The requested number of pages to be freed from the * I/O Pdir. * * This function frees the resouces allocated for the iova.
*/ staticvoid
ccio_free_range(struct ioc *ioc, dma_addr_t iova, unsignedlong pages_mapped)
{ unsignedlong iovp = CCIO_IOVP(iova); unsignedint res_idx = PDIR_INDEX(iovp) >> 3;
/* ** DMA "Page Type" and Hints ** o if SAFE_DMA isn't set, mapping is for FAST_DMA. SAFE_DMA should be ** set for subcacheline DMA transfers since we don't want to damage the ** other part of a cacheline. ** o SAFE_DMA must be set for "memory" allocated via pci_alloc_consistent(). ** This bit tells U2 to do R/M/W for partial cachelines. "Streaming" ** data can avoid this if the mapping covers full cache lines. ** o STOP_MOST is needed for atomicity across cachelines. ** Apparently only "some EISA devices" need this. ** Using CONFIG_ISA is hack. Only the IOA with EISA under it needs ** to use this hint iff the EISA devices needs this feature. ** According to the U2 ERS, STOP_MOST enabled pages hurt performance. ** o PREFETCH should *not* be set for cases like Multiple PCI devices ** behind GSCtoPCI (dino) bus converter. Only one cacheline per GSC ** device can be fetched and multiply DMA streams will thrash the ** prefetch buffer and burn memory bandwidth. See 6.7.3 "Prefetch Rules ** and Invalidation of Prefetch Entries". ** ** FIXME: the default hints need to be per GSC device - not global. ** ** HP-UX dorks: linux device driver programming model is totally different ** than HP-UX's. HP-UX always sets HINT_PREFETCH since it's drivers ** do special things to work on non-coherent platforms...linux has to ** be much more careful with this.
*/ #define IOPDIR_VALID 0x01UL #define HINT_SAFE_DMA 0x02UL /* used for pci_alloc_consistent() pages */ #ifdef CONFIG_EISA #define HINT_STOP_MOST 0x04UL /* LSL support */ #else #define HINT_STOP_MOST 0x00UL /* only needed for "some EISA devices" */ #endif #define HINT_UDPATE_ENB 0x08UL /* not used/supported by U2 */ #define HINT_PREFETCH 0x10UL /* for outbound pages which are not SAFE */
/* ** Use direction (ie PCI_DMA_TODEVICE) to pick hint. ** ccio_alloc_consistent() depends on this to get SAFE_DMA ** when it passes in BIDIRECTIONAL flag.
*/ static u32 hint_lookup[] = {
[DMA_BIDIRECTIONAL] = HINT_STOP_MOST | HINT_SAFE_DMA | IOPDIR_VALID,
[DMA_TO_DEVICE] = HINT_STOP_MOST | HINT_PREFETCH | IOPDIR_VALID,
[DMA_FROM_DEVICE] = HINT_STOP_MOST | IOPDIR_VALID,
};
/** * ccio_io_pdir_entry - Initialize an I/O Pdir. * @pdir_ptr: A pointer into I/O Pdir. * @sid: The Space Identifier. * @vba: The virtual address. * @hints: The DMA Hint. * * Given a virtual address (vba, arg2) and space id, (sid, arg1), * load the I/O PDIR entry pointed to by pdir_ptr (arg0). Each IO Pdir * entry consists of 8 bytes as shown below (MSB == bit 0): * * * WORD 0: * +------+----------------+-----------------------------------------------+ * | Phys | Virtual Index | Phys | * | 0:3 | 0:11 | 4:19 | * |4 bits| 12 bits | 16 bits | * +------+----------------+-----------------------------------------------+ * WORD 1: * +-----------------------+-----------------------------------------------+ * | Phys | Rsvd | Prefetch |Update |Rsvd |Lock |Safe |Valid | * | 20:39 | | Enable |Enable | |Enable|DMA | | * | 20 bits | 5 bits | 1 bit |1 bit |2 bits|1 bit |1 bit |1 bit | * +-----------------------+-----------------------------------------------+ * * The virtual index field is filled with the results of the LCI * (Load Coherence Index) instruction. The 8 bits used for the virtual * index are bits 12:19 of the value returned by LCI.
*/ staticvoid
ccio_io_pdir_entry(__le64 *pdir_ptr, space_t sid, unsignedlong vba, unsignedlong hints)
{ registerunsignedlong pa; registerunsignedlong ci; /* coherent index */
/* We currently only support kernel addresses */
BUG_ON(sid != KERNEL_SPACE);
/* ** WORD 1 - low order word ** "hints" parm includes the VALID bit! ** "dep" clobbers the physical address offset bits as well.
*/
pa = lpa(vba); asmvolatile("depw %1,31,12,%0" : "+r" (pa) : "r" (hints));
((u32 *)pdir_ptr)[1] = (u32) pa;
/* ** WORD 0 - high order word
*/
#ifdef __LP64__ /* ** get bits 12:15 of physical address ** shift bits 16:31 of physical address ** and deposit them
*/ asmvolatile ("extrd,u %1,15,4,%0" : "=r" (ci) : "r" (pa)); asmvolatile ("extrd,u %1,31,16,%0" : "+r" (pa) : "r" (pa)); asmvolatile ("depd %1,35,4,%0" : "+r" (pa) : "r" (ci)); #else
pa = 0; #endif /* ** get CPU coherency index bits ** Grab virtual index [0:11] ** Deposit virt_idx bits into I/O PDIR word
*/ asmvolatile ("lci %%r0(%1), %0" : "=r" (ci) : "r" (vba)); asmvolatile ("extru %1,19,12,%0" : "+r" (ci) : "r" (ci)); asmvolatile ("depw %1,15,12,%0" : "+r" (pa) : "r" (ci));
((u32 *)pdir_ptr)[0] = (u32) pa;
/* FIXME: PCX_W platforms don't need FDC/SYNC. (eg C360) ** PCX-U/U+ do. (eg C200/C240) ** PCX-T'? Don't know. (eg C110 or similar K-class) ** ** See PDC_MODEL/option 0/SW_CAP word for "Non-coherent IO-PDIR bit". ** ** "Since PCX-U employs an offset hash that is incompatible with ** the real mode coherence index generation of U2, the PDIR entry ** must be flushed to memory to retain coherence."
*/
asm_io_fdc(pdir_ptr);
asm_io_sync();
}
/** * ccio_clear_io_tlb - Remove stale entries from the I/O TLB. * @ioc: The I/O Controller. * @iovp: The I/O Virtual Page. * @byte_cnt: The requested number of bytes to be freed from the I/O Pdir. * * Purge invalid I/O PDIR entries from the I/O TLB. * * FIXME: Can we change the byte_cnt to pages_mapped?
*/ staticvoid
ccio_clear_io_tlb(struct ioc *ioc, dma_addr_t iovp, size_t byte_cnt)
{
u32 chain_size = 1 << ioc->chainid_shift;
/** * ccio_mark_invalid - Mark the I/O Pdir entries invalid. * @ioc: The I/O Controller. * @iova: The I/O Virtual Address. * @byte_cnt: The requested number of bytes to be freed from the I/O Pdir. * * Mark the I/O Pdir entries invalid and blow away the corresponding I/O * TLB entries. * * FIXME: at some threshold it might be "cheaper" to just blow * away the entire I/O TLB instead of individual entries. * * FIXME: Uturn has 256 TLB entries. We don't need to purge every * PDIR entry - just once for each possible TLB entry. * (We do need to maker I/O PDIR entries invalid regardless). * * FIXME: Can we change byte_cnt to pages_mapped?
*/ staticvoid
ccio_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt)
{
u32 iovp = (u32)CCIO_IOVP(iova);
size_t saved_byte_cnt;
/* round up to nearest page size */
saved_byte_cnt = byte_cnt = ALIGN(byte_cnt, IOVP_SIZE);
while(byte_cnt > 0) { /* invalidate one page at a time */ unsignedint idx = PDIR_INDEX(iovp); char *pdir_ptr = (char *) &(ioc->pdir_base[idx]);
BUG_ON(idx >= (ioc->pdir_size / sizeof(u64)));
pdir_ptr[7] = 0; /* clear only VALID bit */ /* ** FIXME: PCX_W platforms don't need FDC/SYNC. (eg C360) ** PCX-U/U+ do. (eg C200/C240) ** See PDC_MODEL/option 0/SW_CAP for "Non-coherent IO-PDIR bit".
*/
asm_io_fdc(pdir_ptr);
/** * ccio_dma_supported - Verify the IOMMU supports the DMA address range. * @dev: The PCI device. * @mask: A bit mask describing the DMA address range of the device.
*/ staticint
ccio_dma_supported(struct device *dev, u64 mask)
{ if(dev == NULL) {
printk(KERN_ERR MODULE_NAME ": EISA/ISA/et al not supported\n");
BUG(); return 0;
}
/* only support 32-bit or better devices (ie PCI/GSC) */ return (int)(mask >= 0xffffffffUL);
}
/** * ccio_map_single - Map an address range into the IOMMU. * @dev: The PCI device. * @addr: The start address of the DMA region. * @size: The length of the DMA region. * @direction: The direction of the DMA transaction (to/from device). * * This function implements the pci_map_single function.
*/ static dma_addr_t
ccio_map_single(struct device *dev, void *addr, size_t size, enum dma_data_direction direction)
{ int idx; struct ioc *ioc; unsignedlong flags;
dma_addr_t iovp;
dma_addr_t offset;
__le64 *pdir_start; unsignedlong hint = hint_lookup[(int)direction];
BUG_ON(!dev);
ioc = GET_IOC(dev); if (!ioc) return DMA_MAPPING_ERROR;
/* If not cacheline aligned, force SAFE_DMA on the whole mess */ if((size % L1_CACHE_BYTES) || ((unsignedlong)addr % L1_CACHE_BYTES))
hint |= HINT_SAFE_DMA;
/** * ccio_unmap_page - Unmap an address range from the IOMMU. * @dev: The PCI device. * @iova: The start address of the DMA region. * @size: The length of the DMA region. * @direction: The direction of the DMA transaction (to/from device). * @attrs: attributes
*/ staticvoid
ccio_unmap_page(struct device *dev, dma_addr_t iova, size_t size, enum dma_data_direction direction, unsignedlong attrs)
{ struct ioc *ioc; unsignedlong flags;
dma_addr_t offset = iova & ~IOVP_MASK;
BUG_ON(!dev);
ioc = GET_IOC(dev); if (!ioc) {
WARN_ON(!ioc); return;
}
/** * ccio_alloc - Allocate a consistent DMA mapping. * @dev: The PCI device. * @size: The length of the DMA region. * @dma_handle: The DMA address handed back to the device (not the cpu). * @flag: allocation flags * @attrs: attributes * * This function implements the pci_alloc_consistent function.
*/ staticvoid *
ccio_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag, unsignedlong attrs)
{ void *ret; #if 0 /* GRANT Need to establish hierarchy for non-PCI devs as well ** and then provide matching gsc_map_xxx() functions for them as well.
*/ if(!hwdev) { /* only support PCI */
*dma_handle = 0; return 0;
} #endif
ret = (void *) __get_free_pages(flag, get_order(size));
/** * ccio_free - Free a consistent DMA mapping. * @dev: The PCI device. * @size: The length of the DMA region. * @cpu_addr: The cpu address returned from the ccio_alloc_consistent. * @dma_handle: The device address returned from the ccio_alloc_consistent. * @attrs: attributes * * This function implements the pci_free_consistent function.
*/ staticvoid
ccio_free(struct device *dev, size_t size, void *cpu_addr,
dma_addr_t dma_handle, unsignedlong attrs)
{
ccio_unmap_page(dev, dma_handle, size, 0, 0);
free_pages((unsignedlong)cpu_addr, get_order(size));
}
/* ** Since 0 is a valid pdir_base index value, can't use that ** to determine if a value is valid or not. Use a flag to indicate ** the SG list entry contains a valid pdir index.
*/ #define PIDE_FLAG 0x80000000UL
/** * ccio_map_sg - Map the scatter/gather list into the IOMMU. * @dev: The PCI device. * @sglist: The scatter/gather list to be mapped in the IOMMU. * @nents: The number of entries in the scatter/gather list. * @direction: The direction of the DMA transaction (to/from device). * @attrs: attributes * * This function implements the pci_map_sg function.
*/ staticint
ccio_map_sg(struct device *dev, struct scatterlist *sglist, int nents, enum dma_data_direction direction, unsignedlong attrs)
{ struct ioc *ioc; int coalesced, filled = 0; unsignedlong flags; unsignedlong hint = hint_lookup[(int)direction]; unsignedlong prev_len = 0, current_len = 0; int i;
BUG_ON(!dev);
ioc = GET_IOC(dev); if (!ioc) return -EINVAL;
/* ** First coalesce the chunks and allocate I/O pdir space ** ** If this is one DMA stream, we can properly map using the ** correct virtual address associated with each DMA page. ** w/o this association, we wouldn't have coherent DMA! ** Access to the virtual address is what forces a two pass algorithm.
*/
coalesced = iommu_coalesce_chunks(ioc, dev, sglist, nents, ccio_alloc_range);
/* ** Program the I/O Pdir ** ** map the virtual addresses to the I/O Pdir ** o dma_address will contain the pdir index ** o dma_len will contain the number of bytes to map ** o page/offset contain the virtual address.
*/
filled = iommu_fill_pdir(ioc, sglist, nents, hint, ccio_io_pdir_entry);
for (i = 0; i < filled; i++)
current_len += sg_dma_len(sglist + i);
BUG_ON(current_len != prev_len);
return filled;
}
/** * ccio_unmap_sg - Unmap the scatter/gather list from the IOMMU. * @dev: The PCI device. * @sglist: The scatter/gather list to be unmapped from the IOMMU. * @nents: The number of entries in the scatter/gather list. * @direction: The direction of the DMA transaction (to/from device). * @attrs: attributes * * This function implements the pci_unmap_sg function.
*/ staticvoid
ccio_unmap_sg(struct device *dev, struct scatterlist *sglist, int nents, enum dma_data_direction direction, unsignedlong attrs)
{ struct ioc *ioc;
BUG_ON(!dev);
ioc = GET_IOC(dev); if (!ioc) {
WARN_ON(!ioc); return;
}
while (ioc != NULL) {
seq_hex_dump(m, " ", DUMP_PREFIX_NONE, 32, 4, ioc->res_map,
ioc->res_size, false);
seq_putc(m, '\n');
ioc = ioc->next; break; /* XXX - remove me */
}
return 0;
} #endif/* CONFIG_PROC_FS */
/** * ccio_find_ioc - Find the ioc in the ioc_list * @hw_path: The hardware path of the ioc. * * This function searches the ioc_list for an ioc that matches * the provide hardware path.
*/ staticstruct ioc * ccio_find_ioc(int hw_path)
{ int i; struct ioc *ioc;
ioc = ioc_list; for (i = 0; i < ioc_count; i++) { if (ioc->hw_path == hw_path) return ioc;
ioc = ioc->next;
}
return NULL;
}
/** * ccio_get_iommu - Find the iommu which controls this device * @dev: The parisc device. * * This function searches through the registered IOMMU's and returns * the appropriate IOMMU for the device based on its hardware path.
*/ void * ccio_get_iommu(conststruct parisc_device *dev)
{
dev = find_pa_parent_type(dev, HPHW_IOA); if (!dev) return NULL;
/* Cujo 2.0 has a bug which will silently corrupt data being transferred * to/from certain pages. To avoid this happening, we mark these pages * as `used', and ensure that nothing will try to allocate from them.
*/ void __init ccio_cujo20_fixup(struct parisc_device *cujo, u32 iovp)
{ unsignedint idx; struct parisc_device *dev = parisc_parent(cujo); struct ioc *ioc = ccio_get_iommu(dev);
u8 *res_ptr;
/* ** Get the size of the I/O TLB for this I/O MMU. ** ** If spa_shift is non-zero (ie probably U2), ** then calculate the I/O TLB size using spa_shift. ** ** Otherwise we are supposed to get the IODC entry point ENTRY TLB ** and execute it. However, both U2 and Uturn firmware supplies spa_shift. ** I think only Java (K/D/R-class too?) systems don't do this.
*/ staticint
ccio_get_iotlb_size(struct parisc_device *dev)
{ if (dev->spa_shift == 0) {
panic("%s() : Can't determine I/O TLB size.\n", __func__);
} return (1 << dev->spa_shift);
} #else
/** * ccio_ioc_init - Initialize the I/O Controller * @ioc: The I/O Controller. * * Initialize the I/O Controller which includes setting up the * I/O Page Directory, the resource map, and initalizing the * U2/Uturn chip into virtual mode.
*/ staticvoid __init
ccio_ioc_init(struct ioc *ioc)
{ int i; unsignedint iov_order;
u32 iova_space_size;
/* ** Determine IOVA Space size from memory size. ** ** Ideally, PCI drivers would register the maximum number ** of DMA they can have outstanding for each device they ** own. Next best thing would be to guess how much DMA ** can be outstanding based on PCI Class/sub-class. Both ** methods still require some "extra" to support PCI ** Hot-Plug/Removal of PCI cards. (aka PCI OLARD).
*/
/* ** iova space must be log2() in size. ** thus, pdir/res_map will also be log2().
*/
/* We could use larger page sizes in order to *decrease* the number ** of mappings needed. (ie 8k pages means 1/2 the mappings). ** ** Note: Grant Grunder says "Using 8k I/O pages isn't trivial either ** since the pages must also be physically contiguous - typically ** this is the case under linux."
*/
ioc->res_map = (u8 *)__get_free_pages(GFP_KERNEL,
get_order(ioc->res_size)); if(NULL == ioc->res_map) {
panic("%s() could not allocate resource map\n", __func__);
}
memset(ioc->res_map, 0, ioc->res_size);
/* Initialize the res_hint to 16 */
ioc->res_hint = 16;
/* Initialize the spinlock */
spin_lock_init(&ioc->res_lock);
/* ** Chainid is the upper most bits of an IOVP used to determine ** which TLB entry an IOVP will use.
*/
ioc->chainid_shift = get_order(iova_space_size) + PAGE_SHIFT - CCIO_CHAINID_SHIFT;
DBG_INIT(" chainid_shift 0x%x\n", ioc->chainid_shift);
res->parent = NULL;
res->flags = IORESOURCE_MEM; /* * bracing ((signed) ...) are required for 64bit kernel because * we only want to sign extend the lower 16 bits of the register. * The upper 16-bits of range registers are hardcoded to 0xffff.
*/
res->start = (unsignedlong)((signed) READ_U32(ioaddr) << 16);
res->end = (unsignedlong)((signed) (READ_U32(ioaddr + 4) << 16) - 1);
res->name = name; /* * Check if this MMIO range is disable
*/ if (res->end + 1 == res->start) return;
/* On some platforms (e.g. K-Class), we have already registered * resources for devices reported by firmware. Some are children * of ccio. * "insert" ccio ranges in the mmio hierarchy (/proc/iomem).
*/
result = insert_resource(&iomem_resource, res); if (result < 0) {
printk(KERN_ERR "%s() failed to claim CCIO bus address space (%08lx,%08lx)\n",
__func__, (unsignedlong)res->start, (unsignedlong)res->end);
}
}
staticint __init ccio_init_resources(struct ioc *ioc)
{ struct resource *res = ioc->mmio_region; char *name = kmalloc(14, GFP_KERNEL); if (unlikely(!name)) return -ENOMEM;
snprintf(name, 14, "GSC Bus [%d/]", ioc->hw_path);
/* We might be trying to expand the MMIO range to include * a child device that has already registered it's MMIO space. * Use "insert" instead of request_resource().
*/ if (!insert_resource(&iomem_resource, res)) return 0;
return new_ioc_area(res, size, min, max - size, align);
}
if (!res->parent) return new_ioc_area(res, size, min, max, align);
start = (res->start - size) &~ (align - 1);
len = res->end - start + 1; if (start >= min) { if (!adjust_resource(res, start, len)) return 0;
}
start = res->start;
len = ((size + res->end + align) &~ (align - 1)) - start; if (start + len <= max) { if (!adjust_resource(res, start, len)) return 0;
}
return -EBUSY;
}
/* * Dino calls this function. Beware that we may get called on systems * which have no IOC (725, B180, C160L, etc) but do have a Dino. * So it's legal to find no parent IOC. * * Some other issues: one of the resources in the ioc may be unassigned.
*/ int ccio_allocate_resource(conststruct parisc_device *dev, struct resource *res, unsignedlong size, unsignedlong min, unsignedlong max, unsignedlong align)
{ struct resource *parent = &iomem_resource; struct ioc *ioc = ccio_get_iommu(dev); if (!ioc) goto out;
/* "transparent" bus bridges need to register MMIO resources * firmware assigned them. e.g. children of hppb.c (e.g. K-class) * registered their resources in the PDC "bus walk" (See * arch/parisc/kernel/inventory.c).
*/ return insert_resource(parent, res);
}
/** * ccio_probe - Determine if ccio should claim this device. * @dev: The device which has been found * * Determine if ccio should claim this chip (return 0) or not (return 1). * If so, initialize the chip and tell other partners in crime they * have work to do.
*/ staticint __init ccio_probe(struct parisc_device *dev)
{ int i; struct ioc *ioc, **ioc_p = &ioc_list; struct pci_hba_data *hba;
ioc = kzalloc(sizeof(struct ioc), GFP_KERNEL); if (ioc == NULL) {
printk(KERN_ERR MODULE_NAME ": memory allocation failure\n"); return -ENOMEM;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.