IoHighLevel.c 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309
  1. /** @file
  2. High-level Io/Mmio functions.
  3. All assertions for bit field operations are handled bit field functions in the
  4. Base Library.
  5. Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. Module Name: IoHighLevel.c
  8. The following IoLib instances share the same version of this file:
  9. BaseIoLibIntrinsic
  10. DxeIoLibCpuIo
  11. PeiIoLibCpuIo
  12. **/
  13. #include "DxeCpuIoLibInternal.h"
  14. /**
  15. Reads an 8-bit I/O port, performs a bitwise OR, and writes the
  16. result back to the 8-bit I/O port.
  17. Reads the 8-bit I/O port specified by Port, performs a bitwise OR
  18. between the read result and the value specified by OrData, and writes the
  19. result to the 8-bit I/O port specified by Port. The value written to the I/O
  20. port is returned. This function must guarantee that all I/O read and write
  21. operations are serialized.
  22. If 8-bit I/O port operations are not supported, then ASSERT().
  23. @param Port The I/O port to write.
  24. @param OrData The value to OR with the read value from the I/O port.
  25. @return The value written back to the I/O port.
  26. **/
  27. UINT8
  28. EFIAPI
  29. IoOr8 (
  30. IN UINTN Port,
  31. IN UINT8 OrData
  32. )
  33. {
  34. return IoWrite8 (Port, (UINT8) (IoRead8 (Port) | OrData));
  35. }
  36. /**
  37. Reads an 8-bit I/O port, performs a bitwise AND, and writes the result back
  38. to the 8-bit I/O port.
  39. Reads the 8-bit I/O port specified by Port, performs a bitwise AND between
  40. the read result and the value specified by AndData, and writes the result to
  41. the 8-bit I/O port specified by Port. The value written to the I/O port is
  42. returned. This function must guarantee that all I/O read and write operations
  43. are serialized.
  44. If 8-bit I/O port operations are not supported, then ASSERT().
  45. @param Port The I/O port to write.
  46. @param AndData The value to AND with the read value from the I/O port.
  47. @return The value written back to the I/O port.
  48. **/
  49. UINT8
  50. EFIAPI
  51. IoAnd8 (
  52. IN UINTN Port,
  53. IN UINT8 AndData
  54. )
  55. {
  56. return IoWrite8 (Port, (UINT8) (IoRead8 (Port) & AndData));
  57. }
  58. /**
  59. Reads an 8-bit I/O port, performs a bitwise AND followed by a bitwise
  60. inclusive OR, and writes the result back to the 8-bit I/O port.
  61. Reads the 8-bit I/O port specified by Port, performs a bitwise AND between
  62. the read result and the value specified by AndData, performs a bitwise OR
  63. between the result of the AND operation and the value specified by OrData,
  64. and writes the result to the 8-bit I/O port specified by Port. The value
  65. written to the I/O port is returned. This function must guarantee that all
  66. I/O read and write operations are serialized.
  67. If 8-bit I/O port operations are not supported, then ASSERT().
  68. @param Port The I/O port to write.
  69. @param AndData The value to AND with the read value from the I/O port.
  70. @param OrData The value to OR with the result of the AND operation.
  71. @return The value written back to the I/O port.
  72. **/
  73. UINT8
  74. EFIAPI
  75. IoAndThenOr8 (
  76. IN UINTN Port,
  77. IN UINT8 AndData,
  78. IN UINT8 OrData
  79. )
  80. {
  81. return IoWrite8 (Port, (UINT8) ((IoRead8 (Port) & AndData) | OrData));
  82. }
  83. /**
  84. Reads a bit field of an I/O register.
  85. Reads the bit field in an 8-bit I/O register. The bit field is specified by
  86. the StartBit and the EndBit. The value of the bit field is returned.
  87. If 8-bit I/O port operations are not supported, then ASSERT().
  88. If StartBit is greater than 7, then ASSERT().
  89. If EndBit is greater than 7, then ASSERT().
  90. If EndBit is less than StartBit, then ASSERT().
  91. @param Port The I/O port to read.
  92. @param StartBit The ordinal of the least significant bit in the bit field.
  93. Range 0..7.
  94. @param EndBit The ordinal of the most significant bit in the bit field.
  95. Range 0..7.
  96. @return The value read.
  97. **/
  98. UINT8
  99. EFIAPI
  100. IoBitFieldRead8 (
  101. IN UINTN Port,
  102. IN UINTN StartBit,
  103. IN UINTN EndBit
  104. )
  105. {
  106. return BitFieldRead8 (IoRead8 (Port), StartBit, EndBit);
  107. }
  108. /**
  109. Writes a bit field to an I/O register.
  110. Writes Value to the bit field of the I/O register. The bit field is specified
  111. by the StartBit and the EndBit. All other bits in the destination I/O
  112. register are preserved. The value written to the I/O port is returned. Extra
  113. left bits in Value are stripped.
  114. If 8-bit I/O port operations are not supported, then ASSERT().
  115. If StartBit is greater than 7, then ASSERT().
  116. If EndBit is greater than 7, then ASSERT().
  117. If EndBit is less than StartBit, then ASSERT().
  118. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  119. @param Port The I/O port to write.
  120. @param StartBit The ordinal of the least significant bit in the bit field.
  121. Range 0..7.
  122. @param EndBit The ordinal of the most significant bit in the bit field.
  123. Range 0..7.
  124. @param Value New value of the bit field.
  125. @return The value written back to the I/O port.
  126. **/
  127. UINT8
  128. EFIAPI
  129. IoBitFieldWrite8 (
  130. IN UINTN Port,
  131. IN UINTN StartBit,
  132. IN UINTN EndBit,
  133. IN UINT8 Value
  134. )
  135. {
  136. return IoWrite8 (
  137. Port,
  138. BitFieldWrite8 (IoRead8 (Port), StartBit, EndBit, Value)
  139. );
  140. }
  141. /**
  142. Reads a bit field in an 8-bit port, performs a bitwise OR, and writes the
  143. result back to the bit field in the 8-bit port.
  144. Reads the 8-bit I/O port specified by Port, performs a bitwise OR
  145. between the read result and the value specified by OrData, and writes the
  146. result to the 8-bit I/O port specified by Port. The value written to the I/O
  147. port is returned. This function must guarantee that all I/O read and write
  148. operations are serialized. Extra left bits in OrData are stripped.
  149. If 8-bit I/O port operations are not supported, then ASSERT().
  150. If StartBit is greater than 7, then ASSERT().
  151. If EndBit is greater than 7, then ASSERT().
  152. If EndBit is less than StartBit, then ASSERT().
  153. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  154. @param Port The I/O port to write.
  155. @param StartBit The ordinal of the least significant bit in the bit field.
  156. Range 0..7.
  157. @param EndBit The ordinal of the most significant bit in the bit field.
  158. Range 0..7.
  159. @param OrData The value to OR with the read value from the I/O port.
  160. @return The value written back to the I/O port.
  161. **/
  162. UINT8
  163. EFIAPI
  164. IoBitFieldOr8 (
  165. IN UINTN Port,
  166. IN UINTN StartBit,
  167. IN UINTN EndBit,
  168. IN UINT8 OrData
  169. )
  170. {
  171. return IoWrite8 (
  172. Port,
  173. BitFieldOr8 (IoRead8 (Port), StartBit, EndBit, OrData)
  174. );
  175. }
  176. /**
  177. Reads a bit field in an 8-bit port, performs a bitwise AND, and writes the
  178. result back to the bit field in the 8-bit port.
  179. Reads the 8-bit I/O port specified by Port, performs a bitwise AND between
  180. the read result and the value specified by AndData, and writes the result to
  181. the 8-bit I/O port specified by Port. The value written to the I/O port is
  182. returned. This function must guarantee that all I/O read and write operations
  183. are serialized. Extra left bits in AndData are stripped.
  184. If 8-bit I/O port operations are not supported, then ASSERT().
  185. If StartBit is greater than 7, then ASSERT().
  186. If EndBit is greater than 7, then ASSERT().
  187. If EndBit is less than StartBit, then ASSERT().
  188. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  189. @param Port The I/O port to write.
  190. @param StartBit The ordinal of the least significant bit in the bit field.
  191. Range 0..7.
  192. @param EndBit The ordinal of the most significant bit in the bit field.
  193. Range 0..7.
  194. @param AndData The value to AND with the read value from the I/O port.
  195. @return The value written back to the I/O port.
  196. **/
  197. UINT8
  198. EFIAPI
  199. IoBitFieldAnd8 (
  200. IN UINTN Port,
  201. IN UINTN StartBit,
  202. IN UINTN EndBit,
  203. IN UINT8 AndData
  204. )
  205. {
  206. return IoWrite8 (
  207. Port,
  208. BitFieldAnd8 (IoRead8 (Port), StartBit, EndBit, AndData)
  209. );
  210. }
  211. /**
  212. Reads a bit field in an 8-bit port, performs a bitwise AND followed by a
  213. bitwise OR, and writes the result back to the bit field in the
  214. 8-bit port.
  215. Reads the 8-bit I/O port specified by Port, performs a bitwise AND followed
  216. by a bitwise OR between the read result and the value specified by
  217. AndData, and writes the result to the 8-bit I/O port specified by Port. The
  218. value written to the I/O port is returned. This function must guarantee that
  219. all I/O read and write operations are serialized. Extra left bits in both
  220. AndData and OrData are stripped.
  221. If 8-bit I/O port operations are not supported, then ASSERT().
  222. If StartBit is greater than 7, then ASSERT().
  223. If EndBit is greater than 7, then ASSERT().
  224. If EndBit is less than StartBit, then ASSERT().
  225. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  226. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  227. @param Port The I/O port to write.
  228. @param StartBit The ordinal of the least significant bit in the bit field.
  229. Range 0..7.
  230. @param EndBit The ordinal of the most significant bit in the bit field.
  231. Range 0..7.
  232. @param AndData The value to AND with the read value from the I/O port.
  233. @param OrData The value to OR with the result of the AND operation.
  234. @return The value written back to the I/O port.
  235. **/
  236. UINT8
  237. EFIAPI
  238. IoBitFieldAndThenOr8 (
  239. IN UINTN Port,
  240. IN UINTN StartBit,
  241. IN UINTN EndBit,
  242. IN UINT8 AndData,
  243. IN UINT8 OrData
  244. )
  245. {
  246. return IoWrite8 (
  247. Port,
  248. BitFieldAndThenOr8 (IoRead8 (Port), StartBit, EndBit, AndData, OrData)
  249. );
  250. }
  251. /**
  252. Reads a 16-bit I/O port, performs a bitwise OR, and writes the
  253. result back to the 16-bit I/O port.
  254. Reads the 16-bit I/O port specified by Port, performs a bitwise OR
  255. between the read result and the value specified by OrData, and writes the
  256. result to the 16-bit I/O port specified by Port. The value written to the I/O
  257. port is returned. This function must guarantee that all I/O read and write
  258. operations are serialized.
  259. If 16-bit I/O port operations are not supported, then ASSERT().
  260. @param Port The I/O port to write.
  261. @param OrData The value to OR with the read value from the I/O port.
  262. @return The value written back to the I/O port.
  263. **/
  264. UINT16
  265. EFIAPI
  266. IoOr16 (
  267. IN UINTN Port,
  268. IN UINT16 OrData
  269. )
  270. {
  271. return IoWrite16 (Port, (UINT16) (IoRead16 (Port) | OrData));
  272. }
  273. /**
  274. Reads a 16-bit I/O port, performs a bitwise AND, and writes the result back
  275. to the 16-bit I/O port.
  276. Reads the 16-bit I/O port specified by Port, performs a bitwise AND between
  277. the read result and the value specified by AndData, and writes the result to
  278. the 16-bit I/O port specified by Port. The value written to the I/O port is
  279. returned. This function must guarantee that all I/O read and write operations
  280. are serialized.
  281. If 16-bit I/O port operations are not supported, then ASSERT().
  282. @param Port The I/O port to write.
  283. @param AndData The value to AND with the read value from the I/O port.
  284. @return The value written back to the I/O port.
  285. **/
  286. UINT16
  287. EFIAPI
  288. IoAnd16 (
  289. IN UINTN Port,
  290. IN UINT16 AndData
  291. )
  292. {
  293. return IoWrite16 (Port, (UINT16) (IoRead16 (Port) & AndData));
  294. }
  295. /**
  296. Reads a 16-bit I/O port, performs a bitwise AND followed by a bitwise
  297. inclusive OR, and writes the result back to the 16-bit I/O port.
  298. Reads the 16-bit I/O port specified by Port, performs a bitwise AND between
  299. the read result and the value specified by AndData, performs a bitwise OR
  300. between the result of the AND operation and the value specified by OrData,
  301. and writes the result to the 16-bit I/O port specified by Port. The value
  302. written to the I/O port is returned. This function must guarantee that all
  303. I/O read and write operations are serialized.
  304. If 16-bit I/O port operations are not supported, then ASSERT().
  305. @param Port The I/O port to write.
  306. @param AndData The value to AND with the read value from the I/O port.
  307. @param OrData The value to OR with the result of the AND operation.
  308. @return The value written back to the I/O port.
  309. **/
  310. UINT16
  311. EFIAPI
  312. IoAndThenOr16 (
  313. IN UINTN Port,
  314. IN UINT16 AndData,
  315. IN UINT16 OrData
  316. )
  317. {
  318. return IoWrite16 (Port, (UINT16) ((IoRead16 (Port) & AndData) | OrData));
  319. }
  320. /**
  321. Reads a bit field of an I/O register.
  322. Reads the bit field in a 16-bit I/O register. The bit field is specified by
  323. the StartBit and the EndBit. The value of the bit field is returned.
  324. If 16-bit I/O port operations are not supported, then ASSERT().
  325. If StartBit is greater than 15, then ASSERT().
  326. If EndBit is greater than 15, then ASSERT().
  327. If EndBit is less than StartBit, then ASSERT().
  328. @param Port The I/O port to read.
  329. @param StartBit The ordinal of the least significant bit in the bit field.
  330. Range 0..15.
  331. @param EndBit The ordinal of the most significant bit in the bit field.
  332. Range 0..15.
  333. @return The value read.
  334. **/
  335. UINT16
  336. EFIAPI
  337. IoBitFieldRead16 (
  338. IN UINTN Port,
  339. IN UINTN StartBit,
  340. IN UINTN EndBit
  341. )
  342. {
  343. return BitFieldRead16 (IoRead16 (Port), StartBit, EndBit);
  344. }
  345. /**
  346. Writes a bit field to an I/O register.
  347. Writes Value to the bit field of the I/O register. The bit field is specified
  348. by the StartBit and the EndBit. All other bits in the destination I/O
  349. register are preserved. The value written to the I/O port is returned. Extra
  350. left bits in Value are stripped.
  351. If 16-bit I/O port operations are not supported, then ASSERT().
  352. If StartBit is greater than 15, then ASSERT().
  353. If EndBit is greater than 15, then ASSERT().
  354. If EndBit is less than StartBit, then ASSERT().
  355. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  356. @param Port The I/O port to write.
  357. @param StartBit The ordinal of the least significant bit in the bit field.
  358. Range 0..15.
  359. @param EndBit The ordinal of the most significant bit in the bit field.
  360. Range 0..15.
  361. @param Value New value of the bit field.
  362. @return The value written back to the I/O port.
  363. **/
  364. UINT16
  365. EFIAPI
  366. IoBitFieldWrite16 (
  367. IN UINTN Port,
  368. IN UINTN StartBit,
  369. IN UINTN EndBit,
  370. IN UINT16 Value
  371. )
  372. {
  373. return IoWrite16 (
  374. Port,
  375. BitFieldWrite16 (IoRead16 (Port), StartBit, EndBit, Value)
  376. );
  377. }
  378. /**
  379. Reads a bit field in a 16-bit port, performs a bitwise OR, and writes the
  380. result back to the bit field in the 16-bit port.
  381. Reads the 16-bit I/O port specified by Port, performs a bitwise OR
  382. between the read result and the value specified by OrData, and writes the
  383. result to the 16-bit I/O port specified by Port. The value written to the I/O
  384. port is returned. This function must guarantee that all I/O read and write
  385. operations are serialized. Extra left bits in OrData are stripped.
  386. If 16-bit I/O port operations are not supported, then ASSERT().
  387. If StartBit is greater than 15, then ASSERT().
  388. If EndBit is greater than 15, then ASSERT().
  389. If EndBit is less than StartBit, then ASSERT().
  390. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  391. @param Port The I/O port to write.
  392. @param StartBit The ordinal of the least significant bit in the bit field.
  393. Range 0..15.
  394. @param EndBit The ordinal of the most significant bit in the bit field.
  395. Range 0..15.
  396. @param OrData The value to OR with the read value from the I/O port.
  397. @return The value written back to the I/O port.
  398. **/
  399. UINT16
  400. EFIAPI
  401. IoBitFieldOr16 (
  402. IN UINTN Port,
  403. IN UINTN StartBit,
  404. IN UINTN EndBit,
  405. IN UINT16 OrData
  406. )
  407. {
  408. return IoWrite16 (
  409. Port,
  410. BitFieldOr16 (IoRead16 (Port), StartBit, EndBit, OrData)
  411. );
  412. }
  413. /**
  414. Reads a bit field in a 16-bit port, performs a bitwise AND, and writes the
  415. result back to the bit field in the 16-bit port.
  416. Reads the 16-bit I/O port specified by Port, performs a bitwise AND between
  417. the read result and the value specified by AndData, and writes the result to
  418. the 16-bit I/O port specified by Port. The value written to the I/O port is
  419. returned. This function must guarantee that all I/O read and write operations
  420. are serialized. Extra left bits in AndData are stripped.
  421. If 16-bit I/O port operations are not supported, then ASSERT().
  422. If StartBit is greater than 15, then ASSERT().
  423. If EndBit is greater than 15, then ASSERT().
  424. If EndBit is less than StartBit, then ASSERT().
  425. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  426. @param Port The I/O port to write.
  427. @param StartBit The ordinal of the least significant bit in the bit field.
  428. Range 0..15.
  429. @param EndBit The ordinal of the most significant bit in the bit field.
  430. Range 0..15.
  431. @param AndData The value to AND with the read value from the I/O port.
  432. @return The value written back to the I/O port.
  433. **/
  434. UINT16
  435. EFIAPI
  436. IoBitFieldAnd16 (
  437. IN UINTN Port,
  438. IN UINTN StartBit,
  439. IN UINTN EndBit,
  440. IN UINT16 AndData
  441. )
  442. {
  443. return IoWrite16 (
  444. Port,
  445. BitFieldAnd16 (IoRead16 (Port), StartBit, EndBit, AndData)
  446. );
  447. }
  448. /**
  449. Reads a bit field in a 16-bit port, performs a bitwise AND followed by a
  450. bitwise OR, and writes the result back to the bit field in the
  451. 16-bit port.
  452. Reads the 16-bit I/O port specified by Port, performs a bitwise AND followed
  453. by a bitwise OR between the read result and the value specified by
  454. AndData, and writes the result to the 16-bit I/O port specified by Port. The
  455. value written to the I/O port is returned. This function must guarantee that
  456. all I/O read and write operations are serialized. Extra left bits in both
  457. AndData and OrData are stripped.
  458. If 16-bit I/O port operations are not supported, then ASSERT().
  459. If StartBit is greater than 15, then ASSERT().
  460. If EndBit is greater than 15, then ASSERT().
  461. If EndBit is less than StartBit, then ASSERT().
  462. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  463. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  464. @param Port The I/O port to write.
  465. @param StartBit The ordinal of the least significant bit in the bit field.
  466. Range 0..15.
  467. @param EndBit The ordinal of the most significant bit in the bit field.
  468. Range 0..15.
  469. @param AndData The value to AND with the read value from the I/O port.
  470. @param OrData The value to OR with the result of the AND operation.
  471. @return The value written back to the I/O port.
  472. **/
  473. UINT16
  474. EFIAPI
  475. IoBitFieldAndThenOr16 (
  476. IN UINTN Port,
  477. IN UINTN StartBit,
  478. IN UINTN EndBit,
  479. IN UINT16 AndData,
  480. IN UINT16 OrData
  481. )
  482. {
  483. return IoWrite16 (
  484. Port,
  485. BitFieldAndThenOr16 (IoRead16 (Port), StartBit, EndBit, AndData, OrData)
  486. );
  487. }
  488. /**
  489. Reads a 32-bit I/O port, performs a bitwise OR, and writes the
  490. result back to the 32-bit I/O port.
  491. Reads the 32-bit I/O port specified by Port, performs a bitwise OR
  492. between the read result and the value specified by OrData, and writes the
  493. result to the 32-bit I/O port specified by Port. The value written to the I/O
  494. port is returned. This function must guarantee that all I/O read and write
  495. operations are serialized.
  496. If 32-bit I/O port operations are not supported, then ASSERT().
  497. @param Port The I/O port to write.
  498. @param OrData The value to OR with the read value from the I/O port.
  499. @return The value written back to the I/O port.
  500. **/
  501. UINT32
  502. EFIAPI
  503. IoOr32 (
  504. IN UINTN Port,
  505. IN UINT32 OrData
  506. )
  507. {
  508. return IoWrite32 (Port, IoRead32 (Port) | OrData);
  509. }
  510. /**
  511. Reads a 32-bit I/O port, performs a bitwise AND, and writes the result back
  512. to the 32-bit I/O port.
  513. Reads the 32-bit I/O port specified by Port, performs a bitwise AND between
  514. the read result and the value specified by AndData, and writes the result to
  515. the 32-bit I/O port specified by Port. The value written to the I/O port is
  516. returned. This function must guarantee that all I/O read and write operations
  517. are serialized.
  518. If 32-bit I/O port operations are not supported, then ASSERT().
  519. @param Port The I/O port to write.
  520. @param AndData The value to AND with the read value from the I/O port.
  521. @return The value written back to the I/O port.
  522. **/
  523. UINT32
  524. EFIAPI
  525. IoAnd32 (
  526. IN UINTN Port,
  527. IN UINT32 AndData
  528. )
  529. {
  530. return IoWrite32 (Port, IoRead32 (Port) & AndData);
  531. }
  532. /**
  533. Reads a 32-bit I/O port, performs a bitwise AND followed by a bitwise
  534. inclusive OR, and writes the result back to the 32-bit I/O port.
  535. Reads the 32-bit I/O port specified by Port, performs a bitwise AND between
  536. the read result and the value specified by AndData, performs a bitwise OR
  537. between the result of the AND operation and the value specified by OrData,
  538. and writes the result to the 32-bit I/O port specified by Port. The value
  539. written to the I/O port is returned. This function must guarantee that all
  540. I/O read and write operations are serialized.
  541. If 32-bit I/O port operations are not supported, then ASSERT().
  542. @param Port The I/O port to write.
  543. @param AndData The value to AND with the read value from the I/O port.
  544. @param OrData The value to OR with the result of the AND operation.
  545. @return The value written back to the I/O port.
  546. **/
  547. UINT32
  548. EFIAPI
  549. IoAndThenOr32 (
  550. IN UINTN Port,
  551. IN UINT32 AndData,
  552. IN UINT32 OrData
  553. )
  554. {
  555. return IoWrite32 (Port, (IoRead32 (Port) & AndData) | OrData);
  556. }
  557. /**
  558. Reads a bit field of an I/O register.
  559. Reads the bit field in a 32-bit I/O register. The bit field is specified by
  560. the StartBit and the EndBit. The value of the bit field is returned.
  561. If 32-bit I/O port operations are not supported, then ASSERT().
  562. If StartBit is greater than 31, then ASSERT().
  563. If EndBit is greater than 31, then ASSERT().
  564. If EndBit is less than StartBit, then ASSERT().
  565. @param Port The I/O port to read.
  566. @param StartBit The ordinal of the least significant bit in the bit field.
  567. Range 0..31.
  568. @param EndBit The ordinal of the most significant bit in the bit field.
  569. Range 0..31.
  570. @return The value read.
  571. **/
  572. UINT32
  573. EFIAPI
  574. IoBitFieldRead32 (
  575. IN UINTN Port,
  576. IN UINTN StartBit,
  577. IN UINTN EndBit
  578. )
  579. {
  580. return BitFieldRead32 (IoRead32 (Port), StartBit, EndBit);
  581. }
  582. /**
  583. Writes a bit field to an I/O register.
  584. Writes Value to the bit field of the I/O register. The bit field is specified
  585. by the StartBit and the EndBit. All other bits in the destination I/O
  586. register are preserved. The value written to the I/O port is returned. Extra
  587. left bits in Value are stripped.
  588. If 32-bit I/O port operations are not supported, then ASSERT().
  589. If StartBit is greater than 31, then ASSERT().
  590. If EndBit is greater than 31, then ASSERT().
  591. If EndBit is less than StartBit, then ASSERT().
  592. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  593. @param Port The I/O port to write.
  594. @param StartBit The ordinal of the least significant bit in the bit field.
  595. Range 0..31.
  596. @param EndBit The ordinal of the most significant bit in the bit field.
  597. Range 0..31.
  598. @param Value New value of the bit field.
  599. @return The value written back to the I/O port.
  600. **/
  601. UINT32
  602. EFIAPI
  603. IoBitFieldWrite32 (
  604. IN UINTN Port,
  605. IN UINTN StartBit,
  606. IN UINTN EndBit,
  607. IN UINT32 Value
  608. )
  609. {
  610. return IoWrite32 (
  611. Port,
  612. BitFieldWrite32 (IoRead32 (Port), StartBit, EndBit, Value)
  613. );
  614. }
  615. /**
  616. Reads a bit field in a 32-bit port, performs a bitwise OR, and writes the
  617. result back to the bit field in the 32-bit port.
  618. Reads the 32-bit I/O port specified by Port, performs a bitwise OR
  619. between the read result and the value specified by OrData, and writes the
  620. result to the 32-bit I/O port specified by Port. The value written to the I/O
  621. port is returned. This function must guarantee that all I/O read and write
  622. operations are serialized. Extra left bits in OrData are stripped.
  623. If 32-bit I/O port operations are not supported, then ASSERT().
  624. If StartBit is greater than 31, then ASSERT().
  625. If EndBit is greater than 31, then ASSERT().
  626. If EndBit is less than StartBit, then ASSERT().
  627. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  628. @param Port The I/O port to write.
  629. @param StartBit The ordinal of the least significant bit in the bit field.
  630. Range 0..31.
  631. @param EndBit The ordinal of the most significant bit in the bit field.
  632. Range 0..31.
  633. @param OrData The value to OR with the read value from the I/O port.
  634. @return The value written back to the I/O port.
  635. **/
  636. UINT32
  637. EFIAPI
  638. IoBitFieldOr32 (
  639. IN UINTN Port,
  640. IN UINTN StartBit,
  641. IN UINTN EndBit,
  642. IN UINT32 OrData
  643. )
  644. {
  645. return IoWrite32 (
  646. Port,
  647. BitFieldOr32 (IoRead32 (Port), StartBit, EndBit, OrData)
  648. );
  649. }
  650. /**
  651. Reads a bit field in a 32-bit port, performs a bitwise AND, and writes the
  652. result back to the bit field in the 32-bit port.
  653. Reads the 32-bit I/O port specified by Port, performs a bitwise AND between
  654. the read result and the value specified by AndData, and writes the result to
  655. the 32-bit I/O port specified by Port. The value written to the I/O port is
  656. returned. This function must guarantee that all I/O read and write operations
  657. are serialized. Extra left bits in AndData are stripped.
  658. If 32-bit I/O port operations are not supported, then ASSERT().
  659. If StartBit is greater than 31, then ASSERT().
  660. If EndBit is greater than 31, then ASSERT().
  661. If EndBit is less than StartBit, then ASSERT().
  662. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  663. @param Port The I/O port to write.
  664. @param StartBit The ordinal of the least significant bit in the bit field.
  665. Range 0..31.
  666. @param EndBit The ordinal of the most significant bit in the bit field.
  667. Range 0..31.
  668. @param AndData The value to AND with the read value from the I/O port.
  669. @return The value written back to the I/O port.
  670. **/
  671. UINT32
  672. EFIAPI
  673. IoBitFieldAnd32 (
  674. IN UINTN Port,
  675. IN UINTN StartBit,
  676. IN UINTN EndBit,
  677. IN UINT32 AndData
  678. )
  679. {
  680. return IoWrite32 (
  681. Port,
  682. BitFieldAnd32 (IoRead32 (Port), StartBit, EndBit, AndData)
  683. );
  684. }
  685. /**
  686. Reads a bit field in a 32-bit port, performs a bitwise AND followed by a
  687. bitwise OR, and writes the result back to the bit field in the
  688. 32-bit port.
  689. Reads the 32-bit I/O port specified by Port, performs a bitwise AND followed
  690. by a bitwise OR between the read result and the value specified by
  691. AndData, and writes the result to the 32-bit I/O port specified by Port. The
  692. value written to the I/O port is returned. This function must guarantee that
  693. all I/O read and write operations are serialized. Extra left bits in both
  694. AndData and OrData are stripped.
  695. If 32-bit I/O port operations are not supported, then ASSERT().
  696. If StartBit is greater than 31, then ASSERT().
  697. If EndBit is greater than 31, then ASSERT().
  698. If EndBit is less than StartBit, then ASSERT().
  699. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  700. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  701. @param Port The I/O port to write.
  702. @param StartBit The ordinal of the least significant bit in the bit field.
  703. Range 0..31.
  704. @param EndBit The ordinal of the most significant bit in the bit field.
  705. Range 0..31.
  706. @param AndData The value to AND with the read value from the I/O port.
  707. @param OrData The value to OR with the result of the AND operation.
  708. @return The value written back to the I/O port.
  709. **/
  710. UINT32
  711. EFIAPI
  712. IoBitFieldAndThenOr32 (
  713. IN UINTN Port,
  714. IN UINTN StartBit,
  715. IN UINTN EndBit,
  716. IN UINT32 AndData,
  717. IN UINT32 OrData
  718. )
  719. {
  720. return IoWrite32 (
  721. Port,
  722. BitFieldAndThenOr32 (IoRead32 (Port), StartBit, EndBit, AndData, OrData)
  723. );
  724. }
  725. /**
  726. Reads a 64-bit I/O port, performs a bitwise OR, and writes the
  727. result back to the 64-bit I/O port.
  728. Reads the 64-bit I/O port specified by Port, performs a bitwise OR
  729. between the read result and the value specified by OrData, and writes the
  730. result to the 64-bit I/O port specified by Port. The value written to the I/O
  731. port is returned. This function must guarantee that all I/O read and write
  732. operations are serialized.
  733. If 64-bit I/O port operations are not supported, then ASSERT().
  734. @param Port The I/O port to write.
  735. @param OrData The value to OR with the read value from the I/O port.
  736. @return The value written back to the I/O port.
  737. **/
  738. UINT64
  739. EFIAPI
  740. IoOr64 (
  741. IN UINTN Port,
  742. IN UINT64 OrData
  743. )
  744. {
  745. return IoWrite64 (Port, IoRead64 (Port) | OrData);
  746. }
  747. /**
  748. Reads a 64-bit I/O port, performs a bitwise AND, and writes the result back
  749. to the 64-bit I/O port.
  750. Reads the 64-bit I/O port specified by Port, performs a bitwise AND between
  751. the read result and the value specified by AndData, and writes the result to
  752. the 64-bit I/O port specified by Port. The value written to the I/O port is
  753. returned. This function must guarantee that all I/O read and write operations
  754. are serialized.
  755. If 64-bit I/O port operations are not supported, then ASSERT().
  756. @param Port The I/O port to write.
  757. @param AndData The value to AND with the read value from the I/O port.
  758. @return The value written back to the I/O port.
  759. **/
  760. UINT64
  761. EFIAPI
  762. IoAnd64 (
  763. IN UINTN Port,
  764. IN UINT64 AndData
  765. )
  766. {
  767. return IoWrite64 (Port, IoRead64 (Port) & AndData);
  768. }
  769. /**
  770. Reads a 64-bit I/O port, performs a bitwise AND followed by a bitwise
  771. inclusive OR, and writes the result back to the 64-bit I/O port.
  772. Reads the 64-bit I/O port specified by Port, performs a bitwise AND between
  773. the read result and the value specified by AndData, performs a bitwise OR
  774. between the result of the AND operation and the value specified by OrData,
  775. and writes the result to the 64-bit I/O port specified by Port. The value
  776. written to the I/O port is returned. This function must guarantee that all
  777. I/O read and write operations are serialized.
  778. If 64-bit I/O port operations are not supported, then ASSERT().
  779. @param Port The I/O port to write.
  780. @param AndData The value to AND with the read value from the I/O port.
  781. @param OrData The value to OR with the result of the AND operation.
  782. @return The value written back to the I/O port.
  783. **/
  784. UINT64
  785. EFIAPI
  786. IoAndThenOr64 (
  787. IN UINTN Port,
  788. IN UINT64 AndData,
  789. IN UINT64 OrData
  790. )
  791. {
  792. return IoWrite64 (Port, (IoRead64 (Port) & AndData) | OrData);
  793. }
  794. /**
  795. Reads a bit field of an I/O register.
  796. Reads the bit field in a 64-bit I/O register. The bit field is specified by
  797. the StartBit and the EndBit. The value of the bit field is returned.
  798. If 64-bit I/O port operations are not supported, then ASSERT().
  799. If StartBit is greater than 63, then ASSERT().
  800. If EndBit is greater than 63, then ASSERT().
  801. If EndBit is less than StartBit, then ASSERT().
  802. @param Port The I/O port to read.
  803. @param StartBit The ordinal of the least significant bit in the bit field.
  804. Range 0..63.
  805. @param EndBit The ordinal of the most significant bit in the bit field.
  806. Range 0..63.
  807. @return The value read.
  808. **/
  809. UINT64
  810. EFIAPI
  811. IoBitFieldRead64 (
  812. IN UINTN Port,
  813. IN UINTN StartBit,
  814. IN UINTN EndBit
  815. )
  816. {
  817. return BitFieldRead64 (IoRead64 (Port), StartBit, EndBit);
  818. }
  819. /**
  820. Writes a bit field to an I/O register.
  821. Writes Value to the bit field of the I/O register. The bit field is specified
  822. by the StartBit and the EndBit. All other bits in the destination I/O
  823. register are preserved. The value written to the I/O port is returned. Extra
  824. left bits in Value are stripped.
  825. If 64-bit I/O port operations are not supported, then ASSERT().
  826. If StartBit is greater than 63, then ASSERT().
  827. If EndBit is greater than 63, then ASSERT().
  828. If EndBit is less than StartBit, then ASSERT().
  829. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  830. @param Port The I/O port to write.
  831. @param StartBit The ordinal of the least significant bit in the bit field.
  832. Range 0..63.
  833. @param EndBit The ordinal of the most significant bit in the bit field.
  834. Range 0..63.
  835. @param Value New value of the bit field.
  836. @return The value written back to the I/O port.
  837. **/
  838. UINT64
  839. EFIAPI
  840. IoBitFieldWrite64 (
  841. IN UINTN Port,
  842. IN UINTN StartBit,
  843. IN UINTN EndBit,
  844. IN UINT64 Value
  845. )
  846. {
  847. return IoWrite64 (
  848. Port,
  849. BitFieldWrite64 (IoRead64 (Port), StartBit, EndBit, Value)
  850. );
  851. }
  852. /**
  853. Reads a bit field in a 64-bit port, performs a bitwise OR, and writes the
  854. result back to the bit field in the 64-bit port.
  855. Reads the 64-bit I/O port specified by Port, performs a bitwise OR
  856. between the read result and the value specified by OrData, and writes the
  857. result to the 64-bit I/O port specified by Port. The value written to the I/O
  858. port is returned. This function must guarantee that all I/O read and write
  859. operations are serialized. Extra left bits in OrData are stripped.
  860. If 64-bit I/O port operations are not supported, then ASSERT().
  861. If StartBit is greater than 63, then ASSERT().
  862. If EndBit is greater than 63, then ASSERT().
  863. If EndBit is less than StartBit, then ASSERT().
  864. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  865. @param Port The I/O port to write.
  866. @param StartBit The ordinal of the least significant bit in the bit field.
  867. Range 0..63.
  868. @param EndBit The ordinal of the most significant bit in the bit field.
  869. Range 0..63.
  870. @param OrData The value to OR with the read value from the I/O port.
  871. @return The value written back to the I/O port.
  872. **/
  873. UINT64
  874. EFIAPI
  875. IoBitFieldOr64 (
  876. IN UINTN Port,
  877. IN UINTN StartBit,
  878. IN UINTN EndBit,
  879. IN UINT64 OrData
  880. )
  881. {
  882. return IoWrite64 (
  883. Port,
  884. BitFieldOr64 (IoRead64 (Port), StartBit, EndBit, OrData)
  885. );
  886. }
  887. /**
  888. Reads a bit field in a 64-bit port, performs a bitwise AND, and writes the
  889. result back to the bit field in the 64-bit port.
  890. Reads the 64-bit I/O port specified by Port, performs a bitwise AND between
  891. the read result and the value specified by AndData, and writes the result to
  892. the 64-bit I/O port specified by Port. The value written to the I/O port is
  893. returned. This function must guarantee that all I/O read and write operations
  894. are serialized. Extra left bits in AndData are stripped.
  895. If 64-bit I/O port operations are not supported, then ASSERT().
  896. If StartBit is greater than 63, then ASSERT().
  897. If EndBit is greater than 63, then ASSERT().
  898. If EndBit is less than StartBit, then ASSERT().
  899. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  900. @param Port The I/O port to write.
  901. @param StartBit The ordinal of the least significant bit in the bit field.
  902. Range 0..63.
  903. @param EndBit The ordinal of the most significant bit in the bit field.
  904. Range 0..63.
  905. @param AndData The value to AND with the read value from the I/O port.
  906. @return The value written back to the I/O port.
  907. **/
  908. UINT64
  909. EFIAPI
  910. IoBitFieldAnd64 (
  911. IN UINTN Port,
  912. IN UINTN StartBit,
  913. IN UINTN EndBit,
  914. IN UINT64 AndData
  915. )
  916. {
  917. return IoWrite64 (
  918. Port,
  919. BitFieldAnd64 (IoRead64 (Port), StartBit, EndBit, AndData)
  920. );
  921. }
  922. /**
  923. Reads a bit field in a 64-bit port, performs a bitwise AND followed by a
  924. bitwise OR, and writes the result back to the bit field in the
  925. 64-bit port.
  926. Reads the 64-bit I/O port specified by Port, performs a bitwise AND followed
  927. by a bitwise OR between the read result and the value specified by
  928. AndData, and writes the result to the 64-bit I/O port specified by Port. The
  929. value written to the I/O port is returned. This function must guarantee that
  930. all I/O read and write operations are serialized. Extra left bits in both
  931. AndData and OrData are stripped.
  932. If 64-bit I/O port operations are not supported, then ASSERT().
  933. If StartBit is greater than 63, then ASSERT().
  934. If EndBit is greater than 63, then ASSERT().
  935. If EndBit is less than StartBit, then ASSERT().
  936. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  937. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  938. @param Port The I/O port to write.
  939. @param StartBit The ordinal of the least significant bit in the bit field.
  940. Range 0..63.
  941. @param EndBit The ordinal of the most significant bit in the bit field.
  942. Range 0..63.
  943. @param AndData The value to AND with the read value from the I/O port.
  944. @param OrData The value to OR with the result of the AND operation.
  945. @return The value written back to the I/O port.
  946. **/
  947. UINT64
  948. EFIAPI
  949. IoBitFieldAndThenOr64 (
  950. IN UINTN Port,
  951. IN UINTN StartBit,
  952. IN UINTN EndBit,
  953. IN UINT64 AndData,
  954. IN UINT64 OrData
  955. )
  956. {
  957. return IoWrite64 (
  958. Port,
  959. BitFieldAndThenOr64 (IoRead64 (Port), StartBit, EndBit, AndData, OrData)
  960. );
  961. }
  962. /**
  963. Reads an 8-bit MMIO register, performs a bitwise OR, and writes the
  964. result back to the 8-bit MMIO register.
  965. Reads the 8-bit MMIO register specified by Address, performs a bitwise
  966. inclusive OR between the read result and the value specified by OrData, and
  967. writes the result to the 8-bit MMIO register specified by Address. The value
  968. written to the MMIO register is returned. This function must guarantee that
  969. all MMIO read and write operations are serialized.
  970. If 8-bit MMIO register operations are not supported, then ASSERT().
  971. @param Address The MMIO register to write.
  972. @param OrData The value to OR with the read value from the MMIO register.
  973. @return The value written back to the MMIO register.
  974. **/
  975. UINT8
  976. EFIAPI
  977. MmioOr8 (
  978. IN UINTN Address,
  979. IN UINT8 OrData
  980. )
  981. {
  982. return MmioWrite8 (Address, (UINT8) (MmioRead8 (Address) | OrData));
  983. }
  984. /**
  985. Reads an 8-bit MMIO register, performs a bitwise AND, and writes the result
  986. back to the 8-bit MMIO register.
  987. Reads the 8-bit MMIO register specified by Address, performs a bitwise AND
  988. between the read result and the value specified by AndData, and writes the
  989. result to the 8-bit MMIO register specified by Address. The value written to
  990. the MMIO register is returned. This function must guarantee that all MMIO
  991. read and write operations are serialized.
  992. If 8-bit MMIO register operations are not supported, then ASSERT().
  993. @param Address The MMIO register to write.
  994. @param AndData The value to AND with the read value from the MMIO register.
  995. @return The value written back to the MMIO register.
  996. **/
  997. UINT8
  998. EFIAPI
  999. MmioAnd8 (
  1000. IN UINTN Address,
  1001. IN UINT8 AndData
  1002. )
  1003. {
  1004. return MmioWrite8 (Address, (UINT8) (MmioRead8 (Address) & AndData));
  1005. }
  1006. /**
  1007. Reads an 8-bit MMIO register, performs a bitwise AND followed by a bitwise
  1008. inclusive OR, and writes the result back to the 8-bit MMIO register.
  1009. Reads the 8-bit MMIO register specified by Address, performs a bitwise AND
  1010. between the read result and the value specified by AndData, performs a
  1011. bitwise OR between the result of the AND operation and the value specified by
  1012. OrData, and writes the result to the 8-bit MMIO register specified by
  1013. Address. The value written to the MMIO register is returned. This function
  1014. must guarantee that all MMIO read and write operations are serialized.
  1015. If 8-bit MMIO register operations are not supported, then ASSERT().
  1016. @param Address The MMIO register to write.
  1017. @param AndData The value to AND with the read value from the MMIO register.
  1018. @param OrData The value to OR with the result of the AND operation.
  1019. @return The value written back to the MMIO register.
  1020. **/
  1021. UINT8
  1022. EFIAPI
  1023. MmioAndThenOr8 (
  1024. IN UINTN Address,
  1025. IN UINT8 AndData,
  1026. IN UINT8 OrData
  1027. )
  1028. {
  1029. return MmioWrite8 (Address, (UINT8) ((MmioRead8 (Address) & AndData) | OrData));
  1030. }
  1031. /**
  1032. Reads a bit field of a MMIO register.
  1033. Reads the bit field in an 8-bit MMIO register. The bit field is specified by
  1034. the StartBit and the EndBit. The value of the bit field is returned.
  1035. If 8-bit MMIO register operations are not supported, then ASSERT().
  1036. If StartBit is greater than 7, then ASSERT().
  1037. If EndBit is greater than 7, then ASSERT().
  1038. If EndBit is less than StartBit, then ASSERT().
  1039. @param Address MMIO register to read.
  1040. @param StartBit The ordinal of the least significant bit in the bit field.
  1041. Range 0..7.
  1042. @param EndBit The ordinal of the most significant bit in the bit field.
  1043. Range 0..7.
  1044. @return The value read.
  1045. **/
  1046. UINT8
  1047. EFIAPI
  1048. MmioBitFieldRead8 (
  1049. IN UINTN Address,
  1050. IN UINTN StartBit,
  1051. IN UINTN EndBit
  1052. )
  1053. {
  1054. return BitFieldRead8 (MmioRead8 (Address), StartBit, EndBit);
  1055. }
  1056. /**
  1057. Writes a bit field to a MMIO register.
  1058. Writes Value to the bit field of the MMIO register. The bit field is
  1059. specified by the StartBit and the EndBit. All other bits in the destination
  1060. MMIO register are preserved. The new value of the 8-bit register is returned.
  1061. If 8-bit MMIO register operations are not supported, then ASSERT().
  1062. If StartBit is greater than 7, then ASSERT().
  1063. If EndBit is greater than 7, then ASSERT().
  1064. If EndBit is less than StartBit, then ASSERT().
  1065. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1066. @param Address MMIO register to write.
  1067. @param StartBit The ordinal of the least significant bit in the bit field.
  1068. Range 0..7.
  1069. @param EndBit The ordinal of the most significant bit in the bit field.
  1070. Range 0..7.
  1071. @param Value New value of the bit field.
  1072. @return The value written back to the MMIO register.
  1073. **/
  1074. UINT8
  1075. EFIAPI
  1076. MmioBitFieldWrite8 (
  1077. IN UINTN Address,
  1078. IN UINTN StartBit,
  1079. IN UINTN EndBit,
  1080. IN UINT8 Value
  1081. )
  1082. {
  1083. return MmioWrite8 (
  1084. Address,
  1085. BitFieldWrite8 (MmioRead8 (Address), StartBit, EndBit, Value)
  1086. );
  1087. }
  1088. /**
  1089. Reads a bit field in an 8-bit MMIO register, performs a bitwise OR, and
  1090. writes the result back to the bit field in the 8-bit MMIO register.
  1091. Reads the 8-bit MMIO register specified by Address, performs a bitwise
  1092. inclusive OR between the read result and the value specified by OrData, and
  1093. writes the result to the 8-bit MMIO register specified by Address. The value
  1094. written to the MMIO register is returned. This function must guarantee that
  1095. all MMIO read and write operations are serialized. Extra left bits in OrData
  1096. are stripped.
  1097. If 8-bit MMIO register operations are not supported, then ASSERT().
  1098. If StartBit is greater than 7, then ASSERT().
  1099. If EndBit is greater than 7, then ASSERT().
  1100. If EndBit is less than StartBit, then ASSERT().
  1101. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1102. @param Address MMIO register to write.
  1103. @param StartBit The ordinal of the least significant bit in the bit field.
  1104. Range 0..7.
  1105. @param EndBit The ordinal of the most significant bit in the bit field.
  1106. Range 0..7.
  1107. @param OrData The value to OR with read value from the MMIO register.
  1108. @return The value written back to the MMIO register.
  1109. **/
  1110. UINT8
  1111. EFIAPI
  1112. MmioBitFieldOr8 (
  1113. IN UINTN Address,
  1114. IN UINTN StartBit,
  1115. IN UINTN EndBit,
  1116. IN UINT8 OrData
  1117. )
  1118. {
  1119. return MmioWrite8 (
  1120. Address,
  1121. BitFieldOr8 (MmioRead8 (Address), StartBit, EndBit, OrData)
  1122. );
  1123. }
  1124. /**
  1125. Reads a bit field in an 8-bit MMIO register, performs a bitwise AND, and
  1126. writes the result back to the bit field in the 8-bit MMIO register.
  1127. Reads the 8-bit MMIO register specified by Address, performs a bitwise AND
  1128. between the read result and the value specified by AndData, and writes the
  1129. result to the 8-bit MMIO register specified by Address. The value written to
  1130. the MMIO register is returned. This function must guarantee that all MMIO
  1131. read and write operations are serialized. Extra left bits in AndData are
  1132. stripped.
  1133. If 8-bit MMIO register operations are not supported, then ASSERT().
  1134. If StartBit is greater than 7, then ASSERT().
  1135. If EndBit is greater than 7, then ASSERT().
  1136. If EndBit is less than StartBit, then ASSERT().
  1137. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1138. @param Address MMIO register to write.
  1139. @param StartBit The ordinal of the least significant bit in the bit field.
  1140. Range 0..7.
  1141. @param EndBit The ordinal of the most significant bit in the bit field.
  1142. Range 0..7.
  1143. @param AndData The value to AND with read value from the MMIO register.
  1144. @return The value written back to the MMIO register.
  1145. **/
  1146. UINT8
  1147. EFIAPI
  1148. MmioBitFieldAnd8 (
  1149. IN UINTN Address,
  1150. IN UINTN StartBit,
  1151. IN UINTN EndBit,
  1152. IN UINT8 AndData
  1153. )
  1154. {
  1155. return MmioWrite8 (
  1156. Address,
  1157. BitFieldAnd8 (MmioRead8 (Address), StartBit, EndBit, AndData)
  1158. );
  1159. }
  1160. /**
  1161. Reads a bit field in an 8-bit MMIO register, performs a bitwise AND followed
  1162. by a bitwise OR, and writes the result back to the bit field in the
  1163. 8-bit MMIO register.
  1164. Reads the 8-bit MMIO register specified by Address, performs a bitwise AND
  1165. followed by a bitwise OR between the read result and the value
  1166. specified by AndData, and writes the result to the 8-bit MMIO register
  1167. specified by Address. The value written to the MMIO register is returned.
  1168. This function must guarantee that all MMIO read and write operations are
  1169. serialized. Extra left bits in both AndData and OrData are stripped.
  1170. If 8-bit MMIO register operations are not supported, then ASSERT().
  1171. If StartBit is greater than 7, then ASSERT().
  1172. If EndBit is greater than 7, then ASSERT().
  1173. If EndBit is less than StartBit, then ASSERT().
  1174. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1175. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1176. @param Address MMIO register to write.
  1177. @param StartBit The ordinal of the least significant bit in the bit field.
  1178. Range 0..7.
  1179. @param EndBit The ordinal of the most significant bit in the bit field.
  1180. Range 0..7.
  1181. @param AndData The value to AND with read value from the MMIO register.
  1182. @param OrData The value to OR with the result of the AND operation.
  1183. @return The value written back to the MMIO register.
  1184. **/
  1185. UINT8
  1186. EFIAPI
  1187. MmioBitFieldAndThenOr8 (
  1188. IN UINTN Address,
  1189. IN UINTN StartBit,
  1190. IN UINTN EndBit,
  1191. IN UINT8 AndData,
  1192. IN UINT8 OrData
  1193. )
  1194. {
  1195. return MmioWrite8 (
  1196. Address,
  1197. BitFieldAndThenOr8 (MmioRead8 (Address), StartBit, EndBit, AndData, OrData)
  1198. );
  1199. }
  1200. /**
  1201. Reads a 16-bit MMIO register, performs a bitwise OR, and writes the
  1202. result back to the 16-bit MMIO register.
  1203. Reads the 16-bit MMIO register specified by Address, performs a bitwise
  1204. inclusive OR between the read result and the value specified by OrData, and
  1205. writes the result to the 16-bit MMIO register specified by Address. The value
  1206. written to the MMIO register is returned. This function must guarantee that
  1207. all MMIO read and write operations are serialized.
  1208. If 16-bit MMIO register operations are not supported, then ASSERT().
  1209. @param Address The MMIO register to write.
  1210. @param OrData The value to OR with the read value from the MMIO register.
  1211. @return The value written back to the MMIO register.
  1212. **/
  1213. UINT16
  1214. EFIAPI
  1215. MmioOr16 (
  1216. IN UINTN Address,
  1217. IN UINT16 OrData
  1218. )
  1219. {
  1220. return MmioWrite16 (Address, (UINT16) (MmioRead16 (Address) | OrData));
  1221. }
  1222. /**
  1223. Reads a 16-bit MMIO register, performs a bitwise AND, and writes the result
  1224. back to the 16-bit MMIO register.
  1225. Reads the 16-bit MMIO register specified by Address, performs a bitwise AND
  1226. between the read result and the value specified by AndData, and writes the
  1227. result to the 16-bit MMIO register specified by Address. The value written to
  1228. the MMIO register is returned. This function must guarantee that all MMIO
  1229. read and write operations are serialized.
  1230. If 16-bit MMIO register operations are not supported, then ASSERT().
  1231. @param Address The MMIO register to write.
  1232. @param AndData The value to AND with the read value from the MMIO register.
  1233. @return The value written back to the MMIO register.
  1234. **/
  1235. UINT16
  1236. EFIAPI
  1237. MmioAnd16 (
  1238. IN UINTN Address,
  1239. IN UINT16 AndData
  1240. )
  1241. {
  1242. return MmioWrite16 (Address, (UINT16) (MmioRead16 (Address) & AndData));
  1243. }
  1244. /**
  1245. Reads a 16-bit MMIO register, performs a bitwise AND followed by a bitwise
  1246. inclusive OR, and writes the result back to the 16-bit MMIO register.
  1247. Reads the 16-bit MMIO register specified by Address, performs a bitwise AND
  1248. between the read result and the value specified by AndData, performs a
  1249. bitwise OR between the result of the AND operation and the value specified by
  1250. OrData, and writes the result to the 16-bit MMIO register specified by
  1251. Address. The value written to the MMIO register is returned. This function
  1252. must guarantee that all MMIO read and write operations are serialized.
  1253. If 16-bit MMIO register operations are not supported, then ASSERT().
  1254. @param Address The MMIO register to write.
  1255. @param AndData The value to AND with the read value from the MMIO register.
  1256. @param OrData The value to OR with the result of the AND operation.
  1257. @return The value written back to the MMIO register.
  1258. **/
  1259. UINT16
  1260. EFIAPI
  1261. MmioAndThenOr16 (
  1262. IN UINTN Address,
  1263. IN UINT16 AndData,
  1264. IN UINT16 OrData
  1265. )
  1266. {
  1267. return MmioWrite16 (Address, (UINT16) ((MmioRead16 (Address) & AndData) | OrData));
  1268. }
  1269. /**
  1270. Reads a bit field of a MMIO register.
  1271. Reads the bit field in a 16-bit MMIO register. The bit field is specified by
  1272. the StartBit and the EndBit. The value of the bit field is returned.
  1273. If 16-bit MMIO register operations are not supported, then ASSERT().
  1274. If StartBit is greater than 15, then ASSERT().
  1275. If EndBit is greater than 15, then ASSERT().
  1276. If EndBit is less than StartBit, then ASSERT().
  1277. @param Address MMIO register to read.
  1278. @param StartBit The ordinal of the least significant bit in the bit field.
  1279. Range 0..15.
  1280. @param EndBit The ordinal of the most significant bit in the bit field.
  1281. Range 0..15.
  1282. @return The value read.
  1283. **/
  1284. UINT16
  1285. EFIAPI
  1286. MmioBitFieldRead16 (
  1287. IN UINTN Address,
  1288. IN UINTN StartBit,
  1289. IN UINTN EndBit
  1290. )
  1291. {
  1292. return BitFieldRead16 (MmioRead16 (Address), StartBit, EndBit);
  1293. }
  1294. /**
  1295. Writes a bit field to a MMIO register.
  1296. Writes Value to the bit field of the MMIO register. The bit field is
  1297. specified by the StartBit and the EndBit. All other bits in the destination
  1298. MMIO register are preserved. The new value of the 16-bit register is returned.
  1299. If 16-bit MMIO register operations are not supported, then ASSERT().
  1300. If StartBit is greater than 15, then ASSERT().
  1301. If EndBit is greater than 15, then ASSERT().
  1302. If EndBit is less than StartBit, then ASSERT().
  1303. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1304. @param Address MMIO register to write.
  1305. @param StartBit The ordinal of the least significant bit in the bit field.
  1306. Range 0..15.
  1307. @param EndBit The ordinal of the most significant bit in the bit field.
  1308. Range 0..15.
  1309. @param Value New value of the bit field.
  1310. @return The value written back to the MMIO register.
  1311. **/
  1312. UINT16
  1313. EFIAPI
  1314. MmioBitFieldWrite16 (
  1315. IN UINTN Address,
  1316. IN UINTN StartBit,
  1317. IN UINTN EndBit,
  1318. IN UINT16 Value
  1319. )
  1320. {
  1321. return MmioWrite16 (
  1322. Address,
  1323. BitFieldWrite16 (MmioRead16 (Address), StartBit, EndBit, Value)
  1324. );
  1325. }
  1326. /**
  1327. Reads a bit field in a 16-bit MMIO register, performs a bitwise OR, and
  1328. writes the result back to the bit field in the 16-bit MMIO register.
  1329. Reads the 16-bit MMIO register specified by Address, performs a bitwise
  1330. inclusive OR between the read result and the value specified by OrData, and
  1331. writes the result to the 16-bit MMIO register specified by Address. The value
  1332. written to the MMIO register is returned. This function must guarantee that
  1333. all MMIO read and write operations are serialized. Extra left bits in OrData
  1334. are stripped.
  1335. If 16-bit MMIO register operations are not supported, then ASSERT().
  1336. If StartBit is greater than 15, then ASSERT().
  1337. If EndBit is greater than 15, then ASSERT().
  1338. If EndBit is less than StartBit, then ASSERT().
  1339. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1340. @param Address MMIO register to write.
  1341. @param StartBit The ordinal of the least significant bit in the bit field.
  1342. Range 0..15.
  1343. @param EndBit The ordinal of the most significant bit in the bit field.
  1344. Range 0..15.
  1345. @param OrData The value to OR with read value from the MMIO register.
  1346. @return The value written back to the MMIO register.
  1347. **/
  1348. UINT16
  1349. EFIAPI
  1350. MmioBitFieldOr16 (
  1351. IN UINTN Address,
  1352. IN UINTN StartBit,
  1353. IN UINTN EndBit,
  1354. IN UINT16 OrData
  1355. )
  1356. {
  1357. return MmioWrite16 (
  1358. Address,
  1359. BitFieldOr16 (MmioRead16 (Address), StartBit, EndBit, OrData)
  1360. );
  1361. }
  1362. /**
  1363. Reads a bit field in a 16-bit MMIO register, performs a bitwise AND, and
  1364. writes the result back to the bit field in the 16-bit MMIO register.
  1365. Reads the 16-bit MMIO register specified by Address, performs a bitwise AND
  1366. between the read result and the value specified by AndData, and writes the
  1367. result to the 16-bit MMIO register specified by Address. The value written to
  1368. the MMIO register is returned. This function must guarantee that all MMIO
  1369. read and write operations are serialized. Extra left bits in AndData are
  1370. stripped.
  1371. If 16-bit MMIO register operations are not supported, then ASSERT().
  1372. If StartBit is greater than 15, then ASSERT().
  1373. If EndBit is greater than 15, then ASSERT().
  1374. If EndBit is less than StartBit, then ASSERT().
  1375. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1376. @param Address MMIO register to write.
  1377. @param StartBit The ordinal of the least significant bit in the bit field.
  1378. Range 0..15.
  1379. @param EndBit The ordinal of the most significant bit in the bit field.
  1380. Range 0..15.
  1381. @param AndData The value to AND with read value from the MMIO register.
  1382. @return The value written back to the MMIO register.
  1383. **/
  1384. UINT16
  1385. EFIAPI
  1386. MmioBitFieldAnd16 (
  1387. IN UINTN Address,
  1388. IN UINTN StartBit,
  1389. IN UINTN EndBit,
  1390. IN UINT16 AndData
  1391. )
  1392. {
  1393. return MmioWrite16 (
  1394. Address,
  1395. BitFieldAnd16 (MmioRead16 (Address), StartBit, EndBit, AndData)
  1396. );
  1397. }
  1398. /**
  1399. Reads a bit field in a 16-bit MMIO register, performs a bitwise AND followed
  1400. by a bitwise OR, and writes the result back to the bit field in the
  1401. 16-bit MMIO register.
  1402. Reads the 16-bit MMIO register specified by Address, performs a bitwise AND
  1403. followed by a bitwise OR between the read result and the value
  1404. specified by AndData, and writes the result to the 16-bit MMIO register
  1405. specified by Address. The value written to the MMIO register is returned.
  1406. This function must guarantee that all MMIO read and write operations are
  1407. serialized. Extra left bits in both AndData and OrData are stripped.
  1408. If 16-bit MMIO register operations are not supported, then ASSERT().
  1409. If StartBit is greater than 15, then ASSERT().
  1410. If EndBit is greater than 15, then ASSERT().
  1411. If EndBit is less than StartBit, then ASSERT().
  1412. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1413. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1414. @param Address MMIO register to write.
  1415. @param StartBit The ordinal of the least significant bit in the bit field.
  1416. Range 0..15.
  1417. @param EndBit The ordinal of the most significant bit in the bit field.
  1418. Range 0..15.
  1419. @param AndData The value to AND with read value from the MMIO register.
  1420. @param OrData The value to OR with the result of the AND operation.
  1421. @return The value written back to the MMIO register.
  1422. **/
  1423. UINT16
  1424. EFIAPI
  1425. MmioBitFieldAndThenOr16 (
  1426. IN UINTN Address,
  1427. IN UINTN StartBit,
  1428. IN UINTN EndBit,
  1429. IN UINT16 AndData,
  1430. IN UINT16 OrData
  1431. )
  1432. {
  1433. return MmioWrite16 (
  1434. Address,
  1435. BitFieldAndThenOr16 (MmioRead16 (Address), StartBit, EndBit, AndData, OrData)
  1436. );
  1437. }
  1438. /**
  1439. Reads a 32-bit MMIO register, performs a bitwise OR, and writes the
  1440. result back to the 32-bit MMIO register.
  1441. Reads the 32-bit MMIO register specified by Address, performs a bitwise
  1442. inclusive OR between the read result and the value specified by OrData, and
  1443. writes the result to the 32-bit MMIO register specified by Address. The value
  1444. written to the MMIO register is returned. This function must guarantee that
  1445. all MMIO read and write operations are serialized.
  1446. If 32-bit MMIO register operations are not supported, then ASSERT().
  1447. @param Address The MMIO register to write.
  1448. @param OrData The value to OR with the read value from the MMIO register.
  1449. @return The value written back to the MMIO register.
  1450. **/
  1451. UINT32
  1452. EFIAPI
  1453. MmioOr32 (
  1454. IN UINTN Address,
  1455. IN UINT32 OrData
  1456. )
  1457. {
  1458. return MmioWrite32 (Address, MmioRead32 (Address) | OrData);
  1459. }
  1460. /**
  1461. Reads a 32-bit MMIO register, performs a bitwise AND, and writes the result
  1462. back to the 32-bit MMIO register.
  1463. Reads the 32-bit MMIO register specified by Address, performs a bitwise AND
  1464. between the read result and the value specified by AndData, and writes the
  1465. result to the 32-bit MMIO register specified by Address. The value written to
  1466. the MMIO register is returned. This function must guarantee that all MMIO
  1467. read and write operations are serialized.
  1468. If 32-bit MMIO register operations are not supported, then ASSERT().
  1469. @param Address The MMIO register to write.
  1470. @param AndData The value to AND with the read value from the MMIO register.
  1471. @return The value written back to the MMIO register.
  1472. **/
  1473. UINT32
  1474. EFIAPI
  1475. MmioAnd32 (
  1476. IN UINTN Address,
  1477. IN UINT32 AndData
  1478. )
  1479. {
  1480. return MmioWrite32 (Address, MmioRead32 (Address) & AndData);
  1481. }
  1482. /**
  1483. Reads a 32-bit MMIO register, performs a bitwise AND followed by a bitwise
  1484. inclusive OR, and writes the result back to the 32-bit MMIO register.
  1485. Reads the 32-bit MMIO register specified by Address, performs a bitwise AND
  1486. between the read result and the value specified by AndData, performs a
  1487. bitwise OR between the result of the AND operation and the value specified by
  1488. OrData, and writes the result to the 32-bit MMIO register specified by
  1489. Address. The value written to the MMIO register is returned. This function
  1490. must guarantee that all MMIO read and write operations are serialized.
  1491. If 32-bit MMIO register operations are not supported, then ASSERT().
  1492. @param Address The MMIO register to write.
  1493. @param AndData The value to AND with the read value from the MMIO register.
  1494. @param OrData The value to OR with the result of the AND operation.
  1495. @return The value written back to the MMIO register.
  1496. **/
  1497. UINT32
  1498. EFIAPI
  1499. MmioAndThenOr32 (
  1500. IN UINTN Address,
  1501. IN UINT32 AndData,
  1502. IN UINT32 OrData
  1503. )
  1504. {
  1505. return MmioWrite32 (Address, (MmioRead32 (Address) & AndData) | OrData);
  1506. }
  1507. /**
  1508. Reads a bit field of a MMIO register.
  1509. Reads the bit field in a 32-bit MMIO register. The bit field is specified by
  1510. the StartBit and the EndBit. The value of the bit field is returned.
  1511. If 32-bit MMIO register operations are not supported, then ASSERT().
  1512. If StartBit is greater than 31, then ASSERT().
  1513. If EndBit is greater than 31, then ASSERT().
  1514. If EndBit is less than StartBit, then ASSERT().
  1515. @param Address MMIO register to read.
  1516. @param StartBit The ordinal of the least significant bit in the bit field.
  1517. Range 0..31.
  1518. @param EndBit The ordinal of the most significant bit in the bit field.
  1519. Range 0..31.
  1520. @return The value read.
  1521. **/
  1522. UINT32
  1523. EFIAPI
  1524. MmioBitFieldRead32 (
  1525. IN UINTN Address,
  1526. IN UINTN StartBit,
  1527. IN UINTN EndBit
  1528. )
  1529. {
  1530. return BitFieldRead32 (MmioRead32 (Address), StartBit, EndBit);
  1531. }
  1532. /**
  1533. Writes a bit field to a MMIO register.
  1534. Writes Value to the bit field of the MMIO register. The bit field is
  1535. specified by the StartBit and the EndBit. All other bits in the destination
  1536. MMIO register are preserved. The new value of the 32-bit register is returned.
  1537. If 32-bit MMIO register operations are not supported, then ASSERT().
  1538. If StartBit is greater than 31, then ASSERT().
  1539. If EndBit is greater than 31, then ASSERT().
  1540. If EndBit is less than StartBit, then ASSERT().
  1541. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1542. @param Address MMIO register to write.
  1543. @param StartBit The ordinal of the least significant bit in the bit field.
  1544. Range 0..31.
  1545. @param EndBit The ordinal of the most significant bit in the bit field.
  1546. Range 0..31.
  1547. @param Value New value of the bit field.
  1548. @return The value written back to the MMIO register.
  1549. **/
  1550. UINT32
  1551. EFIAPI
  1552. MmioBitFieldWrite32 (
  1553. IN UINTN Address,
  1554. IN UINTN StartBit,
  1555. IN UINTN EndBit,
  1556. IN UINT32 Value
  1557. )
  1558. {
  1559. return MmioWrite32 (
  1560. Address,
  1561. BitFieldWrite32 (MmioRead32 (Address), StartBit, EndBit, Value)
  1562. );
  1563. }
  1564. /**
  1565. Reads a bit field in a 32-bit MMIO register, performs a bitwise OR, and
  1566. writes the result back to the bit field in the 32-bit MMIO register.
  1567. Reads the 32-bit MMIO register specified by Address, performs a bitwise
  1568. inclusive OR between the read result and the value specified by OrData, and
  1569. writes the result to the 32-bit MMIO register specified by Address. The value
  1570. written to the MMIO register is returned. This function must guarantee that
  1571. all MMIO read and write operations are serialized. Extra left bits in OrData
  1572. are stripped.
  1573. If 32-bit MMIO register operations are not supported, then ASSERT().
  1574. If StartBit is greater than 31, then ASSERT().
  1575. If EndBit is greater than 31, then ASSERT().
  1576. If EndBit is less than StartBit, then ASSERT().
  1577. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1578. @param Address MMIO register to write.
  1579. @param StartBit The ordinal of the least significant bit in the bit field.
  1580. Range 0..31.
  1581. @param EndBit The ordinal of the most significant bit in the bit field.
  1582. Range 0..31.
  1583. @param OrData The value to OR with read value from the MMIO register.
  1584. @return The value written back to the MMIO register.
  1585. **/
  1586. UINT32
  1587. EFIAPI
  1588. MmioBitFieldOr32 (
  1589. IN UINTN Address,
  1590. IN UINTN StartBit,
  1591. IN UINTN EndBit,
  1592. IN UINT32 OrData
  1593. )
  1594. {
  1595. return MmioWrite32 (
  1596. Address,
  1597. BitFieldOr32 (MmioRead32 (Address), StartBit, EndBit, OrData)
  1598. );
  1599. }
  1600. /**
  1601. Reads a bit field in a 32-bit MMIO register, performs a bitwise AND, and
  1602. writes the result back to the bit field in the 32-bit MMIO register.
  1603. Reads the 32-bit MMIO register specified by Address, performs a bitwise AND
  1604. between the read result and the value specified by AndData, and writes the
  1605. result to the 32-bit MMIO register specified by Address. The value written to
  1606. the MMIO register is returned. This function must guarantee that all MMIO
  1607. read and write operations are serialized. Extra left bits in AndData are
  1608. stripped.
  1609. If 32-bit MMIO register operations are not supported, then ASSERT().
  1610. If StartBit is greater than 31, then ASSERT().
  1611. If EndBit is greater than 31, then ASSERT().
  1612. If EndBit is less than StartBit, then ASSERT().
  1613. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1614. @param Address MMIO register to write.
  1615. @param StartBit The ordinal of the least significant bit in the bit field.
  1616. Range 0..31.
  1617. @param EndBit The ordinal of the most significant bit in the bit field.
  1618. Range 0..31.
  1619. @param AndData The value to AND with read value from the MMIO register.
  1620. @return The value written back to the MMIO register.
  1621. **/
  1622. UINT32
  1623. EFIAPI
  1624. MmioBitFieldAnd32 (
  1625. IN UINTN Address,
  1626. IN UINTN StartBit,
  1627. IN UINTN EndBit,
  1628. IN UINT32 AndData
  1629. )
  1630. {
  1631. return MmioWrite32 (
  1632. Address,
  1633. BitFieldAnd32 (MmioRead32 (Address), StartBit, EndBit, AndData)
  1634. );
  1635. }
  1636. /**
  1637. Reads a bit field in a 32-bit MMIO register, performs a bitwise AND followed
  1638. by a bitwise OR, and writes the result back to the bit field in the
  1639. 32-bit MMIO register.
  1640. Reads the 32-bit MMIO register specified by Address, performs a bitwise AND
  1641. followed by a bitwise OR between the read result and the value
  1642. specified by AndData, and writes the result to the 32-bit MMIO register
  1643. specified by Address. The value written to the MMIO register is returned.
  1644. This function must guarantee that all MMIO read and write operations are
  1645. serialized. Extra left bits in both AndData and OrData are stripped.
  1646. If 32-bit MMIO register operations are not supported, then ASSERT().
  1647. If StartBit is greater than 31, then ASSERT().
  1648. If EndBit is greater than 31, then ASSERT().
  1649. If EndBit is less than StartBit, then ASSERT().
  1650. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1651. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1652. @param Address MMIO register to write.
  1653. @param StartBit The ordinal of the least significant bit in the bit field.
  1654. Range 0..31.
  1655. @param EndBit The ordinal of the most significant bit in the bit field.
  1656. Range 0..31.
  1657. @param AndData The value to AND with read value from the MMIO register.
  1658. @param OrData The value to OR with the result of the AND operation.
  1659. @return The value written back to the MMIO register.
  1660. **/
  1661. UINT32
  1662. EFIAPI
  1663. MmioBitFieldAndThenOr32 (
  1664. IN UINTN Address,
  1665. IN UINTN StartBit,
  1666. IN UINTN EndBit,
  1667. IN UINT32 AndData,
  1668. IN UINT32 OrData
  1669. )
  1670. {
  1671. return MmioWrite32 (
  1672. Address,
  1673. BitFieldAndThenOr32 (MmioRead32 (Address), StartBit, EndBit, AndData, OrData)
  1674. );
  1675. }
  1676. /**
  1677. Reads a 64-bit MMIO register, performs a bitwise OR, and writes the
  1678. result back to the 64-bit MMIO register.
  1679. Reads the 64-bit MMIO register specified by Address, performs a bitwise
  1680. inclusive OR between the read result and the value specified by OrData, and
  1681. writes the result to the 64-bit MMIO register specified by Address. The value
  1682. written to the MMIO register is returned. This function must guarantee that
  1683. all MMIO read and write operations are serialized.
  1684. If 64-bit MMIO register operations are not supported, then ASSERT().
  1685. @param Address The MMIO register to write.
  1686. @param OrData The value to OR with the read value from the MMIO register.
  1687. @return The value written back to the MMIO register.
  1688. **/
  1689. UINT64
  1690. EFIAPI
  1691. MmioOr64 (
  1692. IN UINTN Address,
  1693. IN UINT64 OrData
  1694. )
  1695. {
  1696. return MmioWrite64 (Address, MmioRead64 (Address) | OrData);
  1697. }
  1698. /**
  1699. Reads a 64-bit MMIO register, performs a bitwise AND, and writes the result
  1700. back to the 64-bit MMIO register.
  1701. Reads the 64-bit MMIO register specified by Address, performs a bitwise AND
  1702. between the read result and the value specified by AndData, and writes the
  1703. result to the 64-bit MMIO register specified by Address. The value written to
  1704. the MMIO register is returned. This function must guarantee that all MMIO
  1705. read and write operations are serialized.
  1706. If 64-bit MMIO register operations are not supported, then ASSERT().
  1707. @param Address The MMIO register to write.
  1708. @param AndData The value to AND with the read value from the MMIO register.
  1709. @return The value written back to the MMIO register.
  1710. **/
  1711. UINT64
  1712. EFIAPI
  1713. MmioAnd64 (
  1714. IN UINTN Address,
  1715. IN UINT64 AndData
  1716. )
  1717. {
  1718. return MmioWrite64 (Address, MmioRead64 (Address) & AndData);
  1719. }
  1720. /**
  1721. Reads a 64-bit MMIO register, performs a bitwise AND followed by a bitwise
  1722. inclusive OR, and writes the result back to the 64-bit MMIO register.
  1723. Reads the 64-bit MMIO register specified by Address, performs a bitwise AND
  1724. between the read result and the value specified by AndData, performs a
  1725. bitwise OR between the result of the AND operation and the value specified by
  1726. OrData, and writes the result to the 64-bit MMIO register specified by
  1727. Address. The value written to the MMIO register is returned. This function
  1728. must guarantee that all MMIO read and write operations are serialized.
  1729. If 64-bit MMIO register operations are not supported, then ASSERT().
  1730. @param Address The MMIO register to write.
  1731. @param AndData The value to AND with the read value from the MMIO register.
  1732. @param OrData The value to OR with the result of the AND operation.
  1733. @return The value written back to the MMIO register.
  1734. **/
  1735. UINT64
  1736. EFIAPI
  1737. MmioAndThenOr64 (
  1738. IN UINTN Address,
  1739. IN UINT64 AndData,
  1740. IN UINT64 OrData
  1741. )
  1742. {
  1743. return MmioWrite64 (Address, (MmioRead64 (Address) & AndData) | OrData);
  1744. }
  1745. /**
  1746. Reads a bit field of a MMIO register.
  1747. Reads the bit field in a 64-bit MMIO register. The bit field is specified by
  1748. the StartBit and the EndBit. The value of the bit field is returned.
  1749. If 64-bit MMIO register operations are not supported, then ASSERT().
  1750. If StartBit is greater than 63, then ASSERT().
  1751. If EndBit is greater than 63, then ASSERT().
  1752. If EndBit is less than StartBit, then ASSERT().
  1753. @param Address MMIO register to read.
  1754. @param StartBit The ordinal of the least significant bit in the bit field.
  1755. Range 0..63.
  1756. @param EndBit The ordinal of the most significant bit in the bit field.
  1757. Range 0..63.
  1758. @return The value read.
  1759. **/
  1760. UINT64
  1761. EFIAPI
  1762. MmioBitFieldRead64 (
  1763. IN UINTN Address,
  1764. IN UINTN StartBit,
  1765. IN UINTN EndBit
  1766. )
  1767. {
  1768. return BitFieldRead64 (MmioRead64 (Address), StartBit, EndBit);
  1769. }
  1770. /**
  1771. Writes a bit field to a MMIO register.
  1772. Writes Value to the bit field of the MMIO register. The bit field is
  1773. specified by the StartBit and the EndBit. All other bits in the destination
  1774. MMIO register are preserved. The new value of the 64-bit register is returned.
  1775. If 64-bit MMIO register operations are not supported, then ASSERT().
  1776. If StartBit is greater than 63, then ASSERT().
  1777. If EndBit is greater than 63, then ASSERT().
  1778. If EndBit is less than StartBit, then ASSERT().
  1779. If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1780. @param Address MMIO register to write.
  1781. @param StartBit The ordinal of the least significant bit in the bit field.
  1782. Range 0..63.
  1783. @param EndBit The ordinal of the most significant bit in the bit field.
  1784. Range 0..63.
  1785. @param Value New value of the bit field.
  1786. @return The value written back to the MMIO register.
  1787. **/
  1788. UINT64
  1789. EFIAPI
  1790. MmioBitFieldWrite64 (
  1791. IN UINTN Address,
  1792. IN UINTN StartBit,
  1793. IN UINTN EndBit,
  1794. IN UINT64 Value
  1795. )
  1796. {
  1797. return MmioWrite64 (
  1798. Address,
  1799. BitFieldWrite64 (MmioRead64 (Address), StartBit, EndBit, Value)
  1800. );
  1801. }
  1802. /**
  1803. Reads a bit field in a 64-bit MMIO register, performs a bitwise OR, and
  1804. writes the result back to the bit field in the 64-bit MMIO register.
  1805. Reads the 64-bit MMIO register specified by Address, performs a bitwise
  1806. inclusive OR between the read result and the value specified by OrData, and
  1807. writes the result to the 64-bit MMIO register specified by Address. The value
  1808. written to the MMIO register is returned. This function must guarantee that
  1809. all MMIO read and write operations are serialized. Extra left bits in OrData
  1810. are stripped.
  1811. If 64-bit MMIO register operations are not supported, then ASSERT().
  1812. If StartBit is greater than 63, then ASSERT().
  1813. If EndBit is greater than 63, then ASSERT().
  1814. If EndBit is less than StartBit, then ASSERT().
  1815. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1816. @param Address MMIO register to write.
  1817. @param StartBit The ordinal of the least significant bit in the bit field.
  1818. Range 0..63.
  1819. @param EndBit The ordinal of the most significant bit in the bit field.
  1820. Range 0..63.
  1821. @param OrData The value to OR with read value from the MMIO register.
  1822. @return The value written back to the MMIO register.
  1823. **/
  1824. UINT64
  1825. EFIAPI
  1826. MmioBitFieldOr64 (
  1827. IN UINTN Address,
  1828. IN UINTN StartBit,
  1829. IN UINTN EndBit,
  1830. IN UINT64 OrData
  1831. )
  1832. {
  1833. return MmioWrite64 (
  1834. Address,
  1835. BitFieldOr64 (MmioRead64 (Address), StartBit, EndBit, OrData)
  1836. );
  1837. }
  1838. /**
  1839. Reads a bit field in a 64-bit MMIO register, performs a bitwise AND, and
  1840. writes the result back to the bit field in the 64-bit MMIO register.
  1841. Reads the 64-bit MMIO register specified by Address, performs a bitwise AND
  1842. between the read result and the value specified by AndData, and writes the
  1843. result to the 64-bit MMIO register specified by Address. The value written to
  1844. the MMIO register is returned. This function must guarantee that all MMIO
  1845. read and write operations are serialized. Extra left bits in AndData are
  1846. stripped.
  1847. If 64-bit MMIO register operations are not supported, then ASSERT().
  1848. If StartBit is greater than 63, then ASSERT().
  1849. If EndBit is greater than 63, then ASSERT().
  1850. If EndBit is less than StartBit, then ASSERT().
  1851. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1852. @param Address MMIO register to write.
  1853. @param StartBit The ordinal of the least significant bit in the bit field.
  1854. Range 0..63.
  1855. @param EndBit The ordinal of the most significant bit in the bit field.
  1856. Range 0..63.
  1857. @param AndData The value to AND with read value from the MMIO register.
  1858. @return The value written back to the MMIO register.
  1859. **/
  1860. UINT64
  1861. EFIAPI
  1862. MmioBitFieldAnd64 (
  1863. IN UINTN Address,
  1864. IN UINTN StartBit,
  1865. IN UINTN EndBit,
  1866. IN UINT64 AndData
  1867. )
  1868. {
  1869. return MmioWrite64 (
  1870. Address,
  1871. BitFieldAnd64 (MmioRead64 (Address), StartBit, EndBit, AndData)
  1872. );
  1873. }
  1874. /**
  1875. Reads a bit field in a 64-bit MMIO register, performs a bitwise AND followed
  1876. by a bitwise OR, and writes the result back to the bit field in the
  1877. 64-bit MMIO register.
  1878. Reads the 64-bit MMIO register specified by Address, performs a bitwise AND
  1879. followed by a bitwise OR between the read result and the value
  1880. specified by AndData, and writes the result to the 64-bit MMIO register
  1881. specified by Address. The value written to the MMIO register is returned.
  1882. This function must guarantee that all MMIO read and write operations are
  1883. serialized. Extra left bits in both AndData and OrData are stripped.
  1884. If 64-bit MMIO register operations are not supported, then ASSERT().
  1885. If StartBit is greater than 63, then ASSERT().
  1886. If EndBit is greater than 63, then ASSERT().
  1887. If EndBit is less than StartBit, then ASSERT().
  1888. If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1889. If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
  1890. @param Address MMIO register to write.
  1891. @param StartBit The ordinal of the least significant bit in the bit field.
  1892. Range 0..63.
  1893. @param EndBit The ordinal of the most significant bit in the bit field.
  1894. Range 0..63.
  1895. @param AndData The value to AND with read value from the MMIO register.
  1896. @param OrData The value to OR with the result of the AND operation.
  1897. @return The value written back to the MMIO register.
  1898. **/
  1899. UINT64
  1900. EFIAPI
  1901. MmioBitFieldAndThenOr64 (
  1902. IN UINTN Address,
  1903. IN UINTN StartBit,
  1904. IN UINTN EndBit,
  1905. IN UINT64 AndData,
  1906. IN UINT64 OrData
  1907. )
  1908. {
  1909. return MmioWrite64 (
  1910. Address,
  1911. BitFieldAndThenOr64 (MmioRead64 (Address), StartBit, EndBit, AndData, OrData)
  1912. );
  1913. }