tirom.h 16 KB

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