X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/55e303ae13a4cf49d70f2294092726f2fffb9ef2..39236c6e673c41db228275375ab7fdb0f837b292:/iokit/Kernel/IOMapper.cpp diff --git a/iokit/Kernel/IOMapper.cpp b/iokit/Kernel/IOMapper.cpp index c1795da6c..294e13822 100644 --- a/iokit/Kernel/IOMapper.cpp +++ b/iokit/Kernel/IOMapper.cpp @@ -1,16 +1,19 @@ /* - * Copyright (c) 1998-2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1998-2004 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -20,19 +23,25 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #include #include +#include #include +#include + +__BEGIN_DECLS +extern ppnum_t pmap_find_phys(pmap_t pmap, addr64_t va); +__END_DECLS #define super IOService OSDefineMetaClassAndAbstractStructors(IOMapper, IOService); -OSMetaClassDefineReservedUnused(IOMapper, 0); -OSMetaClassDefineReservedUnused(IOMapper, 1); -OSMetaClassDefineReservedUnused(IOMapper, 2); -OSMetaClassDefineReservedUnused(IOMapper, 3); +OSMetaClassDefineReservedUsed(IOMapper, 0); +OSMetaClassDefineReservedUsed(IOMapper, 1); +OSMetaClassDefineReservedUsed(IOMapper, 2); +OSMetaClassDefineReservedUsed(IOMapper, 3); OSMetaClassDefineReservedUnused(IOMapper, 4); OSMetaClassDefineReservedUnused(IOMapper, 5); OSMetaClassDefineReservedUnused(IOMapper, 6); @@ -64,6 +73,7 @@ static IOMapperLock sMapperLock; bool IOMapper::start(IOService *provider) { + OSObject * obj; if (!super::start(provider)) return false; @@ -77,6 +87,14 @@ bool IOMapper::start(IOService *provider) sMapperLock.unlock(); } + if (provider) + { + obj = provider->getProperty("iommu-id"); + if (!obj) + obj = provider->getProperty("AAPL,phandle"); + if (obj) + setProperty(gIOMapperIDKey, obj); + } return true; } @@ -114,11 +132,81 @@ void IOMapper::setMapperRequired(bool hasMapper) void IOMapper::waitForSystemMapper() { sMapperLock.lock(); - while ((vm_address_t) IOMapper::gSystem & kWaitMask) + while ((uintptr_t) IOMapper::gSystem & kWaitMask) + { + OSReportWithBacktrace("waitForSystemMapper"); sMapperLock.sleep(&IOMapper::gSystem); + } sMapperLock.unlock(); } +IOMapper * IOMapper::copyMapperForDevice(IOService * device) +{ + return copyMapperForDeviceWithIndex(device, 0); +} + +IOMapper * IOMapper::copyMapperForDeviceWithIndex(IOService * device, unsigned int index) +{ + OSData *data; + OSObject * obj; + IOMapper * mapper = NULL; + OSDictionary * matching; + + obj = device->copyProperty("iommu-parent"); + if (!obj) + return (NULL); + + if ((mapper = OSDynamicCast(IOMapper, obj))) + return (mapper); + + if ((data = OSDynamicCast(OSData, obj))) + { + if (index >= data->getLength() / sizeof(UInt32)) + goto done; + + data = OSData::withBytesNoCopy((UInt32 *)data->getBytesNoCopy() + index, sizeof(UInt32)); + if (!data) + goto done; + + matching = IOService::propertyMatching(gIOMapperIDKey, data); + data->release(); + } + else + matching = IOService::propertyMatching(gIOMapperIDKey, obj); + + if (matching) + { + mapper = OSDynamicCast(IOMapper, IOService::waitForMatchingService(matching)); + matching->release(); + } + +done: + if (obj) + obj->release(); + return (mapper); +} + +ppnum_t IOMapper::iovmAllocDMACommand(IODMACommand * command, IOItemCount pageCount) +{ + return (0); +} + +void IOMapper::iovmFreeDMACommand(IODMACommand * command, + ppnum_t addr, IOItemCount pageCount) +{ +} + +ppnum_t IOMapper::iovmMapMemory( + OSObject * memory, // dma command or iomd + ppnum_t offsetPage, + ppnum_t pageCount, + uint32_t options, + upl_page_info_t * pageList, + const IODMAMapSpecification * mapSpecification) +{ + return (0); +} + void IOMapper::iovmInsert(ppnum_t addr, IOItemCount offset, ppnum_t *pageList, IOItemCount pageCount) { @@ -133,96 +221,44 @@ void IOMapper::iovmInsert(ppnum_t addr, IOItemCount offset, iovmInsert(addr, offset + i, pageList[i].phys_addr); } -struct ARTTableData { - void *v; - upl_t u[0]; -}; -#define getARTDataP(data) ((ARTTableData *) (data)->getBytesNoCopy()) - -OSData * -IOMapper::NewARTTable(IOByteCount size, - void ** virtAddrP, ppnum_t *physAddrP) +OSData * IOMapper:: +NewARTTable(IOByteCount size, void ** virtAddrP, ppnum_t *physAddrP) { - OSData *ret; - kern_return_t kr; - vm_address_t startUpl; - ARTTableData *dataP; - unsigned int dataSize; - upl_page_info_t *pl = 0; - - // Each UPL can deal with about one meg at the moment - size = round_page_32(size); - dataSize = sizeof(ARTTableData) + sizeof(upl_t) * size / (1024 * 1024); - ret = OSData::withCapacity(dataSize); - if (!ret) - return 0; + if (!virtAddrP || !physAddrP) + return 0; - // Append 0's to the buffer, in-other-words reset to nulls. - ret->appendBytes(NULL, sizeof(ARTTableData)); - dataP = getARTDataP(ret); + kern_return_t kr; + vm_address_t address; - kr = kmem_alloc_contig(kernel_map, &startUpl, size, PAGE_MASK, 0); + size = round_page(size); + kr = kmem_alloc_contig(kernel_map, &address, size, PAGE_MASK, 0 /*max_pnum*/, 0 /*pnum_mask*/, false); if (kr) return 0; - dataP->v = (void *) startUpl; - - do { - upl_t iopl; - int upl_flags = UPL_SET_INTERNAL | UPL_SET_LITE - | UPL_SET_IO_WIRE | UPL_COPYOUT_FROM; - vm_size_t iopl_size = size; - - kr = vm_map_get_upl(kernel_map, - startUpl, - &iopl_size, - &iopl, - 0, - 0, - &upl_flags, - 0); - if (kr) { - panic("IOMapper:vm_map_get_upl returned 0x%x\n"); - goto bail; - } - - if (!ret->appendBytes(&iopl, sizeof(upl_t))) - goto bail; - - startUpl += iopl_size; - size -= iopl_size; - } while(size); - - // Need to re-establish the dataP as the OSData may have grown. - dataP = getARTDataP(ret); - - // Now grab the page entry of the first page and get its phys addr - pl = UPL_GET_INTERNAL_PAGE_LIST(dataP->u[0]); - *physAddrP = pl->phys_addr; - *virtAddrP = dataP->v; - - return ret; - -bail: - FreeARTTable(ret, size); - return 0; + ppnum_t pagenum = pmap_find_phys(kernel_pmap, (addr64_t) address); + if (pagenum) + *physAddrP = pagenum; + else { + FreeARTTable((OSData *) address, size); + address = 0; + } + + *virtAddrP = (void *) address; + + return (OSData *) address; } void IOMapper::FreeARTTable(OSData *artHandle, IOByteCount size) { - assert(artHandle); - - ARTTableData *dataP = getARTDataP(artHandle); + vm_address_t address = (vm_address_t) artHandle; - int numupls = ((artHandle->getLength() - sizeof(*dataP)) / sizeof(upl_t)); - for (int i = 0; i < numupls; i++) - kernel_upl_abort(dataP->u[i], 0); + size = round_page(size); + kmem_free(kernel_map, address, size); // Just panic if address is 0 +} - if (dataP->v) { - size = round_page_32(size); - kmem_free(kernel_map, (vm_address_t) dataP->v, size); - } - artHandle->release(); +bool IOMapper::getBypassMask(addr64_t *maskP) const +{ + return false; } __BEGIN_DECLS @@ -247,6 +283,7 @@ void IOMapperIOVMFree(ppnum_t addr, unsigned pages) ppnum_t IOMapperInsertPage(ppnum_t addr, unsigned offset, ppnum_t page) { if (IOMapper::gSystem) { + if (!addr) panic("!addr"); IOMapper::gSystem->iovmInsert(addr, (IOItemCount) offset, page); return addr + offset; }