xref: /xnu-10002.1.13/iokit/Kernel/IOMapper.cpp (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a) !
1*1031c584SApple OSS Distributions /*
2*1031c584SApple OSS Distributions  * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
3*1031c584SApple OSS Distributions  *
4*1031c584SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*1031c584SApple OSS Distributions  *
6*1031c584SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*1031c584SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*1031c584SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*1031c584SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*1031c584SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*1031c584SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*1031c584SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*1031c584SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*1031c584SApple OSS Distributions  *
15*1031c584SApple OSS Distributions  * Please obtain a copy of the License at
16*1031c584SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*1031c584SApple OSS Distributions  *
18*1031c584SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*1031c584SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*1031c584SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*1031c584SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*1031c584SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*1031c584SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*1031c584SApple OSS Distributions  * limitations under the License.
25*1031c584SApple OSS Distributions  *
26*1031c584SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*1031c584SApple OSS Distributions  */
28*1031c584SApple OSS Distributions 
29*1031c584SApple OSS Distributions #define IOKIT_ENABLE_SHARED_PTR
30*1031c584SApple OSS Distributions 
31*1031c584SApple OSS Distributions #include <IOKit/IOLib.h>
32*1031c584SApple OSS Distributions #include <IOKit/IOMapper.h>
33*1031c584SApple OSS Distributions #include <IOKit/IODMACommand.h>
34*1031c584SApple OSS Distributions #include <libkern/c++/OSData.h>
35*1031c584SApple OSS Distributions #include <libkern/OSDebug.h>
36*1031c584SApple OSS Distributions #include <mach_debug/zone_info.h>
37*1031c584SApple OSS Distributions #include "IOKitKernelInternal.h"
38*1031c584SApple OSS Distributions 
39*1031c584SApple OSS Distributions __BEGIN_DECLS
40*1031c584SApple OSS Distributions extern ppnum_t pmap_find_phys(pmap_t pmap, addr64_t va);
41*1031c584SApple OSS Distributions __END_DECLS
42*1031c584SApple OSS Distributions 
43*1031c584SApple OSS Distributions #define super IOService
44*1031c584SApple OSS Distributions OSDefineMetaClassAndAbstractStructors(IOMapper, IOService);
45*1031c584SApple OSS Distributions 
46*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 0);
47*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 1);
48*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 2);
49*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 3);
50*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 4);
51*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 5);
52*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 6);
53*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 7);
54*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 8);
55*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 9);
56*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 10);
57*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 11);
58*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 12);
59*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 13);
60*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 14);
61*1031c584SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 15);
62*1031c584SApple OSS Distributions 
63*1031c584SApple OSS Distributions IOMapper * IOMapper::gSystem = (IOMapper *) IOMapper::kUnknown;
64*1031c584SApple OSS Distributions 
65*1031c584SApple OSS Distributions class IOMapperLock {
66*1031c584SApple OSS Distributions 	IOLock *fWaitLock;
67*1031c584SApple OSS Distributions public:
IOMapperLock()68*1031c584SApple OSS Distributions 	IOMapperLock()
69*1031c584SApple OSS Distributions 	{
70*1031c584SApple OSS Distributions 		fWaitLock = IOLockAlloc();
71*1031c584SApple OSS Distributions 	}
~IOMapperLock()72*1031c584SApple OSS Distributions 	~IOMapperLock()
73*1031c584SApple OSS Distributions 	{
74*1031c584SApple OSS Distributions 		IOLockFree(fWaitLock);
75*1031c584SApple OSS Distributions 	}
76*1031c584SApple OSS Distributions 
77*1031c584SApple OSS Distributions 	void
lock()78*1031c584SApple OSS Distributions 	lock()
79*1031c584SApple OSS Distributions 	{
80*1031c584SApple OSS Distributions 		IOLockLock(fWaitLock);
81*1031c584SApple OSS Distributions 	}
82*1031c584SApple OSS Distributions 	void
unlock()83*1031c584SApple OSS Distributions 	unlock()
84*1031c584SApple OSS Distributions 	{
85*1031c584SApple OSS Distributions 		IOLockUnlock(fWaitLock);
86*1031c584SApple OSS Distributions 	}
87*1031c584SApple OSS Distributions 	void
sleep(void * event)88*1031c584SApple OSS Distributions 	sleep(void *event)
89*1031c584SApple OSS Distributions 	{
90*1031c584SApple OSS Distributions 		IOLockSleep(fWaitLock, event, THREAD_UNINT);
91*1031c584SApple OSS Distributions 	}
92*1031c584SApple OSS Distributions 	void
wakeup(void * event)93*1031c584SApple OSS Distributions 	wakeup(void *event)
94*1031c584SApple OSS Distributions 	{
95*1031c584SApple OSS Distributions 		IOLockWakeup(fWaitLock, event, false);
96*1031c584SApple OSS Distributions 	}
97*1031c584SApple OSS Distributions };
98*1031c584SApple OSS Distributions 
99*1031c584SApple OSS Distributions static IOMapperLock sMapperLock;
100*1031c584SApple OSS Distributions 
101*1031c584SApple OSS Distributions bool
start(IOService * provider)102*1031c584SApple OSS Distributions IOMapper::start(IOService *provider)
103*1031c584SApple OSS Distributions {
104*1031c584SApple OSS Distributions 	OSSharedPtr<OSObject> obj;
105*1031c584SApple OSS Distributions 	if (!super::start(provider)) {
106*1031c584SApple OSS Distributions 		return false;
107*1031c584SApple OSS Distributions 	}
108*1031c584SApple OSS Distributions 
109*1031c584SApple OSS Distributions 	if (!initHardware(provider)) {
110*1031c584SApple OSS Distributions 		return false;
111*1031c584SApple OSS Distributions 	}
112*1031c584SApple OSS Distributions 
113*1031c584SApple OSS Distributions 	uint64_t pageSize = getPageSize();
114*1031c584SApple OSS Distributions 	assert(pageSize <= UINT_MAX);
115*1031c584SApple OSS Distributions 	fPageSize = (uint32_t) pageSize;
116*1031c584SApple OSS Distributions 
117*1031c584SApple OSS Distributions 	if (fIsSystem) {
118*1031c584SApple OSS Distributions 		sMapperLock.lock();
119*1031c584SApple OSS Distributions 		IOMapper::gSystem = this;
120*1031c584SApple OSS Distributions 		sMapperLock.wakeup(&IOMapper::gSystem);
121*1031c584SApple OSS Distributions 		sMapperLock.unlock();
122*1031c584SApple OSS Distributions 	}
123*1031c584SApple OSS Distributions 
124*1031c584SApple OSS Distributions 	if (provider) {
125*1031c584SApple OSS Distributions 		obj = provider->copyProperty("iommu-id");
126*1031c584SApple OSS Distributions 		if (!obj) {
127*1031c584SApple OSS Distributions 			obj = provider->copyProperty("AAPL,phandle");
128*1031c584SApple OSS Distributions 		}
129*1031c584SApple OSS Distributions 		if (obj) {
130*1031c584SApple OSS Distributions 			setProperty(gIOMapperIDKey, obj.get());
131*1031c584SApple OSS Distributions 		}
132*1031c584SApple OSS Distributions 	}
133*1031c584SApple OSS Distributions 	return true;
134*1031c584SApple OSS Distributions }
135*1031c584SApple OSS Distributions 
136*1031c584SApple OSS Distributions void
free()137*1031c584SApple OSS Distributions IOMapper::free()
138*1031c584SApple OSS Distributions {
139*1031c584SApple OSS Distributions 	super::free();
140*1031c584SApple OSS Distributions }
141*1031c584SApple OSS Distributions 
142*1031c584SApple OSS Distributions void
setMapperRequired(bool hasMapper)143*1031c584SApple OSS Distributions IOMapper::setMapperRequired(bool hasMapper)
144*1031c584SApple OSS Distributions {
145*1031c584SApple OSS Distributions 	if (hasMapper) {
146*1031c584SApple OSS Distributions 		IOMapper::gSystem = (IOMapper *) kHasMapper;
147*1031c584SApple OSS Distributions 	} else {
148*1031c584SApple OSS Distributions 		sMapperLock.lock();
149*1031c584SApple OSS Distributions 		IOMapper::gSystem = (IOMapper *) kNoMapper;
150*1031c584SApple OSS Distributions 		sMapperLock.unlock();
151*1031c584SApple OSS Distributions 		sMapperLock.wakeup(&IOMapper::gSystem);
152*1031c584SApple OSS Distributions 	}
153*1031c584SApple OSS Distributions }
154*1031c584SApple OSS Distributions 
155*1031c584SApple OSS Distributions void
waitForSystemMapper()156*1031c584SApple OSS Distributions IOMapper::waitForSystemMapper()
157*1031c584SApple OSS Distributions {
158*1031c584SApple OSS Distributions 	sMapperLock.lock();
159*1031c584SApple OSS Distributions 	while ((uintptr_t) IOMapper::gSystem & kWaitMask) {
160*1031c584SApple OSS Distributions 		OSReportWithBacktrace("waitForSystemMapper");
161*1031c584SApple OSS Distributions 		sMapperLock.sleep(&IOMapper::gSystem);
162*1031c584SApple OSS Distributions 	}
163*1031c584SApple OSS Distributions 	sMapperLock.unlock();
164*1031c584SApple OSS Distributions }
165*1031c584SApple OSS Distributions 
166*1031c584SApple OSS Distributions OSSharedPtr<IOMapper>
copyMapperForDevice(IOService * device)167*1031c584SApple OSS Distributions IOMapper::copyMapperForDevice(IOService * device)
168*1031c584SApple OSS Distributions {
169*1031c584SApple OSS Distributions 	return copyMapperForDeviceWithIndex(device, 0);
170*1031c584SApple OSS Distributions }
171*1031c584SApple OSS Distributions 
172*1031c584SApple OSS Distributions OSSharedPtr<IOMapper>
copyMapperForDeviceWithIndex(IOService * device,unsigned int index)173*1031c584SApple OSS Distributions IOMapper::copyMapperForDeviceWithIndex(IOService * device, unsigned int index)
174*1031c584SApple OSS Distributions {
175*1031c584SApple OSS Distributions 	OSSharedPtr<OSData> data;
176*1031c584SApple OSS Distributions 	OSSharedPtr<OSObject> obj;
177*1031c584SApple OSS Distributions 	OSSharedPtr<IOMapper> mapper;
178*1031c584SApple OSS Distributions 	OSSharedPtr<OSDictionary> matching;
179*1031c584SApple OSS Distributions 
180*1031c584SApple OSS Distributions 	obj = device->copyProperty("iommu-parent");
181*1031c584SApple OSS Distributions 	if (!obj) {
182*1031c584SApple OSS Distributions 		return NULL;
183*1031c584SApple OSS Distributions 	}
184*1031c584SApple OSS Distributions 
185*1031c584SApple OSS Distributions 	if ((mapper = OSDynamicPtrCast<IOMapper>(obj))) {
186*1031c584SApple OSS Distributions 		goto found;
187*1031c584SApple OSS Distributions 	}
188*1031c584SApple OSS Distributions 
189*1031c584SApple OSS Distributions 	if ((data = OSDynamicPtrCast<OSData>(obj))) {
190*1031c584SApple OSS Distributions 		if (index >= data->getLength() / sizeof(UInt32)) {
191*1031c584SApple OSS Distributions 			goto found;
192*1031c584SApple OSS Distributions 		}
193*1031c584SApple OSS Distributions 
194*1031c584SApple OSS Distributions 		data = OSData::withValueNoCopy(*((UInt32 *)data->getBytesNoCopy() + index));
195*1031c584SApple OSS Distributions 		if (!data) {
196*1031c584SApple OSS Distributions 			goto found;
197*1031c584SApple OSS Distributions 		}
198*1031c584SApple OSS Distributions 
199*1031c584SApple OSS Distributions 		matching = IOService::propertyMatching(gIOMapperIDKey, data.get());
200*1031c584SApple OSS Distributions 	} else {
201*1031c584SApple OSS Distributions 		matching = IOService::propertyMatching(gIOMapperIDKey, obj.get());
202*1031c584SApple OSS Distributions 	}
203*1031c584SApple OSS Distributions 
204*1031c584SApple OSS Distributions 	if (matching) {
205*1031c584SApple OSS Distributions 		mapper = OSDynamicPtrCast<IOMapper>(IOService::waitForMatchingService(matching.get()));
206*1031c584SApple OSS Distributions 	}
207*1031c584SApple OSS Distributions 
208*1031c584SApple OSS Distributions found:
209*1031c584SApple OSS Distributions 	if (mapper) {
210*1031c584SApple OSS Distributions 		if (!mapper->fAllocName) {
211*1031c584SApple OSS Distributions 			char name[MACH_ZONE_NAME_MAX_LEN];
212*1031c584SApple OSS Distributions 			char kmodname[KMOD_MAX_NAME];
213*1031c584SApple OSS Distributions 			vm_tag_t tag;
214*1031c584SApple OSS Distributions 			uint32_t kmodid;
215*1031c584SApple OSS Distributions 
216*1031c584SApple OSS Distributions 			tag = IOMemoryTag(kernel_map);
217*1031c584SApple OSS Distributions 			if (!(kmodid = vm_tag_get_kext(tag, &kmodname[0], KMOD_MAX_NAME))) {
218*1031c584SApple OSS Distributions 				snprintf(kmodname, sizeof(kmodname), "%d", tag);
219*1031c584SApple OSS Distributions 			}
220*1031c584SApple OSS Distributions 			snprintf(name, sizeof(name), "%s.DMA.%s", kmodname, device->getName());
221*1031c584SApple OSS Distributions 			mapper->fAllocName = kern_allocation_name_allocate(name, 16);
222*1031c584SApple OSS Distributions 		}
223*1031c584SApple OSS Distributions 	}
224*1031c584SApple OSS Distributions 
225*1031c584SApple OSS Distributions 	return mapper;
226*1031c584SApple OSS Distributions }
227*1031c584SApple OSS Distributions 
228*1031c584SApple OSS Distributions __BEGIN_DECLS
229*1031c584SApple OSS Distributions 
230*1031c584SApple OSS Distributions // These are C accessors to the system mapper for non-IOKit clients
231*1031c584SApple OSS Distributions ppnum_t
IOMapperIOVMAlloc(unsigned pages)232*1031c584SApple OSS Distributions IOMapperIOVMAlloc(unsigned pages)
233*1031c584SApple OSS Distributions {
234*1031c584SApple OSS Distributions 	IOReturn ret;
235*1031c584SApple OSS Distributions 	uint64_t dmaAddress, dmaLength;
236*1031c584SApple OSS Distributions 
237*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
238*1031c584SApple OSS Distributions 
239*1031c584SApple OSS Distributions 	ret = kIOReturnUnsupported;
240*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
241*1031c584SApple OSS Distributions 		ret = IOMapper::gSystem->iovmMapMemory(
242*1031c584SApple OSS Distributions 			NULL, 0, ptoa_64(pages),
243*1031c584SApple OSS Distributions 			(kIODMAMapReadAccess | kIODMAMapWriteAccess),
244*1031c584SApple OSS Distributions 			NULL, NULL, NULL,
245*1031c584SApple OSS Distributions 			&dmaAddress, &dmaLength);
246*1031c584SApple OSS Distributions 	}
247*1031c584SApple OSS Distributions 
248*1031c584SApple OSS Distributions 	if (kIOReturnSuccess == ret) {
249*1031c584SApple OSS Distributions 		uint64_t dmaAddressPage64;
250*1031c584SApple OSS Distributions 		dmaAddressPage64 = atop_64(dmaAddress);
251*1031c584SApple OSS Distributions 		if (dmaAddressPage64 > UINT_MAX) {
252*1031c584SApple OSS Distributions 			return 0;
253*1031c584SApple OSS Distributions 		}
254*1031c584SApple OSS Distributions 		return (ppnum_t) atop_64(dmaAddress);
255*1031c584SApple OSS Distributions 	}
256*1031c584SApple OSS Distributions 	return 0;
257*1031c584SApple OSS Distributions }
258*1031c584SApple OSS Distributions 
259*1031c584SApple OSS Distributions void
IOMapperIOVMFree(ppnum_t addr,unsigned pages)260*1031c584SApple OSS Distributions IOMapperIOVMFree(ppnum_t addr, unsigned pages)
261*1031c584SApple OSS Distributions {
262*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
263*1031c584SApple OSS Distributions 		IOMapper::gSystem->iovmUnmapMemory(NULL, NULL, ptoa_64(addr), ptoa_64(pages));
264*1031c584SApple OSS Distributions 	}
265*1031c584SApple OSS Distributions }
266*1031c584SApple OSS Distributions 
267*1031c584SApple OSS Distributions ppnum_t
IOMapperInsertPage(ppnum_t addr,unsigned offset,ppnum_t page)268*1031c584SApple OSS Distributions IOMapperInsertPage(ppnum_t addr, unsigned offset, ppnum_t page)
269*1031c584SApple OSS Distributions {
270*1031c584SApple OSS Distributions 	if (!IOMapper::gSystem) {
271*1031c584SApple OSS Distributions 		return page;
272*1031c584SApple OSS Distributions 	}
273*1031c584SApple OSS Distributions 	if (!addr) {
274*1031c584SApple OSS Distributions 		panic("!addr");
275*1031c584SApple OSS Distributions 	}
276*1031c584SApple OSS Distributions 	IOMapper::gSystem->iovmInsert((kIODMAMapReadAccess | kIODMAMapWriteAccess),
277*1031c584SApple OSS Distributions 	    ptoa_64(addr), ptoa_64(offset), ptoa_64(page), ptoa_64(1));
278*1031c584SApple OSS Distributions 	return addr + offset;
279*1031c584SApple OSS Distributions }
280*1031c584SApple OSS Distributions 
281*1031c584SApple OSS Distributions /////////////////////////////////////////////////////////////////////////////
282*1031c584SApple OSS Distributions //
283*1031c584SApple OSS Distributions //
284*1031c584SApple OSS Distributions //	IOLib.h APIs
285*1031c584SApple OSS Distributions //
286*1031c584SApple OSS Distributions //
287*1031c584SApple OSS Distributions /////////////////////////////////////////////////////////////////////////////
288*1031c584SApple OSS Distributions 
289*1031c584SApple OSS Distributions #include <machine/machine_routines.h>
290*1031c584SApple OSS Distributions 
291*1031c584SApple OSS Distributions UInt8
IOMappedRead8(IOPhysicalAddress address)292*1031c584SApple OSS Distributions IOMappedRead8(IOPhysicalAddress address)
293*1031c584SApple OSS Distributions {
294*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
295*1031c584SApple OSS Distributions 
296*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
297*1031c584SApple OSS Distributions 		addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
298*1031c584SApple OSS Distributions 		return (UInt8) ml_phys_read_byte_64(addr);
299*1031c584SApple OSS Distributions 	} else {
300*1031c584SApple OSS Distributions 		return (UInt8) ml_phys_read_byte((vm_offset_t) address);
301*1031c584SApple OSS Distributions 	}
302*1031c584SApple OSS Distributions }
303*1031c584SApple OSS Distributions 
304*1031c584SApple OSS Distributions UInt16
IOMappedRead16(IOPhysicalAddress address)305*1031c584SApple OSS Distributions IOMappedRead16(IOPhysicalAddress address)
306*1031c584SApple OSS Distributions {
307*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
308*1031c584SApple OSS Distributions 
309*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
310*1031c584SApple OSS Distributions 		addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
311*1031c584SApple OSS Distributions 		return (UInt16) ml_phys_read_half_64(addr);
312*1031c584SApple OSS Distributions 	} else {
313*1031c584SApple OSS Distributions 		return (UInt16) ml_phys_read_half((vm_offset_t) address);
314*1031c584SApple OSS Distributions 	}
315*1031c584SApple OSS Distributions }
316*1031c584SApple OSS Distributions 
317*1031c584SApple OSS Distributions UInt32
IOMappedRead32(IOPhysicalAddress address)318*1031c584SApple OSS Distributions IOMappedRead32(IOPhysicalAddress address)
319*1031c584SApple OSS Distributions {
320*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
321*1031c584SApple OSS Distributions 
322*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
323*1031c584SApple OSS Distributions 		addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
324*1031c584SApple OSS Distributions 		return (UInt32) ml_phys_read_word_64(addr);
325*1031c584SApple OSS Distributions 	} else {
326*1031c584SApple OSS Distributions 		return (UInt32) ml_phys_read_word((vm_offset_t) address);
327*1031c584SApple OSS Distributions 	}
328*1031c584SApple OSS Distributions }
329*1031c584SApple OSS Distributions 
330*1031c584SApple OSS Distributions UInt64
IOMappedRead64(IOPhysicalAddress address)331*1031c584SApple OSS Distributions IOMappedRead64(IOPhysicalAddress address)
332*1031c584SApple OSS Distributions {
333*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
334*1031c584SApple OSS Distributions 
335*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
336*1031c584SApple OSS Distributions 		addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
337*1031c584SApple OSS Distributions 		return (UInt64) ml_phys_read_double_64(addr);
338*1031c584SApple OSS Distributions 	} else {
339*1031c584SApple OSS Distributions 		return (UInt64) ml_phys_read_double((vm_offset_t) address);
340*1031c584SApple OSS Distributions 	}
341*1031c584SApple OSS Distributions }
342*1031c584SApple OSS Distributions 
343*1031c584SApple OSS Distributions void
IOMappedWrite8(IOPhysicalAddress address,UInt8 value)344*1031c584SApple OSS Distributions IOMappedWrite8(IOPhysicalAddress address, UInt8 value)
345*1031c584SApple OSS Distributions {
346*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
347*1031c584SApple OSS Distributions 
348*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
349*1031c584SApple OSS Distributions 		addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
350*1031c584SApple OSS Distributions 		ml_phys_write_byte_64(addr, value);
351*1031c584SApple OSS Distributions 	} else {
352*1031c584SApple OSS Distributions 		ml_phys_write_byte((vm_offset_t) address, value);
353*1031c584SApple OSS Distributions 	}
354*1031c584SApple OSS Distributions }
355*1031c584SApple OSS Distributions 
356*1031c584SApple OSS Distributions void
IOMappedWrite16(IOPhysicalAddress address,UInt16 value)357*1031c584SApple OSS Distributions IOMappedWrite16(IOPhysicalAddress address, UInt16 value)
358*1031c584SApple OSS Distributions {
359*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
360*1031c584SApple OSS Distributions 
361*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
362*1031c584SApple OSS Distributions 		addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
363*1031c584SApple OSS Distributions 		ml_phys_write_half_64(addr, value);
364*1031c584SApple OSS Distributions 	} else {
365*1031c584SApple OSS Distributions 		ml_phys_write_half((vm_offset_t) address, value);
366*1031c584SApple OSS Distributions 	}
367*1031c584SApple OSS Distributions }
368*1031c584SApple OSS Distributions 
369*1031c584SApple OSS Distributions void
IOMappedWrite32(IOPhysicalAddress address,UInt32 value)370*1031c584SApple OSS Distributions IOMappedWrite32(IOPhysicalAddress address, UInt32 value)
371*1031c584SApple OSS Distributions {
372*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
373*1031c584SApple OSS Distributions 
374*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
375*1031c584SApple OSS Distributions 		addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
376*1031c584SApple OSS Distributions 		ml_phys_write_word_64(addr, value);
377*1031c584SApple OSS Distributions 	} else {
378*1031c584SApple OSS Distributions 		ml_phys_write_word((vm_offset_t) address, value);
379*1031c584SApple OSS Distributions 	}
380*1031c584SApple OSS Distributions }
381*1031c584SApple OSS Distributions 
382*1031c584SApple OSS Distributions void
IOMappedWrite64(IOPhysicalAddress address,UInt64 value)383*1031c584SApple OSS Distributions IOMappedWrite64(IOPhysicalAddress address, UInt64 value)
384*1031c584SApple OSS Distributions {
385*1031c584SApple OSS Distributions 	IOMapper::checkForSystemMapper();
386*1031c584SApple OSS Distributions 
387*1031c584SApple OSS Distributions 	if (IOMapper::gSystem) {
388*1031c584SApple OSS Distributions 		addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
389*1031c584SApple OSS Distributions 		ml_phys_write_double_64(addr, value);
390*1031c584SApple OSS Distributions 	} else {
391*1031c584SApple OSS Distributions 		ml_phys_write_double((vm_offset_t) address, value);
392*1031c584SApple OSS Distributions 	}
393*1031c584SApple OSS Distributions }
394*1031c584SApple OSS Distributions 
395*1031c584SApple OSS Distributions __END_DECLS
396