本文整理汇总了C++中IOBufferMemoryDescriptor类的典型用法代码示例。如果您正苦于以下问题:C++ IOBufferMemoryDescriptor类的具体用法?C++ IOBufferMemoryDescriptor怎么用?C++ IOBufferMemoryDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IOBufferMemoryDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pci_free_consistent
void pci_free_consistent(void *pdev, size_t size, void *vaddr, dma_addr_t dma_handle)
{
// free a hw dma scatter/gather list located in host memory
int index;
OSArray *dma_info_array;
IOBufferMemoryDescriptor *memDesc;
IOVirtualAddress virt_address;
// search for the correct dma_info by checking against passed virtual address
dma_info_array = g_bcm_dma_info;
for(index = 0; index < (int)dma_info_array->getCount(); index++) {
memDesc = (IOBufferMemoryDescriptor*)dma_info_array->getObject(index);
virt_address = (IOVirtualAddress)memDesc->getBytesNoCopy();
if ((IOVirtualAddress)vaddr == virt_address) {
//IOLog("pci_free_consistent padd(%p), size(0x%X)\n", dma_handle, size);
// found it, now complete. removeObject will release it
memDesc->complete();
dma_info_array->removeObject(index);
// should be able to just call memDesc->release() after memDesc->complete()
// but on atv, there's something holding a ref to memDesc and so we leak memory
// everytime the crystalhs driver closes. Doing the release this way fixes the mem
// leak on atv and is fine under real 10.4/10.5 boxes.
SAFE_RELEASE(memDesc);
break;
}
}
}
示例2: IOLog
void *pci_alloc_consistent(void *pdev, size_t size, dma_addr_t *dma_handle)
{
IOBufferMemoryDescriptor *memDesc;
IOVirtualAddress virt_address;
IOPhysicalAddress phys_address;
// construct a memory descriptor for a buffer below the 4Gb line,
// addressable by 32 bit DMA and page aligned.
memDesc = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task,
kIOMemoryPhysicallyContiguous, size, PAGE_SIZE);
if (memDesc) {
IOByteCount offset = 0;
IOByteCount length;
memDesc->prepare();
virt_address = (IOVirtualAddress)memDesc->getBytesNoCopy();
phys_address = memDesc->getPhysicalSegment(offset, &length);
g_bcm_dma_info->setObject(memDesc);
} else {
virt_address = NULL;
phys_address = NULL;
IOLog("pci_alloc_consistent:IOBufferMemoryDescriptor::inTaskWithOptions failed\n");
}
//IOLog("pci_alloc_consistent paddr(0x%X), size(0x%X)\n", (unsigned int)phys_address, size);
*dma_handle = phys_address;
return (void*)virt_address;
}
示例3: OSDynamicCast
IOReturn XboxOneControllerClass::handleReport(IOMemoryDescriptor * descriptor, IOHIDReportType reportType, IOOptionBits options)
{
if (descriptor->getLength() >= sizeof(XBOXONE_IN_GUIDE_REPORT)) {
IOBufferMemoryDescriptor *desc = OSDynamicCast(IOBufferMemoryDescriptor, descriptor);
if (desc != NULL) {
XBOXONE_ELITE_IN_REPORT *report=(XBOXONE_ELITE_IN_REPORT*)desc->getBytesNoCopy();
if ((report->header.command==0x07) && (report->header.size==(sizeof(XBOXONE_IN_GUIDE_REPORT)-4)))
{
XBOXONE_IN_GUIDE_REPORT *guideReport=(XBOXONE_IN_GUIDE_REPORT*)report;
isXboxOneGuideButtonPressed = (bool)guideReport->state;
XBOX360_IN_REPORT *oldReport = (XBOX360_IN_REPORT*)lastData;
oldReport->buttons ^= (-isXboxOneGuideButtonPressed ^ oldReport->buttons) & (1 << GetOwner(this)->mapping[10]);
memcpy(report, lastData, sizeof(XBOX360_IN_REPORT));
}
else if (report->header.command==0x20)
{
if (report->header.size==0x0e || report->header.size==0x1d || report->header.size==0x1a)
{
convertFromXboxOne(report, report->header.size);
XBOX360_IN_REPORT *report360=(XBOX360_IN_REPORT*)report;
if (!(GetOwner(this)->noMapping))
remapButtons(report360);
GetOwner(this)->fiddleReport(report360->left, report360->right);
if (GetOwner(this)->swapSticks)
remapAxes(report360);
memcpy(lastData, report360, sizeof(XBOX360_IN_REPORT));
}
}
}
}
IOReturn ret = IOHIDDevice::handleReport(descriptor, reportType, options);
return ret;
}
示例4: QueueWrite
// Queue an asynchronous write on a controller
bool WirelessGamingReceiver::QueueWrite(int index, const void *bytes, UInt32 length)
{
IOBufferMemoryDescriptor *outBuffer;
IOUSBCompletion complete;
IOReturn err;
outBuffer = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task, 0, length);
if (outBuffer == NULL)
{
// IOLog("send - unable to allocate buffer\n");
return false;
}
outBuffer->writeBytes(0, bytes, length);
complete.target = this;
complete.action = _WriteComplete;
complete.parameter = outBuffer;
err = connections[index].controllerOut->Write(outBuffer, 0, 0, length, &complete);
if (err == kIOReturnSuccess)
return true;
else
{
// IOLog("send - failed to start (0x%.8x)\n",err);
return false;
}
}
示例5:
// Returns the HID descriptor for this device
IOReturn Xbox360ControllerClass::newReportDescriptor(IOMemoryDescriptor **descriptor) const
{
IOBufferMemoryDescriptor *buffer = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task,0,sizeof(HID_360::ReportDescriptor));
if (buffer == NULL) return kIOReturnNoResources;
buffer->writeBytes(0,HID_360::ReportDescriptor,sizeof(HID_360::ReportDescriptor));
*descriptor=buffer;
return kIOReturnSuccess;
}
示例6: IOMallocContiguous
void * IOMallocContiguous(vm_size_t size, vm_size_t alignment,
IOPhysicalAddress * physicalAddress)
{
mach_vm_address_t address = 0;
if (size == 0)
return 0;
if (alignment == 0)
alignment = 1;
/* Do we want a physical address? */
if (!physicalAddress)
{
address = IOKernelAllocateWithPhysicalRestrict(size, 0 /*maxPhys*/, alignment, true);
}
else do
{
IOBufferMemoryDescriptor * bmd;
mach_vm_address_t physicalMask;
vm_offset_t alignMask;
alignMask = alignment - 1;
physicalMask = (0xFFFFFFFF ^ alignMask);
bmd = IOBufferMemoryDescriptor::inTaskWithPhysicalMask(
kernel_task, kIOMemoryPhysicallyContiguous, size, physicalMask);
if (!bmd)
break;
_IOMallocContiguousEntry *
entry = IONew(_IOMallocContiguousEntry, 1);
if (!entry)
{
bmd->release();
break;
}
entry->virtualAddr = (mach_vm_address_t) bmd->getBytesNoCopy();
entry->md = bmd;
lck_mtx_lock(gIOMallocContiguousEntriesLock);
queue_enter( &gIOMallocContiguousEntries, entry,
_IOMallocContiguousEntry *, link );
lck_mtx_unlock(gIOMallocContiguousEntriesLock);
address = (mach_vm_address_t) entry->virtualAddr;
*physicalAddress = bmd->getPhysicalAddress();
}
while (false);
if (address) {
IOStatisticsAlloc(kIOStatisticsMallocContiguous, size);
}
return (void *) address;
}
示例7:
IOBufferMemoryDescriptor * IOBufferMemoryDescriptor::withOptions(
IOOptionBits options,
vm_size_t capacity,
vm_offset_t alignment)
{
IOBufferMemoryDescriptor *me = new IOBufferMemoryDescriptor;
if (me && !me->initWithPhysicalMask(kernel_task, options, capacity, alignment, 0)) {
me->release();
me = 0;
}
return me;
}
示例8:
/*
* withBytes:
*
* Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
* The descriptor's length and capacity are set to the input buffer's size.
*/
IOBufferMemoryDescriptor *
IOBufferMemoryDescriptor::withBytes(const void * inBytes,
vm_size_t inLength,
IODirection inDirection,
bool inContiguous)
{
IOBufferMemoryDescriptor *me = new IOBufferMemoryDescriptor;
if (me && !me->initWithBytes(inBytes, inLength, inDirection, inContiguous)) {
me->release();
me = 0;
}
return me;
}
示例9: OSDynamicCast
IOReturn Xbox360ControllerClass::handleReport(IOMemoryDescriptor * descriptor, IOHIDReportType reportType, IOOptionBits options) {
if (descriptor->getLength() >= sizeof(XBOX360_IN_REPORT)) {
IOBufferMemoryDescriptor *desc = OSDynamicCast(IOBufferMemoryDescriptor, descriptor);
if (desc != NULL) {
XBOX360_IN_REPORT *report=(XBOX360_IN_REPORT*)desc->getBytesNoCopy();
if ((report->header.command==inReport) && (report->header.size==sizeof(XBOX360_IN_REPORT))) {
GetOwner(this)->fiddleReport(desc);
remapButtons(report);
}
}
}
IOReturn ret = IOHIDDevice::handleReport(descriptor, reportType, options);
return ret;
}
示例10: IOLog
IOReturn it_unbit_foohid_device::newReportDescriptor(IOMemoryDescriptor **descriptor) const {
IOLog("it_unbit_foohid_device::newReportDescriptor()\n");
IOBufferMemoryDescriptor *buffer = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task, 0, reportDescriptor_len);
if (buffer == NULL) {
IOLog("OOOOPS");
return kIOReturnNoResources;
}
buffer->writeBytes(0, reportDescriptor, reportDescriptor_len);
*descriptor = buffer;
IOLog("all fine\n");
return kIOReturnSuccess;
}
示例11: MemoryDmaAlloc
IOBufferMemoryDescriptor* MemoryDmaAlloc(UInt32 buf_size, dma_addr_t *phys_add, void *virt_add)
{
IOBufferMemoryDescriptor *memBuffer;
void *virt_address;
dma_addr_t phys_address;
IOMemoryMap *memMap;
memBuffer = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task,
kIODirectionOutIn | kIOMemoryPhysicallyContiguous | \
kIOMemoryAutoPrepare | kIOMapInhibitCache, buf_size, \
PAGE_SIZE);
if (memBuffer == NULL) {
//IOLog("Memory Allocation failed - RLC");
return NULL;
}
memMap = memBuffer->map();
if (memMap == NULL) {
//IOLog("mapping failed\n");
memBuffer->release();
memBuffer = NULL;
return NULL;
}
phys_address = memMap->getPhysicalAddress();
virt_address = (void *)memMap->getVirtualAddress();
if (virt_address == NULL || phys_address == NULL) {
memMap->release();
memBuffer->release();
memBuffer = NULL;
return NULL;
}
*phys_add = phys_address;
*(IOVirtualAddress*)virt_add = (IOVirtualAddress)virt_address;
memMap->release();
return memBuffer;
}
示例12: KINFO
/* read the <partition#> sector on the root address for label and size */
void net_habitue_device_SC101::partitionCompletion(void *parameter, IOReturn status, UInt64 actualByteCount)
{
if (status != kIOReturnSuccess || actualByteCount != sizeof(psan_get_response_partition_t))
{
KINFO("partition lookup on %s failed", getID()->getCStringNoCopy());
return;
}
IOBufferMemoryDescriptor *buffer = (IOBufferMemoryDescriptor *)parameter;
psan_get_response_partition_t *part = (psan_get_response_partition_t *)buffer->getBytesNoCopy();
OSString *id = getID();
for (UInt32 i = 0; i < actualByteCount / sizeof(psan_get_response_partition_t); i++, part++)
{
KDEBUG("cmp %s", part->id);
if (strncmp(part->id, id->getCStringNoCopy(), id->getLength() + 1) != 0)
continue;
KDEBUG("Matched!");
OSString *label = OSString::withCString(part->label);
if (label)
{
setProperty(gSC101DeviceLabelKey, label);
label->release();
}
OSNumber *size = OSNumber::withNumber(getUInt48(part->sector_size) << 9, 64);
if (size)
{
setProperty(gSC101DeviceSizeKey, size);
size->release();
}
if (1) // TODO(iwade) determine minimum fields needed
{
_mediaStateAttached = true;
_mediaStateChanged = true;
}
break;
}
}
示例13: UInt16
void VoodooI2CHIDDevice::i2c_hid_get_input(OSObject* owner, IOTimerEventSource* sender) {
// IOLog("getting input\n");
if (hid_device->reading)
return;
UInt rsize;
int ret;
rsize = UInt16(ihid->hdesc.wMaxInputLength);
unsigned char* rdesc = (unsigned char *)IOMalloc(rsize);
ret = i2c_hid_command(ihid, &hid_input_cmd, rdesc, rsize);
// IOLog("===Input (%d)===\n", rsize);
// for (int i = 0; i < rsize; i++)
// IOLog("0x%02x ", (UInt8) rdesc[i]);
// IOLog("\n");
int return_size = rdesc[0] | rdesc[1] << 8;
if (return_size == 0) {
/* host or device initiated RESET completed */
// test/clear bit?
hid_device->timerSource->setTimeoutMS(10);
return;
}
if (return_size > rsize) {
IOLog("%s: Incomplete report %d/%d\n", __func__, rsize, return_size);
}
IOBufferMemoryDescriptor *buffer = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task, 0, return_size);
buffer->writeBytes(0, rdesc + 2, return_size - 2);
IOReturn err = _wrapper->handleReport(buffer, kIOHIDReportTypeInput);
if (err != kIOReturnSuccess)
IOLog("Error handling report: 0x%.8x\n", err);
buffer->release();
IOFree(rdesc, rsize);
hid_device->timerSource->setTimeoutMS(10);
}
示例14: limit
IOBufferMemoryDescriptor *kXAudioEngine::my_alloc_contiguous(mach_vm_size_t size, void **addr, dword *phys)
{
if(size<PAGE_SIZE)
size=PAGE_SIZE;
#ifdef DEBUGGING
size += 2 * PAGE_SIZE;
#endif
//void *addr=IOMallocContiguous(size+PAGE_SIZE+PAGE_SIZE,alignment,phys);
mach_vm_address_t mask = 0x000000007FFFFFFFULL & ~(PAGE_SIZE - 1);
IOBufferMemoryDescriptor *desc =
IOBufferMemoryDescriptor::inTaskWithPhysicalMask(
kernel_task,
kIODirectionInOut | kIOMemoryPhysicallyContiguous,
size,
mask);
if(desc)
{
desc->prepare();
IOPhysicalAddress pa = desc->getPhysicalAddress();
if (pa & ~mask)
debug("kXAudioEngine[%p]::my_alloc_contiguous() - memory misaligned or beyond 2GB limit (%p)\n", this, (void *)pa);
*phys = (dword)pa;
*addr = desc->getBytesNoCopy();
#ifdef DEBUGGING
memset(addr,0x11,PAGE_SIZE);
memset((UInt8 *)addr+PAGE_SIZE+size,0x22,PAGE_SIZE);
*((UInt8 *)addr) += PAGE_SIZE;
*phys += PAGE_SIZE;
#endif
}
else
debug("kXAudioEngine[%p]::my_alloc_contiguous() - allocation failed\n",this);
return desc;
}
示例15: IOLog
IOReturn org_litio_OzoneStrikeBattle::newReportDescriptor(IOMemoryDescriptor** descriptor) const {
// TODO: Define new device descriptor struct for the keyboard.
// Assigning current descriptor.
IOLog("OzoneStrike::%s[%p] - Setting HID report descriptor.\n", getName(), this);
OSData *reportDescriptor = OSData::withBytes(Ozone::HIDReportDescriptor, sizeof(Ozone::HIDReportDescriptor));
OSData *reportDescriptorNew = OSDynamicCast(OSData, getProperty("ReportDescriptorOverride"));
if (reportDescriptor == NULL) {
IOLog("OzoneStrike::%s[%p] - reportDescriptor OSData not set.\n", getName(), this);
return kIOReturnNoResources;
}
printBytes(reportDescriptorNew);
printBytes(reportDescriptor);
IOLog("OzoneStrike::%s[%p] - reportDescriptor OSData set (size: %d, data: %s).\n", getName(), this, reportDescriptor->getLength(), reportDescriptor->getBytesNoCopy());
//OSData *reportDescriptor = OSDynamicCast(OSData, Ozone::HIDReportDescriptor);
IOBufferMemoryDescriptor *bufferDescriptor = IOBufferMemoryDescriptor::withBytes(reportDescriptor->getBytesNoCopy(),
reportDescriptor->getLength(),
kIODirectionOutIn);
//IOBufferMemoryDescriptor *bufferDescriptor = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task,
// 0,
// sizeof(Ozone::HIDReportDescriptor));
/*
if (bufferDescriptor == NULL) {
return kIOReturnNoResources;
}
bufferDescriptor->writeBytes(0, Ozone::HIDReportDescriptor,sizeof(Ozone::HIDReportDescriptor));
*/
if (bufferDescriptor) {
*descriptor = bufferDescriptor;
return kIOReturnSuccess;
} else {
bufferDescriptor->release();
*descriptor = NULL;
return kIOReturnNoMemory;
}
//return IOUSBHostHIDDevice::newReportDescriptor(descriptor);
}