tirom.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. tirom.h
  9. Abstract:
  10. This header contains definitions for the TI ROM API.
  11. Author:
  12. Evan Green 1-Apr-2014
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // --------------------------------------------------------------------- Macros
  19. //
  20. #define TI_ROM_API(_Value) ((void *)(*((UINT32 *)(_Value))))
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. #define OMAP4460_PUBLIC_API_BASE 0x30400
  25. #define OMAP4430_PUBLIC_API_BASE 0x28400
  26. #define AM335_PUBLIC_API_BASE 0x20400
  27. #define PUBLIC_GET_DRIVER_MEM_OFFSET 0x04
  28. #define PUBLIC_GET_DRIVER_PER_OFFSET 0x08
  29. #define PUBLIC_GET_DEVICE_MEM_OFFSET 0x80
  30. #define PUBLIC_GET_DEVICE_PER_OFFSET 0x84
  31. #define OMAP4_ROM_DEVICE_NULL 0x40
  32. #define OMAP4_ROM_DEVICE_UART1 0x41
  33. #define OMAP4_ROM_DEVICE_UART2 0x42
  34. #define OMAP4_ROM_DEVICE_UART3 0x43
  35. #define OMAP4_ROM_DEVICE_UART4 0x44
  36. #define OMAP4_ROM_DEVICE_USB 0x45
  37. #define OMAP4_ROM_DEVICE_USBEXT 0x46
  38. #define AM335_ROM_DEVICE_NULL 0x00
  39. #define AM335_ROM_DEVICE_XIP_MUX1 0x01
  40. #define AM335_ROM_DEVICE_XIPWAIT_MUX1 0x02
  41. #define AM335_ROM_DEVICE_XIP_MUX2 0x03
  42. #define AM335_ROM_DEVICE_XIPWAIT_MUX2 0x04
  43. #define AM335_ROM_DEVICE_NAND 0x05
  44. #define AM335_ROM_DEVICE_NAND_I2C 0x06
  45. #define AM335_ROM_DEVICE_MMCSD0 0x08
  46. #define AM335_ROM_DEVICE_MMCSD1 0x09
  47. #define AM335_ROM_DEVICE_SPI 0x15
  48. #define AM335_ROM_DEVICE_UART0 0x41
  49. #define AM335_ROM_DEVICE_USB 0x44
  50. #define AM335_ROM_DEVICE_MAC0 0x46
  51. #define TI_ROM_USB_MAX_IO_SIZE 65536
  52. #define TI_ROM_TRANSFER_MODE_CPU 0
  53. #define TI_ROM_TRANSFER_MODE_DMA 1
  54. #define TI_ROM_STATUS_SUCCESS 0
  55. #define TI_ROM_STATUS_FAILED 1
  56. #define TI_ROM_STATUS_TIMEOUT 2
  57. #define TI_ROM_STATUS_BAD_PARAM 3
  58. #define TI_ROM_STATUS_WAITING 4
  59. #define TI_ROM_STATUS_NO_MEMORY 5
  60. #define TI_ROM_STATUS_INVALID_PTR 6
  61. #define TI_ROM_MMCSD_TYPE_MMC 1
  62. #define TI_ROM_MMCSD_TYPE_SD 2
  63. #define TI_ROM_MMCSD_MODE_RAW 1
  64. #define TI_ROM_MMCSD_MODE_FAT 2
  65. #define TI_ROM_MMCSD_ADDRESSING_BYTE 1
  66. #define TI_ROM_MMCSD_ADDRESSING_SECTOR 2
  67. #define TI_ROM_MMCSD_PARTITION_COUNT 8
  68. //
  69. // ------------------------------------------------------ Data Type Definitions
  70. //
  71. typedef struct _TI_ROM_PER_HANDLE
  72. TI_ROM_PER_HANDLE, *PTI_ROM_PER_HANDLE;
  73. /*++
  74. Structure Description:
  75. This structure defines the format of information passed from the TI ROM
  76. code to the first stage loader.
  77. Members:
  78. Reserved - Stores a reserved value, contents unknown.
  79. MemoryDeviceDescriptor - Stores a pointer to the memory device descriptor
  80. that has been used during the memory booting process.
  81. BootDevice - Stores the code of the device that was booted from. See
  82. AM335_ROM_DEVICE_* definitions.
  83. ResetReason - Stores the current reset reason bit mask.
  84. Reserved2 - Stores another reserved field.
  85. --*/
  86. #pragma pack(push, 1)
  87. typedef struct _AM335_BOOT_DATA {
  88. UINT32 Reserved;
  89. UINT32 MemoryDeviceDescriptor;
  90. UINT8 BootDevice;
  91. UINT8 ResetReason;
  92. UINT8 Reserved2;
  93. } PACKED AM335_BOOT_DATA, *PAM335_BOOT_DATA;
  94. #pragma pack(pop)
  95. typedef
  96. INT32
  97. (*PTI_ROM_PER_CALLBACK) (
  98. PTI_ROM_PER_HANDLE Handle
  99. );
  100. /*++
  101. Routine Description:
  102. This routine is called by the ROM when I/O completes.
  103. Arguments:
  104. Handle - Supplies the handle with the I/O.
  105. Return Value:
  106. 0 on success.
  107. Non-zero on failure.
  108. --*/
  109. /*++
  110. Structure Description:
  111. This structure defines the TI ROM peripheral driver handle.
  112. Members:
  113. IoConfiguration - Stores a pointer to the I/O configuration object.
  114. Callback - Stores a pointer to the callback function to call when I/O is
  115. complete.
  116. Data - Stores the address of the data to send or receive.
  117. Length - Stores the length of the data in bytes.
  118. Options - Stores a pointer to the boot options.
  119. TransferMode - Stores the transfer mode.
  120. DeviceType - Stores the device type.
  121. Status - Stores the return status of the I/O.
  122. HsTocMask - Stores a reserved value.
  123. GpTocMask - Stores another reserved value.
  124. ConfigTimeout - Stores another reserved value.
  125. --*/
  126. struct _TI_ROM_PER_HANDLE {
  127. VOID *IoConfiguration;
  128. PTI_ROM_PER_CALLBACK Callback;
  129. VOID *Data;
  130. UINT32 Length;
  131. UINT16 *Options;
  132. UINT32 TransferMode;
  133. UINT32 DeviceType;
  134. volatile UINT32 Status;
  135. UINT16 HsTocMask;
  136. UINT16 GpTocMask;
  137. UINT32 ConfigTimeout;
  138. };
  139. typedef
  140. INT32
  141. (*PTI_ROM_PER_INITIALIZE) (
  142. PTI_ROM_PER_HANDLE Handle
  143. );
  144. /*++
  145. Routine Description:
  146. This routine initializes a peripheral device.
  147. Arguments:
  148. Handle - Supplies a pointer to the device handle.
  149. Return Value:
  150. 0 on success.
  151. Non-zero on failure.
  152. --*/
  153. typedef
  154. INT32
  155. (*PTI_ROM_PER_READ) (
  156. PTI_ROM_PER_HANDLE Handle
  157. );
  158. /*++
  159. Routine Description:
  160. This routine performs a peripheral read.
  161. Arguments:
  162. Handle - Supplies a pointer to the device handle.
  163. Return Value:
  164. 0 on success.
  165. Non-zero on failure.
  166. --*/
  167. typedef
  168. INT32
  169. (*PTI_ROM_PER_WRITE) (
  170. PTI_ROM_PER_HANDLE Handle
  171. );
  172. /*++
  173. Routine Description:
  174. This routine performs a peripheral write.
  175. Arguments:
  176. Handle - Supplies a pointer to the device handle.
  177. Return Value:
  178. 0 on success.
  179. Non-zero on failure.
  180. --*/
  181. typedef
  182. INT32
  183. (*PTI_ROM_PER_CLOSE) (
  184. PTI_ROM_PER_HANDLE Handle
  185. );
  186. /*++
  187. Routine Description:
  188. This routine closes a peripheral handle.
  189. Arguments:
  190. Handle - Supplies a pointer to the device handle.
  191. Return Value:
  192. 0 on success.
  193. Non-zero on failure.
  194. --*/
  195. typedef
  196. INT32
  197. (*PTI_ROM_PER_CONFIGURE) (
  198. PTI_ROM_PER_HANDLE Handle,
  199. VOID *Data
  200. );
  201. /*++
  202. Routine Description:
  203. This routine configures a peripheral device.
  204. Arguments:
  205. Handle - Supplies a pointer to the device handle.
  206. Data - Supplies a pointer to the configuration data.
  207. Return Value:
  208. 0 on success.
  209. Non-zero on failure.
  210. --*/
  211. /*++
  212. Structure Description:
  213. This structure defines the TI ROM peripheral driver interface.
  214. Members:
  215. Initialize - Stores a pointer to a function used to initialize a peripheral
  216. device handle.
  217. Read - Stores a pointer to a function used to read from the device.
  218. Write - Stores a pointer to a function used to write to the device.
  219. Close - Stores a pointer to a function used to close the handle.
  220. Configure - Stores a pointer to a function used to configure the handle.
  221. --*/
  222. typedef struct _TI_ROM_PER_DRIVER {
  223. PTI_ROM_PER_INITIALIZE Initialize;
  224. PTI_ROM_PER_READ Read;
  225. PTI_ROM_PER_WRITE Write;
  226. PTI_ROM_PER_CLOSE Close;
  227. PTI_ROM_PER_CONFIGURE Configure;
  228. } TI_ROM_PER_DRIVER, *PTI_ROM_PER_DRIVER;
  229. /*++
  230. Structure Description:
  231. This structure defines the TI ROM USB configuration type.
  232. Members:
  233. Type - Stores the configuration type identifier.
  234. Value - Stores the value for the configuration type.
  235. --*/
  236. typedef struct _TI_ROM_USB_CONFIGURATION {
  237. UINT32 Type;
  238. UINT32 Value;
  239. } TI_ROM_USB_CONFIGURATION, *PTI_ROM_USB_CONFIGURATION;
  240. typedef
  241. INT32
  242. (*PTI_ROM_GET_PER_DRIVER) (
  243. PTI_ROM_PER_DRIVER *Driver,
  244. UINT32 DeviceType
  245. );
  246. /*++
  247. Routine Description:
  248. This routine gets a peripheral driver interface from the ROM.
  249. Arguments:
  250. Driver - Supplies a pointer where a pointer to the interface will be
  251. returned on success.
  252. DeviceType - Supplies the type of device to get the interface for.
  253. Return Value:
  254. 0 on success.
  255. Non-zero on failure.
  256. --*/
  257. typedef
  258. INT32
  259. (*PTI_ROM_GET_PER_DEVICE) (
  260. PTI_ROM_PER_HANDLE *Handle
  261. );
  262. /*++
  263. Routine Description:
  264. This routine closes a peripheral handle.
  265. Arguments:
  266. Handle - Supplies a pointer where a pointer to the device handle will be
  267. returned on success.
  268. Return Value:
  269. 0 on success.
  270. Non-zero on failure.
  271. --*/
  272. /*++
  273. Structure Description:
  274. This structure defines the TI ROM memory device.
  275. Members:
  276. Initialized - Stores a value indicating the initialization state of the
  277. structure.
  278. DeviceType - Stores the current device type.
  279. TrialsCount - Stores the number of booting trials.
  280. XipDevice - Stores a boolean indicating that this is a XIP device.
  281. SearchSize - Stores the size of blocks to search for an image.
  282. SearchBase - Stores the device base address.
  283. HsTocMask - Stores the mask of TOC items to search (HS device only).
  284. GpTocMask - Stores the mask of TOC items to search on GP devices.
  285. DeviceData - Stores a device dependent sub-structure.
  286. BootOptions - Stores a pointer to boot options.
  287. --*/
  288. typedef struct _TI_ROM_MEM_DEVICE {
  289. UINT32 Initialized;
  290. UINT8 DeviceType;
  291. UINT8 TrialsCount;
  292. UINT32 XipDevice;
  293. UINT16 SearchSize;
  294. UINT32 BaseAddress;
  295. UINT16 HsTocMask;
  296. UINT16 GpTocMask;
  297. VOID *DeviceData;
  298. UINT16 *BootOptions;
  299. } TI_ROM_MEM_DEVICE, *PTI_ROM_MEM_DEVICE;
  300. /*++
  301. Structure Description:
  302. This structure defines the TI ROM Read Descriptor.
  303. Members:
  304. SectorCount - Stores the starting sector to read from.
  305. SectorCount - Stores the number of sectors to read.
  306. Destination - Stores the destination buffer to read the data into.
  307. --*/
  308. typedef struct _TI_ROM_MEM_READ_DESCRIPTOR {
  309. UINT32 SectorStart;
  310. UINT32 SectorCount;
  311. VOID *Destination;
  312. } TI_ROM_MEM_READ_DESCRIPTOR, *PTI_ROM_MEM_READ_DESCRIPTOR;
  313. typedef
  314. INT32
  315. (*PTI_ROM_MEM_INITIALIZE) (
  316. PTI_ROM_MEM_DEVICE Device
  317. );
  318. /*++
  319. Routine Description:
  320. This routine initializes a connection to the ROM memory device.
  321. Arguments:
  322. Device - Supplies a pointer where the device information will be returned.
  323. Return Value:
  324. 0 on success.
  325. Non-zero on failure.
  326. --*/
  327. typedef
  328. INT32
  329. (*PTI_ROM_MEM_READ) (
  330. PTI_ROM_MEM_DEVICE Device,
  331. PTI_ROM_MEM_READ_DESCRIPTOR Descriptor
  332. );
  333. /*++
  334. Routine Description:
  335. This routine reads from the ROM memory device.
  336. Arguments:
  337. Device - Supplies a pointer to the memory device.
  338. Descriptor - Supplies a pointer to the read request information.
  339. Return Value:
  340. 0 on success.
  341. Non-zero on failure.
  342. --*/
  343. typedef
  344. INT32
  345. (*PTI_ROM_MEM_CONFIGURE) (
  346. PTI_ROM_MEM_DEVICE Device,
  347. VOID *Configuration
  348. );
  349. /*++
  350. Routine Description:
  351. This routine configures a ROM memory device.
  352. Arguments:
  353. Device - Supplies a pointer to the memory device.
  354. Configuration - Supplies a pointer to the configuration to set.
  355. Return Value:
  356. 0 on success.
  357. Non-zero on failure.
  358. --*/
  359. /*++
  360. Structure Description:
  361. This structure defines the TI ROM peripheral driver interface.
  362. Members:
  363. Initialize - Stores a pointer to a function used to initialize a memory
  364. device handle.
  365. Read - Stores a pointer to a function used to read from the device.
  366. Configure - Stores a pointer to a function used to configure the device.
  367. --*/
  368. typedef struct _TI_ROM_MEM_DRIVER {
  369. PTI_ROM_MEM_INITIALIZE Initialize;
  370. PTI_ROM_MEM_READ Read;
  371. PTI_ROM_MEM_CONFIGURE Configure;
  372. } TI_ROM_MEM_DRIVER, *PTI_ROM_MEM_DRIVER;
  373. typedef struct _TI_ROM_MMCSD_DEVICE_DATA {
  374. UINT32 ModuleId;
  375. UINT32 Type;
  376. UINT32 Mode;
  377. UINT32 Copy;
  378. UINT32 SpecificationVersion;
  379. UINT32 AddressingMode;
  380. UINT32 SupportedBusWidth;
  381. UINT32 Size;
  382. UINT32 Rca;
  383. UINT32 PartitionSize[TI_ROM_MMCSD_PARTITION_COUNT];
  384. UINT32 PartitionBoot[TI_ROM_MMCSD_PARTITION_COUNT];
  385. UINT8 Partition;
  386. } TI_ROM_MMCSD_DEVICE_DATA, *PTI_ROM_MMCSD_DEVICE_DATA;
  387. typedef
  388. INT32
  389. (*PTI_ROM_GET_MEM_DRIVER) (
  390. PTI_ROM_MEM_DRIVER *Driver,
  391. UINT32 DeviceType
  392. );
  393. /*++
  394. Routine Description:
  395. This routine gets a memory driver interface from the ROM.
  396. Arguments:
  397. Driver - Supplies a pointer where a pointer to the interface will be
  398. returned on success.
  399. DeviceType - Supplies the type of device to get the interface for.
  400. Return Value:
  401. 0 on success.
  402. Non-zero on failure.
  403. --*/
  404. /*++
  405. Structure Description:
  406. This structure defines a connection to the ROM USB peripheral interface.
  407. Members:
  408. ReadHandle - Stores the handle used for reading.
  409. WriteHandle - Stores the handle used for writing.
  410. Driver - Stores a pointer to the driver interface.
  411. --*/
  412. typedef struct _TI_ROM_USB_HANDLE {
  413. TI_ROM_PER_HANDLE ReadHandle;
  414. TI_ROM_PER_HANDLE WriteHandle;
  415. PTI_ROM_PER_DRIVER Driver;
  416. } TI_ROM_USB_HANDLE, *PTI_ROM_USB_HANDLE;
  417. /*++
  418. Structure Description:
  419. This structure defines a connection to the ROM memory device (like an SD
  420. card).
  421. Members:
  422. Device - Stores the device information.
  423. Driver - Stores a pointer to the driver interface.
  424. --*/
  425. typedef struct _TI_ROM_MEM_HANDLE {
  426. TI_ROM_MEM_DEVICE Device;
  427. PTI_ROM_MEM_DRIVER Driver;
  428. } TI_ROM_MEM_HANDLE, *PTI_ROM_MEM_HANDLE;
  429. //
  430. // -------------------------------------------------------------------- Globals
  431. //
  432. //
  433. // -------------------------------------------------------- Function Prototypes
  434. //
  435. INTN
  436. EfipTiMemOpen (
  437. UINT8 DeviceType,
  438. UINT32 ApiBase,
  439. VOID *DeviceData,
  440. PTI_ROM_MEM_HANDLE Handle
  441. );
  442. /*++
  443. Routine Description:
  444. This routine opens a connection to the ROM API for the memory device on
  445. OMAP4 and AM335x SoCs.
  446. Arguments:
  447. DeviceType - Supplies the device type to open.
  448. ApiBase - Supplies the base address of the public API area.
  449. DeviceData - Supplies the device data buffer.
  450. Handle - Supplies a pointer where the connection state will be returned
  451. on success.
  452. Return Value:
  453. 0 on success.
  454. Non-zero on failure.
  455. --*/
  456. INTN
  457. EfipTiMemRead (
  458. PTI_ROM_MEM_HANDLE Handle,
  459. UINT32 Sector,
  460. UINTN SectorCount,
  461. VOID *Data
  462. );
  463. /*++
  464. Routine Description:
  465. This routine reads from the memory device.
  466. Arguments:
  467. Handle - Supplies a pointer to the ROM handle.
  468. Sector - Supplies the sector to read from.
  469. SectorCount - Supplies the number of sectors to read.
  470. Data - Supplies a pointer where the data will be returned on success.
  471. Return Value:
  472. 0 on success.
  473. Non-zero on failure.
  474. --*/
  475. INTN
  476. EfipOmap4UsbOpen (
  477. PTI_ROM_USB_HANDLE Handle
  478. );
  479. /*++
  480. Routine Description:
  481. This routine opens a connection to the ROM API for the USB device.
  482. Arguments:
  483. Handle - Supplies a pointer where the connection state will be returned
  484. on success.
  485. Return Value:
  486. 0 on success.
  487. Non-zero on failure.
  488. --*/
  489. INTN
  490. EfipOmap4UsbRead (
  491. PTI_ROM_USB_HANDLE Handle,
  492. VOID *Data,
  493. UINTN Length
  494. );
  495. /*++
  496. Routine Description:
  497. This routine reads from the USB device.
  498. Arguments:
  499. Handle - Supplies a pointer to the ROM handle.
  500. Data - Supplies a pointer where the data will be returned on success.
  501. Length - Supplies the length of the buffer in bytes.
  502. Return Value:
  503. 0 on success.
  504. Non-zero on failure.
  505. --*/
  506. INTN
  507. EfipOmap4UsbWrite (
  508. PTI_ROM_USB_HANDLE Handle,
  509. VOID *Data,
  510. UINTN Length
  511. );
  512. /*++
  513. Routine Description:
  514. This routine writes to the USB device.
  515. Arguments:
  516. Handle - Supplies a pointer to the ROM handle.
  517. Data - Supplies a pointer to the data to write.
  518. Length - Supplies the length of the buffer in bytes.
  519. Return Value:
  520. 0 on success.
  521. Non-zero on failure.
  522. --*/
  523. VOID
  524. EfipOmap4UsbClose (
  525. PTI_ROM_USB_HANDLE Handle
  526. );
  527. /*++
  528. Routine Description:
  529. This routine closes an open handle to the USB device.
  530. Arguments:
  531. Handle - Supplies a pointer to the ROM handle.
  532. Return Value:
  533. None.
  534. --*/
  535. INTN
  536. EfipTiLoadFirmwareFromFat (
  537. PTI_ROM_MEM_HANDLE Handle,
  538. CHAR8 *FileName,
  539. VOID *LoadAddress,
  540. UINT32 *Length
  541. );
  542. /*++
  543. Routine Description:
  544. This routine loads the firmware from a FAT file system.
  545. Arguments:
  546. Handle - Supplies a pointer to the connection to the block device.
  547. FileName - Supplies a pointer to the null terminated name of the file.
  548. LoadAddress - Supplies the address where the image should be loaded.
  549. Length - Supplies a pointer where the length will be returned on success.
  550. Return Value:
  551. 0 on success.
  552. Non-zero on failure.
  553. --*/