/opensource.apple.com/source/IOGraphics/IOGraphics-16.20/IOGraphicsFamily/IOI2CInterface.cpp
C++ | 240 lines | 188 code | 51 blank | 1 comment | 2 complexity | 539c54ae0ce2e1f8707651bbd84e0ee1 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>IOI2CInterface.cpp</title>
- <style type="text/css">
- .enscript-comment { font-style: italic; color: rgb(178,34,34); }
- .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
- .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
- .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
- .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
- .enscript-string { font-weight: bold; color: rgb(188,143,143); }
- .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
- .enscript-type { font-weight: bold; color: rgb(34,139,34); }
- .enscript-highlight { text-decoration: underline; color: 0; }
- </style>
- </head>
- <body id="top">
- <h1 style="margin:8px;" id="f1">IOI2CInterface.cpp <span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
- <hr/>
- <div></div>
- <pre>
- <span class="enscript-comment">/*
- * IOI2CInterface.cpp
- */</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><IOKit/IOLib.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><IOKit/IOUserClient.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><IOKit/IOLocks.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><IOKit/pwr_mgt/RootDomain.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><IOKit/ndrvsupport/IONDRVFramebuffer.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><IOKit/assert.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><libkern/c++/OSContainers.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><IOKit/i2c/IOI2CInterfacePrivate.h></span>
- <span class="enscript-comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span>
- #<span class="enscript-reference">undef</span> <span class="enscript-variable-name">super</span>
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">super</span> IOService
- <span class="enscript-function-name">OSDefineMetaClassAndAbstractStructors</span>(IOI2CInterface, IOService)
- <span class="enscript-comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span>
- <span class="enscript-type">bool</span> <span class="enscript-function-name">IOI2CInterface::registerI2C</span>( UInt64 id )
- {
- <span class="enscript-type">bool</span> result = true;
- fID = id;
- setProperty(kIOI2CInterfaceIDKey, id, 64);
- registerService();
- <span class="enscript-keyword">return</span>( result );
- }
- IOReturn <span class="enscript-function-name">IOI2CInterface::newUserClient</span>( task_t owningTask,
- <span class="enscript-type">void</span> * security_id,
- UInt32 type,
- IOUserClient ** handler )
- {
- IOReturn err = kIOReturnSuccess;
- IOUserClient * newConnect = 0;
- <span class="enscript-keyword">if</span>( type)
- <span class="enscript-keyword">return</span>( kIOReturnBadArgument );
- newConnect = IOI2CInterfaceUserClient::withTask(owningTask);
- <span class="enscript-keyword">if</span>( newConnect) {
- <span class="enscript-keyword">if</span>( !newConnect->attach( <span class="enscript-keyword">this</span> )
- || !newConnect->start( <span class="enscript-keyword">this</span> )) {
- newConnect->detach( <span class="enscript-keyword">this</span> );
- newConnect->release();
- newConnect = 0;
- }
- }
- *handler = newConnect;
- <span class="enscript-keyword">return</span>( err );
- }
- <span class="enscript-comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span>
- #<span class="enscript-reference">undef</span> <span class="enscript-variable-name">super</span>
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">super</span> IOUserClient
- <span class="enscript-function-name">OSDefineMetaClassAndStructors</span>(IOI2CInterfaceUserClient, IOUserClient)
- <span class="enscript-comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span>
- IOI2CInterfaceUserClient * <span class="enscript-function-name">IOI2CInterfaceUserClient::withTask</span>( task_t owningTask )
- {
- IOI2CInterfaceUserClient * inst;
- inst = <span class="enscript-keyword">new</span> IOI2CInterfaceUserClient;
- <span class="enscript-keyword">if</span>( inst && !inst->init()) {
- inst->release();
- inst = 0;
- }
- <span class="enscript-keyword">if</span>( inst)
- inst->fTask = owningTask;
- <span class="enscript-keyword">return</span>( inst );
- }
- <span class="enscript-type">bool</span> <span class="enscript-function-name">IOI2CInterfaceUserClient::start</span>( IOService * provider )
- {
- <span class="enscript-keyword">if</span>( !super::start( provider ))
- <span class="enscript-keyword">return</span>( false );
- <span class="enscript-keyword">return</span>( true );
- }
- IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::clientClose</span>( <span class="enscript-type">void</span> )
- {
- terminate();
- <span class="enscript-keyword">return</span>( kIOReturnSuccess );
- }
- IOService * <span class="enscript-function-name">IOI2CInterfaceUserClient::getService</span>( <span class="enscript-type">void</span> )
- {
- <span class="enscript-keyword">return</span>( getProvider() );
- }
- IOExternalMethod * <span class="enscript-function-name">IOI2CInterfaceUserClient::getTargetAndMethodForIndex</span>(
- IOService ** targetP, UInt32 index )
- {
- <span class="enscript-type">static</span> <span class="enscript-type">const</span> IOExternalMethod methodTemplate[] = {
- <span class="enscript-comment">/* 0 */</span> { NULL, (IOMethod) &IOI2CInterfaceUserClient::extAcquireBus,
- kIOUCScalarIScalarO, 0, 0 },
- <span class="enscript-comment">/* 1 */</span> { NULL, (IOMethod) &IOI2CInterfaceUserClient::extReleaseBus,
- kIOUCScalarIScalarO, 0, 0 },
- <span class="enscript-comment">/* 3 */</span> { NULL, (IOMethod) &IOI2CInterfaceUserClient::extIO,
- kIOUCStructIStructO, 0xffffffff, 0xffffffff },
- };
- <span class="enscript-keyword">if</span>( index > (<span class="enscript-keyword">sizeof</span>(methodTemplate) / <span class="enscript-keyword">sizeof</span>(methodTemplate[0])))
- <span class="enscript-keyword">return</span>( NULL );
- *targetP = <span class="enscript-keyword">this</span>;
- <span class="enscript-keyword">return</span>( (IOExternalMethod *)(methodTemplate + index) );
- }
- IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::setProperties</span>( OSObject * properties )
- {
- <span class="enscript-keyword">return</span>( kIOReturnUnsupported );
- }
- IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::extAcquireBus</span>( <span class="enscript-type">void</span> )
- {
- IOReturn ret = kIOReturnNotReady;
- IOI2CInterface * provider;
- <span class="enscript-keyword">if</span>( (provider = (IOI2CInterface *) copyParentEntry(gIOServicePlane))) {
- ret = provider->open( <span class="enscript-keyword">this</span> ) ? kIOReturnSuccess : kIOReturnBusy;
- provider->release();
- }
- <span class="enscript-keyword">return</span>( ret );
- }
- IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::extReleaseBus</span>( <span class="enscript-type">void</span> )
- {
- IOReturn ret = kIOReturnNotReady;
- IOI2CInterface * provider;
- <span class="enscript-keyword">if</span>( (provider = (IOI2CInterface *) copyParentEntry(gIOServicePlane))) {
- provider->close( <span class="enscript-keyword">this</span> );
- provider->release();
- ret = kIOReturnSuccess;
- }
- <span class="enscript-keyword">return</span>( ret );
- }
- IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::extIO</span>(
- <span class="enscript-type">void</span> * inStruct, <span class="enscript-type">void</span> * outStruct,
- IOByteCount inSize, IOByteCount * outSize )
- {
- IOReturn err = kIOReturnNotReady;
- IOI2CInterface * provider;
- IOI2CRequest * request;
- IOI2CBuffer * buffer;
- <span class="enscript-keyword">if</span>( inSize < <span class="enscript-keyword">sizeof</span>(IOI2CRequest))
- <span class="enscript-keyword">return</span>( kIOReturnNoSpace );
- <span class="enscript-keyword">if</span>( *outSize < inSize)
- <span class="enscript-keyword">return</span>( kIOReturnNoSpace );
- <span class="enscript-keyword">if</span>( (provider = (IOI2CInterface *) copyParentEntry(gIOServicePlane))) <span class="enscript-keyword">do</span> {
- <span class="enscript-keyword">if</span>( !provider->isOpen( <span class="enscript-keyword">this</span>)) {
- err = kIOReturnNotOpen;
- <span class="enscript-keyword">continue</span>;
- }
- buffer = (IOI2CBuffer *) inStruct;
- request = &buffer->request;
- <span class="enscript-keyword">if</span>( request->sendBytes) {
- <span class="enscript-keyword">if</span>( !request->sendBuffer)
- request->sendBuffer = (vm_address_t) &buffer->inlineBuffer[0];
- <span class="enscript-keyword">else</span> {
- err = kIOReturnMessageTooLarge;
- <span class="enscript-keyword">continue</span>;
- }
- }
- <span class="enscript-keyword">if</span>( request->replyBytes) {
- <span class="enscript-keyword">if</span>( !request->replyBuffer)
- request->replyBuffer = (vm_address_t) &buffer->inlineBuffer[0];
- <span class="enscript-keyword">else</span> {
- err = kIOReturnMessageTooLarge;
- <span class="enscript-keyword">continue</span>;
- }
- }
- err = provider->startIO( &buffer->request );
- } <span class="enscript-keyword">while</span>( false );
- <span class="enscript-keyword">if</span>( provider)
- provider->release();
- <span class="enscript-keyword">if</span>( kIOReturnSuccess == err) {
- *outSize = inSize;
- bcopy(inStruct, outStruct, inSize);
- } <span class="enscript-keyword">else</span>
- *outSize = 0;
- <span class="enscript-keyword">return</span>( err );
- }
- </pre>
- <hr />
- </body></html>