firmware_abi.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #ifndef FIRMWARE_ABI_H
  2. #define FIRMWARE_ABI_H
  3. #ifndef __ASSEMBLY__
  4. /* Open Hack'Ware NVRAM configuration structure */
  5. /* Version 3 */
  6. typedef struct ohwcfg_v3_t ohwcfg_v3_t;
  7. struct ohwcfg_v3_t {
  8. /* 0x00: structure identifier */
  9. uint8_t struct_ident[0x10];
  10. /* 0x10: structure version and NVRAM description */
  11. uint32_t struct_version;
  12. uint16_t nvram_size;
  13. uint16_t pad0;
  14. uint16_t nvram_arch_ptr;
  15. uint16_t nvram_arch_size;
  16. uint16_t nvram_arch_crc;
  17. uint8_t pad1[0x02];
  18. /* 0x20: host architecture */
  19. uint8_t arch[0x10];
  20. /* 0x30: RAM/ROM description */
  21. uint64_t RAM0_base;
  22. uint64_t RAM0_size;
  23. uint64_t RAM1_base;
  24. uint64_t RAM1_size;
  25. uint64_t RAM2_base;
  26. uint64_t RAM2_size;
  27. uint64_t RAM3_base;
  28. uint64_t RAM3_size;
  29. uint64_t ROM_base;
  30. uint64_t ROM_size;
  31. /* 0x80: Kernel description */
  32. uint64_t kernel_image;
  33. uint64_t kernel_size;
  34. /* 0x90: Kernel command line */
  35. uint64_t cmdline;
  36. uint64_t cmdline_size;
  37. /* 0xA0: Kernel boot image */
  38. uint64_t initrd_image;
  39. uint64_t initrd_size;
  40. /* 0xB0: NVRAM image */
  41. uint64_t NVRAM_image;
  42. uint8_t pad2[8];
  43. /* 0xC0: graphic configuration */
  44. uint16_t width;
  45. uint16_t height;
  46. uint16_t depth;
  47. uint16_t graphic_flags;
  48. /* 0xC8: CPUs description */
  49. uint8_t nb_cpus;
  50. uint8_t boot_cpu;
  51. uint8_t nboot_devices;
  52. uint8_t pad3[5];
  53. /* 0xD0: boot devices */
  54. uint8_t boot_devices[0x10];
  55. /* 0xE0 */
  56. uint8_t pad4[0x1C]; /* 28 */
  57. /* 0xFC: checksum */
  58. uint16_t crc;
  59. uint8_t pad5[0x02];
  60. } __attribute__ (( packed ));
  61. #define OHW_GF_NOGRAPHICS 0x0001
  62. static inline uint16_t
  63. OHW_crc_update (uint16_t prev, uint16_t value)
  64. {
  65. uint16_t tmp;
  66. uint16_t pd, pd1, pd2;
  67. tmp = prev >> 8;
  68. pd = prev ^ value;
  69. pd1 = pd & 0x000F;
  70. pd2 = ((pd >> 4) & 0x000F) ^ pd1;
  71. tmp ^= (pd1 << 3) | (pd1 << 8);
  72. tmp ^= pd2 | (pd2 << 7) | (pd2 << 12);
  73. return tmp;
  74. }
  75. static inline uint16_t
  76. OHW_compute_crc (ohwcfg_v3_t *header, uint32_t start, uint32_t count)
  77. {
  78. uint32_t i;
  79. uint16_t crc = 0xFFFF;
  80. uint8_t *ptr = (uint8_t *)header;
  81. int odd;
  82. odd = count & 1;
  83. count &= ~1;
  84. for (i = 0; i != count; i++) {
  85. crc = OHW_crc_update(crc, (ptr[start + i] << 8) | ptr[start + i + 1]);
  86. }
  87. if (odd) {
  88. crc = OHW_crc_update(crc, ptr[start + i] << 8);
  89. }
  90. return crc;
  91. }
  92. /* Sparc32 runtime NVRAM structure for SMP CPU boot */
  93. struct sparc_arch_cfg {
  94. uint32_t smp_ctx;
  95. uint32_t smp_ctxtbl;
  96. uint32_t smp_entry;
  97. uint8_t valid;
  98. uint8_t unused[51];
  99. };
  100. /* OpenBIOS NVRAM partition */
  101. struct OpenBIOS_nvpart_v1 {
  102. uint8_t signature;
  103. uint8_t checksum;
  104. uint16_t len; // BE, length divided by 16
  105. char name[12];
  106. };
  107. #define OPENBIOS_PART_SYSTEM 0x70
  108. #define OPENBIOS_PART_FREE 0x7f
  109. static inline void
  110. OpenBIOS_finish_partition(struct OpenBIOS_nvpart_v1 *header, uint32_t size)
  111. {
  112. unsigned int i, sum;
  113. uint8_t *tmpptr;
  114. // Length divided by 16
  115. header->len = cpu_to_be16(size >> 4);
  116. // Checksum
  117. tmpptr = (uint8_t *)header;
  118. sum = *tmpptr;
  119. for (i = 0; i < 14; i++) {
  120. sum += tmpptr[2 + i];
  121. sum = (sum + ((sum & 0xff00) >> 8)) & 0xff;
  122. }
  123. header->checksum = sum & 0xff;
  124. }
  125. static inline uint32_t
  126. OpenBIOS_set_var(uint8_t *nvram, uint32_t addr, const char *str)
  127. {
  128. uint32_t len;
  129. len = strlen(str) + 1;
  130. memcpy(&nvram[addr], str, len);
  131. return addr + len;
  132. }
  133. /* Sun IDPROM structure at the end of NVRAM */
  134. struct Sun_nvram {
  135. uint8_t type;
  136. uint8_t machine_id;
  137. uint8_t macaddr[6];
  138. uint8_t unused[7];
  139. uint8_t checksum;
  140. };
  141. static inline void
  142. Sun_init_header(struct Sun_nvram *header, const uint8_t *macaddr, int machine_id)
  143. {
  144. uint8_t tmp, *tmpptr;
  145. unsigned int i;
  146. header->type = 1;
  147. header->machine_id = machine_id & 0xff;
  148. memcpy(&header->macaddr, macaddr, 6);
  149. /* Calculate checksum */
  150. tmp = 0;
  151. tmpptr = (uint8_t *)header;
  152. for (i = 0; i < 15; i++)
  153. tmp ^= tmpptr[i];
  154. header->checksum = tmp;
  155. }
  156. #else /* __ASSEMBLY__ */
  157. /* Structure offsets for asm use */
  158. /* Open Hack'Ware NVRAM configuration structure */
  159. #define OHW_ARCH_PTR 0x18
  160. #define OHW_RAM_SIZE 0x38
  161. #define OHW_BOOT_CPU 0xC9
  162. /* Sparc32 runtime NVRAM structure for SMP CPU boot */
  163. #define SPARC_SMP_CTX 0x0
  164. #define SPARC_SMP_CTXTBL 0x4
  165. #define SPARC_SMP_ENTRY 0x8
  166. #define SPARC_SMP_VALID 0xc
  167. /* Sun IDPROM structure at the end of NVRAM */
  168. #define SPARC_MACHINE_ID 0x1fd9
  169. #endif /* __ASSEMBLY__ */
  170. #endif /* FIRMWARE_ABI_H */