X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/5d5c5d0d5b79ade9a973d55186ffda2638ba2b6e..04b8595b18b1b41ac7a206e4b3d51a635f8413d7:/iokit/Kernel/IOMapper.cpp diff --git a/iokit/Kernel/IOMapper.cpp b/iokit/Kernel/IOMapper.cpp index c2691aea7..294e13822 100644 --- a/iokit/Kernel/IOMapper.cpp +++ b/iokit/Kernel/IOMapper.cpp @@ -1,37 +1,35 @@ /* * Copyright (c) 1998-2004 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ + * @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. 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 - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and + * 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. 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 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and * limitations under the License. - * - * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #include #include +#include #include - -#include "IOCopyMapper.h" +#include __BEGIN_DECLS extern ppnum_t pmap_find_phys(pmap_t pmap, addr64_t va); @@ -41,9 +39,9 @@ __END_DECLS OSDefineMetaClassAndAbstractStructors(IOMapper, IOService); OSMetaClassDefineReservedUsed(IOMapper, 0); -OSMetaClassDefineReservedUnused(IOMapper, 1); -OSMetaClassDefineReservedUnused(IOMapper, 2); -OSMetaClassDefineReservedUnused(IOMapper, 3); +OSMetaClassDefineReservedUsed(IOMapper, 1); +OSMetaClassDefineReservedUsed(IOMapper, 2); +OSMetaClassDefineReservedUsed(IOMapper, 3); OSMetaClassDefineReservedUnused(IOMapper, 4); OSMetaClassDefineReservedUnused(IOMapper, 5); OSMetaClassDefineReservedUnused(IOMapper, 6); @@ -75,6 +73,7 @@ static IOMapperLock sMapperLock; bool IOMapper::start(IOService *provider) { + OSObject * obj; if (!super::start(provider)) return false; @@ -88,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; } @@ -125,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) { @@ -153,8 +230,8 @@ NewARTTable(IOByteCount size, void ** virtAddrP, ppnum_t *physAddrP) kern_return_t kr; vm_address_t address; - size = round_page_32(size); - kr = kmem_alloc_contig(kernel_map, &address, 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; @@ -175,7 +252,7 @@ void IOMapper::FreeARTTable(OSData *artHandle, IOByteCount size) { vm_address_t address = (vm_address_t) artHandle; - size = round_page_32(size); + size = round_page(size); kmem_free(kernel_map, address, size); // Just panic if address is 0 } @@ -206,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; } @@ -345,24 +423,4 @@ void IOMappedWrite64(IOPhysicalAddress address, UInt64 value) ml_phys_write_double((vm_offset_t) address, value); } -mach_vm_address_t IOMallocPhysical(mach_vm_size_t size, mach_vm_address_t mask) -{ - mach_vm_address_t address = 0; - if (gIOCopyMapper) - { - address = ptoa_64(gIOCopyMapper->iovmAlloc(atop_64(round_page(size)))); - } - - return (address); -} - -void IOFreePhysical(mach_vm_address_t address, mach_vm_size_t size) -{ - if (gIOCopyMapper) - { - gIOCopyMapper->iovmFree(atop_64(address), atop_64(round_page(size))); - } -} - - __END_DECLS