1368ad365SApple OSS Distributions /*
288cc0b97SApple OSS Distributions * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
3368ad365SApple OSS Distributions *
4e13b1fa5SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5368ad365SApple OSS Distributions *
6e13b1fa5SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7e13b1fa5SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8e13b1fa5SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9e13b1fa5SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10e13b1fa5SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11e13b1fa5SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12e13b1fa5SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13e13b1fa5SApple OSS Distributions * terms of an Apple operating system software license agreement.
14368ad365SApple OSS Distributions *
15e13b1fa5SApple OSS Distributions * Please obtain a copy of the License at
16e13b1fa5SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17e13b1fa5SApple OSS Distributions *
18e13b1fa5SApple OSS Distributions * The Original Code and all software distributed under the License are
19e13b1fa5SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20368ad365SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21368ad365SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22e13b1fa5SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23e13b1fa5SApple OSS Distributions * Please see the License for the specific language governing rights and
24e13b1fa5SApple OSS Distributions * limitations under the License.
25368ad365SApple OSS Distributions *
26e13b1fa5SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27368ad365SApple OSS Distributions */
28bb611c8fSApple OSS Distributions
29bb611c8fSApple OSS Distributions #define IOKIT_ENABLE_SHARED_PTR
30bb611c8fSApple OSS Distributions
31368ad365SApple OSS Distributions #include <IOKit/IOLib.h>
32368ad365SApple OSS Distributions #include <IOKit/IOMapper.h>
333ca3bd55SApple OSS Distributions #include <IOKit/IODMACommand.h>
34368ad365SApple OSS Distributions #include <libkern/c++/OSData.h>
35186b8fceSApple OSS Distributions #include <libkern/OSDebug.h>
3676e12aa3SApple OSS Distributions #include <mach_debug/zone_info.h>
37*8d741a5dSApple OSS Distributions #include <vm/vm_iokit.h>
380f3703acSApple OSS Distributions #include "IOKitKernelInternal.h"
39368ad365SApple OSS Distributions
40e13b1fa5SApple OSS Distributions __BEGIN_DECLS
41e13b1fa5SApple OSS Distributions extern ppnum_t pmap_find_phys(pmap_t pmap, addr64_t va);
42e13b1fa5SApple OSS Distributions __END_DECLS
43e13b1fa5SApple OSS Distributions
44368ad365SApple OSS Distributions #define super IOService
45368ad365SApple OSS Distributions OSDefineMetaClassAndAbstractStructors(IOMapper, IOService);
46368ad365SApple OSS Distributions
470f3703acSApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 0);
480f3703acSApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 1);
490f3703acSApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 2);
500f3703acSApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 3);
51368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 4);
52368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 5);
53368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 6);
54368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 7);
55368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 8);
56368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 9);
57368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 10);
58368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 11);
59368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 12);
60368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 13);
61368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 14);
62368ad365SApple OSS Distributions OSMetaClassDefineReservedUnused(IOMapper, 15);
63368ad365SApple OSS Distributions
64368ad365SApple OSS Distributions IOMapper * IOMapper::gSystem = (IOMapper *) IOMapper::kUnknown;
65368ad365SApple OSS Distributions
66368ad365SApple OSS Distributions class IOMapperLock {
67368ad365SApple OSS Distributions IOLock *fWaitLock;
68368ad365SApple OSS Distributions public:
IOMapperLock()69a5e72196SApple OSS Distributions IOMapperLock()
70a5e72196SApple OSS Distributions {
71a5e72196SApple OSS Distributions fWaitLock = IOLockAlloc();
72a5e72196SApple OSS Distributions }
~IOMapperLock()73a5e72196SApple OSS Distributions ~IOMapperLock()
74a5e72196SApple OSS Distributions {
75a5e72196SApple OSS Distributions IOLockFree(fWaitLock);
76a5e72196SApple OSS Distributions }
77368ad365SApple OSS Distributions
78a5e72196SApple OSS Distributions void
lock()79a5e72196SApple OSS Distributions lock()
80a5e72196SApple OSS Distributions {
81a5e72196SApple OSS Distributions IOLockLock(fWaitLock);
82a5e72196SApple OSS Distributions }
83a5e72196SApple OSS Distributions void
unlock()84a5e72196SApple OSS Distributions unlock()
85a5e72196SApple OSS Distributions {
86a5e72196SApple OSS Distributions IOLockUnlock(fWaitLock);
87a5e72196SApple OSS Distributions }
88a5e72196SApple OSS Distributions void
sleep(void * event)89a5e72196SApple OSS Distributions sleep(void *event)
90a5e72196SApple OSS Distributions {
91a5e72196SApple OSS Distributions IOLockSleep(fWaitLock, event, THREAD_UNINT);
92a5e72196SApple OSS Distributions }
93a5e72196SApple OSS Distributions void
wakeup(void * event)94a5e72196SApple OSS Distributions wakeup(void *event)
95a5e72196SApple OSS Distributions {
96a5e72196SApple OSS Distributions IOLockWakeup(fWaitLock, event, false);
97a5e72196SApple OSS Distributions }
98368ad365SApple OSS Distributions };
99368ad365SApple OSS Distributions
100368ad365SApple OSS Distributions static IOMapperLock sMapperLock;
101368ad365SApple OSS Distributions
102a5e72196SApple OSS Distributions bool
start(IOService * provider)103a5e72196SApple OSS Distributions IOMapper::start(IOService *provider)
104368ad365SApple OSS Distributions {
105bb611c8fSApple OSS Distributions OSSharedPtr<OSObject> obj;
106a5e72196SApple OSS Distributions if (!super::start(provider)) {
107368ad365SApple OSS Distributions return false;
108a5e72196SApple OSS Distributions }
109368ad365SApple OSS Distributions
110a5e72196SApple OSS Distributions if (!initHardware(provider)) {
111368ad365SApple OSS Distributions return false;
112a5e72196SApple OSS Distributions }
113368ad365SApple OSS Distributions
114bb611c8fSApple OSS Distributions uint64_t pageSize = getPageSize();
115bb611c8fSApple OSS Distributions assert(pageSize <= UINT_MAX);
116bb611c8fSApple OSS Distributions fPageSize = (uint32_t) pageSize;
1170f3703acSApple OSS Distributions
118368ad365SApple OSS Distributions if (fIsSystem) {
119368ad365SApple OSS Distributions sMapperLock.lock();
120368ad365SApple OSS Distributions IOMapper::gSystem = this;
121368ad365SApple OSS Distributions sMapperLock.wakeup(&IOMapper::gSystem);
122368ad365SApple OSS Distributions sMapperLock.unlock();
123368ad365SApple OSS Distributions }
124368ad365SApple OSS Distributions
125a5e72196SApple OSS Distributions if (provider) {
126bb611c8fSApple OSS Distributions obj = provider->copyProperty("iommu-id");
127a5e72196SApple OSS Distributions if (!obj) {
128bb611c8fSApple OSS Distributions obj = provider->copyProperty("AAPL,phandle");
129a5e72196SApple OSS Distributions }
130a5e72196SApple OSS Distributions if (obj) {
131bb611c8fSApple OSS Distributions setProperty(gIOMapperIDKey, obj.get());
1323ca3bd55SApple OSS Distributions }
133a5e72196SApple OSS Distributions }
134368ad365SApple OSS Distributions return true;
135368ad365SApple OSS Distributions }
136368ad365SApple OSS Distributions
137a5e72196SApple OSS Distributions void
free()138a5e72196SApple OSS Distributions IOMapper::free()
139368ad365SApple OSS Distributions {
140368ad365SApple OSS Distributions super::free();
141368ad365SApple OSS Distributions }
142368ad365SApple OSS Distributions
143a5e72196SApple OSS Distributions void
setMapperRequired(bool hasMapper)144a5e72196SApple OSS Distributions IOMapper::setMapperRequired(bool hasMapper)
145368ad365SApple OSS Distributions {
146a5e72196SApple OSS Distributions if (hasMapper) {
147368ad365SApple OSS Distributions IOMapper::gSystem = (IOMapper *) kHasMapper;
148a5e72196SApple OSS Distributions } else {
149368ad365SApple OSS Distributions sMapperLock.lock();
150368ad365SApple OSS Distributions IOMapper::gSystem = (IOMapper *) kNoMapper;
151368ad365SApple OSS Distributions sMapperLock.unlock();
152368ad365SApple OSS Distributions sMapperLock.wakeup(&IOMapper::gSystem);
153368ad365SApple OSS Distributions }
154368ad365SApple OSS Distributions }
155368ad365SApple OSS Distributions
156a5e72196SApple OSS Distributions void
waitForSystemMapper()157a5e72196SApple OSS Distributions IOMapper::waitForSystemMapper()
158368ad365SApple OSS Distributions {
159368ad365SApple OSS Distributions sMapperLock.lock();
160a5e72196SApple OSS Distributions while ((uintptr_t) IOMapper::gSystem & kWaitMask) {
161186b8fceSApple OSS Distributions OSReportWithBacktrace("waitForSystemMapper");
162368ad365SApple OSS Distributions sMapperLock.sleep(&IOMapper::gSystem);
163186b8fceSApple OSS Distributions }
164368ad365SApple OSS Distributions sMapperLock.unlock();
165368ad365SApple OSS Distributions }
166368ad365SApple OSS Distributions
167bb611c8fSApple OSS Distributions OSSharedPtr<IOMapper>
copyMapperForDevice(IOService * device)168a5e72196SApple OSS Distributions IOMapper::copyMapperForDevice(IOService * device)
1693ca3bd55SApple OSS Distributions {
170186b8fceSApple OSS Distributions return copyMapperForDeviceWithIndex(device, 0);
171186b8fceSApple OSS Distributions }
172186b8fceSApple OSS Distributions
173bb611c8fSApple OSS Distributions OSSharedPtr<IOMapper>
copyMapperForDeviceWithIndex(IOService * device,unsigned int index)174a5e72196SApple OSS Distributions IOMapper::copyMapperForDeviceWithIndex(IOService * device, unsigned int index)
175186b8fceSApple OSS Distributions {
176bb611c8fSApple OSS Distributions OSSharedPtr<OSData> data;
177bb611c8fSApple OSS Distributions OSSharedPtr<OSObject> obj;
178bb611c8fSApple OSS Distributions OSSharedPtr<IOMapper> mapper;
179bb611c8fSApple OSS Distributions OSSharedPtr<OSDictionary> matching;
1803ca3bd55SApple OSS Distributions
1813ca3bd55SApple OSS Distributions obj = device->copyProperty("iommu-parent");
182a5e72196SApple OSS Distributions if (!obj) {
183a5e72196SApple OSS Distributions return NULL;
184a5e72196SApple OSS Distributions }
1853ca3bd55SApple OSS Distributions
186bb611c8fSApple OSS Distributions if ((mapper = OSDynamicPtrCast<IOMapper>(obj))) {
187a5e72196SApple OSS Distributions goto found;
188a5e72196SApple OSS Distributions }
1893ca3bd55SApple OSS Distributions
190bb611c8fSApple OSS Distributions if ((data = OSDynamicPtrCast<OSData>(obj))) {
191a5e72196SApple OSS Distributions if (index >= data->getLength() / sizeof(UInt32)) {
192bb611c8fSApple OSS Distributions goto found;
193a5e72196SApple OSS Distributions }
194186b8fceSApple OSS Distributions
195e7776783SApple OSS Distributions data = OSData::withValueNoCopy(*((UInt32 *)data->getBytesNoCopy() + index));
196a5e72196SApple OSS Distributions if (!data) {
197bb611c8fSApple OSS Distributions goto found;
198a5e72196SApple OSS Distributions }
199186b8fceSApple OSS Distributions
200bb611c8fSApple OSS Distributions matching = IOService::propertyMatching(gIOMapperIDKey, data.get());
201a5e72196SApple OSS Distributions } else {
202bb611c8fSApple OSS Distributions matching = IOService::propertyMatching(gIOMapperIDKey, obj.get());
203a5e72196SApple OSS Distributions }
204186b8fceSApple OSS Distributions
205a5e72196SApple OSS Distributions if (matching) {
206bb611c8fSApple OSS Distributions mapper = OSDynamicPtrCast<IOMapper>(IOService::waitForMatchingService(matching.get()));
2073ca3bd55SApple OSS Distributions }
2083ca3bd55SApple OSS Distributions
20976e12aa3SApple OSS Distributions found:
210a5e72196SApple OSS Distributions if (mapper) {
211a5e72196SApple OSS Distributions if (!mapper->fAllocName) {
21276e12aa3SApple OSS Distributions char name[MACH_ZONE_NAME_MAX_LEN];
21376e12aa3SApple OSS Distributions char kmodname[KMOD_MAX_NAME];
21476e12aa3SApple OSS Distributions vm_tag_t tag;
21576e12aa3SApple OSS Distributions uint32_t kmodid;
21676e12aa3SApple OSS Distributions
21776e12aa3SApple OSS Distributions tag = IOMemoryTag(kernel_map);
218a5e72196SApple OSS Distributions if (!(kmodid = vm_tag_get_kext(tag, &kmodname[0], KMOD_MAX_NAME))) {
21976e12aa3SApple OSS Distributions snprintf(kmodname, sizeof(kmodname), "%d", tag);
22076e12aa3SApple OSS Distributions }
22176e12aa3SApple OSS Distributions snprintf(name, sizeof(name), "%s.DMA.%s", kmodname, device->getName());
22276e12aa3SApple OSS Distributions mapper->fAllocName = kern_allocation_name_allocate(name, 16);
22376e12aa3SApple OSS Distributions }
22476e12aa3SApple OSS Distributions }
22576e12aa3SApple OSS Distributions
226a5e72196SApple OSS Distributions return mapper;
2273ca3bd55SApple OSS Distributions }
2283ca3bd55SApple OSS Distributions
229368ad365SApple OSS Distributions __BEGIN_DECLS
230368ad365SApple OSS Distributions
231368ad365SApple OSS Distributions // These are C accessors to the system mapper for non-IOKit clients
232a5e72196SApple OSS Distributions ppnum_t
IOMapperIOVMAlloc(unsigned pages)233a5e72196SApple OSS Distributions IOMapperIOVMAlloc(unsigned pages)
234368ad365SApple OSS Distributions {
2350f3703acSApple OSS Distributions IOReturn ret;
2360f3703acSApple OSS Distributions uint64_t dmaAddress, dmaLength;
2370f3703acSApple OSS Distributions
238368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
239368ad365SApple OSS Distributions
2400f3703acSApple OSS Distributions ret = kIOReturnUnsupported;
241a5e72196SApple OSS Distributions if (IOMapper::gSystem) {
2420f3703acSApple OSS Distributions ret = IOMapper::gSystem->iovmMapMemory(
2430f3703acSApple OSS Distributions NULL, 0, ptoa_64(pages),
2440f3703acSApple OSS Distributions (kIODMAMapReadAccess | kIODMAMapWriteAccess),
2450f3703acSApple OSS Distributions NULL, NULL, NULL,
2460f3703acSApple OSS Distributions &dmaAddress, &dmaLength);
2470f3703acSApple OSS Distributions }
2480f3703acSApple OSS Distributions
249a5e72196SApple OSS Distributions if (kIOReturnSuccess == ret) {
250bb611c8fSApple OSS Distributions uint64_t dmaAddressPage64;
251bb611c8fSApple OSS Distributions dmaAddressPage64 = atop_64(dmaAddress);
252bb611c8fSApple OSS Distributions if (dmaAddressPage64 > UINT_MAX) {
253bb611c8fSApple OSS Distributions return 0;
254bb611c8fSApple OSS Distributions }
255bb611c8fSApple OSS Distributions return (ppnum_t) atop_64(dmaAddress);
256a5e72196SApple OSS Distributions }
257a5e72196SApple OSS Distributions return 0;
258368ad365SApple OSS Distributions }
259368ad365SApple OSS Distributions
260a5e72196SApple OSS Distributions void
IOMapperIOVMFree(ppnum_t addr,unsigned pages)261a5e72196SApple OSS Distributions IOMapperIOVMFree(ppnum_t addr, unsigned pages)
262368ad365SApple OSS Distributions {
263a5e72196SApple OSS Distributions if (IOMapper::gSystem) {
2640f3703acSApple OSS Distributions IOMapper::gSystem->iovmUnmapMemory(NULL, NULL, ptoa_64(addr), ptoa_64(pages));
2650f3703acSApple OSS Distributions }
266368ad365SApple OSS Distributions }
267368ad365SApple OSS Distributions
268a5e72196SApple OSS Distributions ppnum_t
IOMapperInsertPage(ppnum_t addr,unsigned offset,ppnum_t page)269a5e72196SApple OSS Distributions IOMapperInsertPage(ppnum_t addr, unsigned offset, ppnum_t page)
270368ad365SApple OSS Distributions {
271a5e72196SApple OSS Distributions if (!IOMapper::gSystem) {
272a5e72196SApple OSS Distributions return page;
273a5e72196SApple OSS Distributions }
274a5e72196SApple OSS Distributions if (!addr) {
275a5e72196SApple OSS Distributions panic("!addr");
276a5e72196SApple OSS Distributions }
2770f3703acSApple OSS Distributions IOMapper::gSystem->iovmInsert((kIODMAMapReadAccess | kIODMAMapWriteAccess),
2780f3703acSApple OSS Distributions ptoa_64(addr), ptoa_64(offset), ptoa_64(page), ptoa_64(1));
279a5e72196SApple OSS Distributions return addr + offset;
280368ad365SApple OSS Distributions }
281368ad365SApple OSS Distributions
282368ad365SApple OSS Distributions /////////////////////////////////////////////////////////////////////////////
283368ad365SApple OSS Distributions //
284368ad365SApple OSS Distributions //
285368ad365SApple OSS Distributions // IOLib.h APIs
286368ad365SApple OSS Distributions //
287368ad365SApple OSS Distributions //
288368ad365SApple OSS Distributions /////////////////////////////////////////////////////////////////////////////
289368ad365SApple OSS Distributions
290368ad365SApple OSS Distributions #include <machine/machine_routines.h>
291368ad365SApple OSS Distributions
292a5e72196SApple OSS Distributions UInt8
IOMappedRead8(IOPhysicalAddress address)293a5e72196SApple OSS Distributions IOMappedRead8(IOPhysicalAddress address)
294368ad365SApple OSS Distributions {
295368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
296368ad365SApple OSS Distributions
297368ad365SApple OSS Distributions if (IOMapper::gSystem) {
2980f3703acSApple OSS Distributions addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
299368ad365SApple OSS Distributions return (UInt8) ml_phys_read_byte_64(addr);
300a5e72196SApple OSS Distributions } else {
301368ad365SApple OSS Distributions return (UInt8) ml_phys_read_byte((vm_offset_t) address);
302368ad365SApple OSS Distributions }
303a5e72196SApple OSS Distributions }
304368ad365SApple OSS Distributions
305a5e72196SApple OSS Distributions UInt16
IOMappedRead16(IOPhysicalAddress address)306a5e72196SApple OSS Distributions IOMappedRead16(IOPhysicalAddress address)
307368ad365SApple OSS Distributions {
308368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
309368ad365SApple OSS Distributions
310368ad365SApple OSS Distributions if (IOMapper::gSystem) {
3110f3703acSApple OSS Distributions addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
312368ad365SApple OSS Distributions return (UInt16) ml_phys_read_half_64(addr);
313a5e72196SApple OSS Distributions } else {
314368ad365SApple OSS Distributions return (UInt16) ml_phys_read_half((vm_offset_t) address);
315368ad365SApple OSS Distributions }
316a5e72196SApple OSS Distributions }
317368ad365SApple OSS Distributions
318a5e72196SApple OSS Distributions UInt32
IOMappedRead32(IOPhysicalAddress address)319a5e72196SApple OSS Distributions IOMappedRead32(IOPhysicalAddress address)
320368ad365SApple OSS Distributions {
321368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
322368ad365SApple OSS Distributions
323368ad365SApple OSS Distributions if (IOMapper::gSystem) {
3240f3703acSApple OSS Distributions addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
325368ad365SApple OSS Distributions return (UInt32) ml_phys_read_word_64(addr);
326a5e72196SApple OSS Distributions } else {
327368ad365SApple OSS Distributions return (UInt32) ml_phys_read_word((vm_offset_t) address);
328368ad365SApple OSS Distributions }
329a5e72196SApple OSS Distributions }
330368ad365SApple OSS Distributions
331a5e72196SApple OSS Distributions UInt64
IOMappedRead64(IOPhysicalAddress address)332a5e72196SApple OSS Distributions IOMappedRead64(IOPhysicalAddress address)
333368ad365SApple OSS Distributions {
334368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
335368ad365SApple OSS Distributions
336368ad365SApple OSS Distributions if (IOMapper::gSystem) {
3370f3703acSApple OSS Distributions addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
338368ad365SApple OSS Distributions return (UInt64) ml_phys_read_double_64(addr);
339a5e72196SApple OSS Distributions } else {
340368ad365SApple OSS Distributions return (UInt64) ml_phys_read_double((vm_offset_t) address);
341368ad365SApple OSS Distributions }
342a5e72196SApple OSS Distributions }
343368ad365SApple OSS Distributions
344a5e72196SApple OSS Distributions void
IOMappedWrite8(IOPhysicalAddress address,UInt8 value)345a5e72196SApple OSS Distributions IOMappedWrite8(IOPhysicalAddress address, UInt8 value)
346368ad365SApple OSS Distributions {
347368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
348368ad365SApple OSS Distributions
349368ad365SApple OSS Distributions if (IOMapper::gSystem) {
3500f3703acSApple OSS Distributions addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
351368ad365SApple OSS Distributions ml_phys_write_byte_64(addr, value);
352a5e72196SApple OSS Distributions } else {
353368ad365SApple OSS Distributions ml_phys_write_byte((vm_offset_t) address, value);
354368ad365SApple OSS Distributions }
355a5e72196SApple OSS Distributions }
356368ad365SApple OSS Distributions
357a5e72196SApple OSS Distributions void
IOMappedWrite16(IOPhysicalAddress address,UInt16 value)358a5e72196SApple OSS Distributions IOMappedWrite16(IOPhysicalAddress address, UInt16 value)
359368ad365SApple OSS Distributions {
360368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
361368ad365SApple OSS Distributions
362368ad365SApple OSS Distributions if (IOMapper::gSystem) {
3630f3703acSApple OSS Distributions addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
364368ad365SApple OSS Distributions ml_phys_write_half_64(addr, value);
365a5e72196SApple OSS Distributions } else {
366368ad365SApple OSS Distributions ml_phys_write_half((vm_offset_t) address, value);
367368ad365SApple OSS Distributions }
368a5e72196SApple OSS Distributions }
369368ad365SApple OSS Distributions
370a5e72196SApple OSS Distributions void
IOMappedWrite32(IOPhysicalAddress address,UInt32 value)371a5e72196SApple OSS Distributions IOMappedWrite32(IOPhysicalAddress address, UInt32 value)
372368ad365SApple OSS Distributions {
373368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
374368ad365SApple OSS Distributions
375368ad365SApple OSS Distributions if (IOMapper::gSystem) {
3760f3703acSApple OSS Distributions addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
377368ad365SApple OSS Distributions ml_phys_write_word_64(addr, value);
378a5e72196SApple OSS Distributions } else {
379368ad365SApple OSS Distributions ml_phys_write_word((vm_offset_t) address, value);
380368ad365SApple OSS Distributions }
381a5e72196SApple OSS Distributions }
382368ad365SApple OSS Distributions
383a5e72196SApple OSS Distributions void
IOMappedWrite64(IOPhysicalAddress address,UInt64 value)384a5e72196SApple OSS Distributions IOMappedWrite64(IOPhysicalAddress address, UInt64 value)
385368ad365SApple OSS Distributions {
386368ad365SApple OSS Distributions IOMapper::checkForSystemMapper();
387368ad365SApple OSS Distributions
388368ad365SApple OSS Distributions if (IOMapper::gSystem) {
3890f3703acSApple OSS Distributions addr64_t addr = IOMapper::gSystem->mapToPhysicalAddress(address);
390368ad365SApple OSS Distributions ml_phys_write_double_64(addr, value);
391a5e72196SApple OSS Distributions } else {
392368ad365SApple OSS Distributions ml_phys_write_double((vm_offset_t) address, value);
393368ad365SApple OSS Distributions }
394a5e72196SApple OSS Distributions }
395368ad365SApple OSS Distributions
396368ad365SApple OSS Distributions __END_DECLS
397