PageRenderTime 65ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>IOI2CInterface.cpp</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">IOI2CInterface.cpp&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. <span class="enscript-comment">/*
  24. * IOI2CInterface.cpp
  25. */</span>
  26. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;IOKit/IOLib.h&gt;</span>
  27. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;IOKit/IOUserClient.h&gt;</span>
  28. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;IOKit/IOLocks.h&gt;</span>
  29. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;IOKit/pwr_mgt/RootDomain.h&gt;</span>
  30. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;IOKit/ndrvsupport/IONDRVFramebuffer.h&gt;</span>
  31. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;IOKit/assert.h&gt;</span>
  32. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;libkern/c++/OSContainers.h&gt;</span>
  33. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;IOKit/i2c/IOI2CInterfacePrivate.h&gt;</span>
  34. <span class="enscript-comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span>
  35. #<span class="enscript-reference">undef</span> <span class="enscript-variable-name">super</span>
  36. #<span class="enscript-reference">define</span> <span class="enscript-variable-name">super</span> IOService
  37. <span class="enscript-function-name">OSDefineMetaClassAndAbstractStructors</span>(IOI2CInterface, IOService)
  38. <span class="enscript-comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span>
  39. <span class="enscript-type">bool</span> <span class="enscript-function-name">IOI2CInterface::registerI2C</span>( UInt64 id )
  40. {
  41. <span class="enscript-type">bool</span> result = true;
  42. fID = id;
  43. setProperty(kIOI2CInterfaceIDKey, id, 64);
  44. registerService();
  45. <span class="enscript-keyword">return</span>( result );
  46. }
  47. IOReturn <span class="enscript-function-name">IOI2CInterface::newUserClient</span>( task_t owningTask,
  48. <span class="enscript-type">void</span> * security_id,
  49. UInt32 type,
  50. IOUserClient ** handler )
  51. {
  52. IOReturn err = kIOReturnSuccess;
  53. IOUserClient * newConnect = 0;
  54. <span class="enscript-keyword">if</span>( type)
  55. <span class="enscript-keyword">return</span>( kIOReturnBadArgument );
  56. newConnect = IOI2CInterfaceUserClient::withTask(owningTask);
  57. <span class="enscript-keyword">if</span>( newConnect) {
  58. <span class="enscript-keyword">if</span>( !newConnect-&gt;attach( <span class="enscript-keyword">this</span> )
  59. || !newConnect-&gt;start( <span class="enscript-keyword">this</span> )) {
  60. newConnect-&gt;detach( <span class="enscript-keyword">this</span> );
  61. newConnect-&gt;release();
  62. newConnect = 0;
  63. }
  64. }
  65. *handler = newConnect;
  66. <span class="enscript-keyword">return</span>( err );
  67. }
  68. <span class="enscript-comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span>
  69. #<span class="enscript-reference">undef</span> <span class="enscript-variable-name">super</span>
  70. #<span class="enscript-reference">define</span> <span class="enscript-variable-name">super</span> IOUserClient
  71. <span class="enscript-function-name">OSDefineMetaClassAndStructors</span>(IOI2CInterfaceUserClient, IOUserClient)
  72. <span class="enscript-comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span>
  73. IOI2CInterfaceUserClient * <span class="enscript-function-name">IOI2CInterfaceUserClient::withTask</span>( task_t owningTask )
  74. {
  75. IOI2CInterfaceUserClient * inst;
  76. inst = <span class="enscript-keyword">new</span> IOI2CInterfaceUserClient;
  77. <span class="enscript-keyword">if</span>( inst &amp;&amp; !inst-&gt;init()) {
  78. inst-&gt;release();
  79. inst = 0;
  80. }
  81. <span class="enscript-keyword">if</span>( inst)
  82. inst-&gt;fTask = owningTask;
  83. <span class="enscript-keyword">return</span>( inst );
  84. }
  85. <span class="enscript-type">bool</span> <span class="enscript-function-name">IOI2CInterfaceUserClient::start</span>( IOService * provider )
  86. {
  87. <span class="enscript-keyword">if</span>( !super::start( provider ))
  88. <span class="enscript-keyword">return</span>( false );
  89. <span class="enscript-keyword">return</span>( true );
  90. }
  91. IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::clientClose</span>( <span class="enscript-type">void</span> )
  92. {
  93. terminate();
  94. <span class="enscript-keyword">return</span>( kIOReturnSuccess );
  95. }
  96. IOService * <span class="enscript-function-name">IOI2CInterfaceUserClient::getService</span>( <span class="enscript-type">void</span> )
  97. {
  98. <span class="enscript-keyword">return</span>( getProvider() );
  99. }
  100. IOExternalMethod * <span class="enscript-function-name">IOI2CInterfaceUserClient::getTargetAndMethodForIndex</span>(
  101. IOService ** targetP, UInt32 index )
  102. {
  103. <span class="enscript-type">static</span> <span class="enscript-type">const</span> IOExternalMethod methodTemplate[] = {
  104. <span class="enscript-comment">/* 0 */</span> { NULL, (IOMethod) &amp;IOI2CInterfaceUserClient::extAcquireBus,
  105. kIOUCScalarIScalarO, 0, 0 },
  106. <span class="enscript-comment">/* 1 */</span> { NULL, (IOMethod) &amp;IOI2CInterfaceUserClient::extReleaseBus,
  107. kIOUCScalarIScalarO, 0, 0 },
  108. <span class="enscript-comment">/* 3 */</span> { NULL, (IOMethod) &amp;IOI2CInterfaceUserClient::extIO,
  109. kIOUCStructIStructO, 0xffffffff, 0xffffffff },
  110. };
  111. <span class="enscript-keyword">if</span>( index &gt; (<span class="enscript-keyword">sizeof</span>(methodTemplate) / <span class="enscript-keyword">sizeof</span>(methodTemplate[0])))
  112. <span class="enscript-keyword">return</span>( NULL );
  113. *targetP = <span class="enscript-keyword">this</span>;
  114. <span class="enscript-keyword">return</span>( (IOExternalMethod *)(methodTemplate + index) );
  115. }
  116. IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::setProperties</span>( OSObject * properties )
  117. {
  118. <span class="enscript-keyword">return</span>( kIOReturnUnsupported );
  119. }
  120. IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::extAcquireBus</span>( <span class="enscript-type">void</span> )
  121. {
  122. IOReturn ret = kIOReturnNotReady;
  123. IOI2CInterface * provider;
  124. <span class="enscript-keyword">if</span>( (provider = (IOI2CInterface *) copyParentEntry(gIOServicePlane))) {
  125. ret = provider-&gt;open( <span class="enscript-keyword">this</span> ) ? kIOReturnSuccess : kIOReturnBusy;
  126. provider-&gt;release();
  127. }
  128. <span class="enscript-keyword">return</span>( ret );
  129. }
  130. IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::extReleaseBus</span>( <span class="enscript-type">void</span> )
  131. {
  132. IOReturn ret = kIOReturnNotReady;
  133. IOI2CInterface * provider;
  134. <span class="enscript-keyword">if</span>( (provider = (IOI2CInterface *) copyParentEntry(gIOServicePlane))) {
  135. provider-&gt;close( <span class="enscript-keyword">this</span> );
  136. provider-&gt;release();
  137. ret = kIOReturnSuccess;
  138. }
  139. <span class="enscript-keyword">return</span>( ret );
  140. }
  141. IOReturn <span class="enscript-function-name">IOI2CInterfaceUserClient::extIO</span>(
  142. <span class="enscript-type">void</span> * inStruct, <span class="enscript-type">void</span> * outStruct,
  143. IOByteCount inSize, IOByteCount * outSize )
  144. {
  145. IOReturn err = kIOReturnNotReady;
  146. IOI2CInterface * provider;
  147. IOI2CRequest * request;
  148. IOI2CBuffer * buffer;
  149. <span class="enscript-keyword">if</span>( inSize &lt; <span class="enscript-keyword">sizeof</span>(IOI2CRequest))
  150. <span class="enscript-keyword">return</span>( kIOReturnNoSpace );
  151. <span class="enscript-keyword">if</span>( *outSize &lt; inSize)
  152. <span class="enscript-keyword">return</span>( kIOReturnNoSpace );
  153. <span class="enscript-keyword">if</span>( (provider = (IOI2CInterface *) copyParentEntry(gIOServicePlane))) <span class="enscript-keyword">do</span> {
  154. <span class="enscript-keyword">if</span>( !provider-&gt;isOpen( <span class="enscript-keyword">this</span>)) {
  155. err = kIOReturnNotOpen;
  156. <span class="enscript-keyword">continue</span>;
  157. }
  158. buffer = (IOI2CBuffer *) inStruct;
  159. request = &amp;buffer-&gt;request;
  160. <span class="enscript-keyword">if</span>( request-&gt;sendBytes) {
  161. <span class="enscript-keyword">if</span>( !request-&gt;sendBuffer)
  162. request-&gt;sendBuffer = (vm_address_t) &amp;buffer-&gt;inlineBuffer[0];
  163. <span class="enscript-keyword">else</span> {
  164. err = kIOReturnMessageTooLarge;
  165. <span class="enscript-keyword">continue</span>;
  166. }
  167. }
  168. <span class="enscript-keyword">if</span>( request-&gt;replyBytes) {
  169. <span class="enscript-keyword">if</span>( !request-&gt;replyBuffer)
  170. request-&gt;replyBuffer = (vm_address_t) &amp;buffer-&gt;inlineBuffer[0];
  171. <span class="enscript-keyword">else</span> {
  172. err = kIOReturnMessageTooLarge;
  173. <span class="enscript-keyword">continue</span>;
  174. }
  175. }
  176. err = provider-&gt;startIO( &amp;buffer-&gt;request );
  177. } <span class="enscript-keyword">while</span>( false );
  178. <span class="enscript-keyword">if</span>( provider)
  179. provider-&gt;release();
  180. <span class="enscript-keyword">if</span>( kIOReturnSuccess == err) {
  181. *outSize = inSize;
  182. bcopy(inStruct, outStruct, inSize);
  183. } <span class="enscript-keyword">else</span>
  184. *outSize = 0;
  185. <span class="enscript-keyword">return</span>( err );
  186. }
  187. </pre>
  188. <hr />
  189. </body></html>