os-area.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * PS3 'Other OS' area data.
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006 Sony Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/io.h>
  22. #include <asm/lmb.h>
  23. #include "platform.h"
  24. enum {
  25. OS_AREA_SEGMENT_SIZE = 0X200,
  26. };
  27. enum {
  28. HEADER_LDR_FORMAT_RAW = 0,
  29. HEADER_LDR_FORMAT_GZIP = 1,
  30. };
  31. /**
  32. * struct os_area_header - os area header segment.
  33. * @magic_num: Always 'cell_ext_os_area'.
  34. * @hdr_version: Header format version number.
  35. * @os_area_offset: Starting segment number of os image area.
  36. * @ldr_area_offset: Starting segment number of bootloader image area.
  37. * @ldr_format: HEADER_LDR_FORMAT flag.
  38. * @ldr_size: Size of bootloader image in bytes.
  39. *
  40. * Note that the docs refer to area offsets. These are offsets in units of
  41. * segments from the start of the os area (top of the header). These are
  42. * better thought of as segment numbers. The os area of the os area is
  43. * reserved for the os image.
  44. */
  45. struct os_area_header {
  46. s8 magic_num[16];
  47. u32 hdr_version;
  48. u32 os_area_offset;
  49. u32 ldr_area_offset;
  50. u32 _reserved_1;
  51. u32 ldr_format;
  52. u32 ldr_size;
  53. u32 _reserved_2[6];
  54. };
  55. enum {
  56. PARAM_BOOT_FLAG_GAME_OS = 0,
  57. PARAM_BOOT_FLAG_OTHER_OS = 1,
  58. };
  59. enum {
  60. PARAM_CTRL_BUTTON_O_IS_YES = 0,
  61. PARAM_CTRL_BUTTON_X_IS_YES = 1,
  62. };
  63. /**
  64. * struct os_area_params - os area params segment.
  65. * @boot_flag: User preference of operating system, PARAM_BOOT_FLAG flag.
  66. * @num_params: Number of params in this (params) segment.
  67. * @rtc_diff: Difference in seconds between 1970 and the ps3 rtc value.
  68. * @av_multi_out: User preference of AV output, PARAM_AV_MULTI_OUT flag.
  69. * @ctrl_button: User preference of controller button config, PARAM_CTRL_BUTTON
  70. * flag.
  71. * @static_ip_addr: User preference of static IP address.
  72. * @network_mask: User preference of static network mask.
  73. * @default_gateway: User preference of static default gateway.
  74. * @dns_primary: User preference of static primary dns server.
  75. * @dns_secondary: User preference of static secondary dns server.
  76. *
  77. * User preference of zero for static_ip_addr means use dhcp.
  78. */
  79. struct os_area_params {
  80. u32 boot_flag;
  81. u32 _reserved_1[3];
  82. u32 num_params;
  83. u32 _reserved_2[3];
  84. /* param 0 */
  85. s64 rtc_diff;
  86. u8 av_multi_out;
  87. u8 ctrl_button;
  88. u8 _reserved_3[6];
  89. /* param 1 */
  90. u8 static_ip_addr[4];
  91. u8 network_mask[4];
  92. u8 default_gateway[4];
  93. u8 _reserved_4[4];
  94. /* param 2 */
  95. u8 dns_primary[4];
  96. u8 dns_secondary[4];
  97. u8 _reserved_5[8];
  98. };
  99. /**
  100. * struct saved_params - Static working copies of data from the 'Other OS' area.
  101. *
  102. * For the convinience of the guest, the HV makes a copy of the 'Other OS' area
  103. * in flash to a high address in the boot memory region and then puts that RAM
  104. * address and the byte count into the repository for retreval by the guest.
  105. * We copy the data we want into a static variable and allow the memory setup
  106. * by the HV to be claimed by the lmb manager.
  107. */
  108. struct saved_params {
  109. /* param 0 */
  110. s64 rtc_diff;
  111. unsigned int av_multi_out;
  112. unsigned int ctrl_button;
  113. /* param 1 */
  114. u8 static_ip_addr[4];
  115. u8 network_mask[4];
  116. u8 default_gateway[4];
  117. /* param 2 */
  118. u8 dns_primary[4];
  119. u8 dns_secondary[4];
  120. } static saved_params;
  121. #define dump_header(_a) _dump_header(_a, __func__, __LINE__)
  122. static void _dump_header(const struct os_area_header __iomem *h, const char* func,
  123. int line)
  124. {
  125. pr_debug("%s:%d: h.magic_num: '%s'\n", func, line,
  126. h->magic_num);
  127. pr_debug("%s:%d: h.hdr_version: %u\n", func, line,
  128. h->hdr_version);
  129. pr_debug("%s:%d: h.os_area_offset: %u\n", func, line,
  130. h->os_area_offset);
  131. pr_debug("%s:%d: h.ldr_area_offset: %u\n", func, line,
  132. h->ldr_area_offset);
  133. pr_debug("%s:%d: h.ldr_format: %u\n", func, line,
  134. h->ldr_format);
  135. pr_debug("%s:%d: h.ldr_size: %xh\n", func, line,
  136. h->ldr_size);
  137. }
  138. #define dump_params(_a) _dump_params(_a, __func__, __LINE__)
  139. static void _dump_params(const struct os_area_params __iomem *p, const char* func,
  140. int line)
  141. {
  142. pr_debug("%s:%d: p.boot_flag: %u\n", func, line, p->boot_flag);
  143. pr_debug("%s:%d: p.num_params: %u\n", func, line, p->num_params);
  144. pr_debug("%s:%d: p.rtc_diff %ld\n", func, line, p->rtc_diff);
  145. pr_debug("%s:%d: p.av_multi_out %u\n", func, line, p->av_multi_out);
  146. pr_debug("%s:%d: p.ctrl_button: %u\n", func, line, p->ctrl_button);
  147. pr_debug("%s:%d: p.static_ip_addr: %u.%u.%u.%u\n", func, line,
  148. p->static_ip_addr[0], p->static_ip_addr[1],
  149. p->static_ip_addr[2], p->static_ip_addr[3]);
  150. pr_debug("%s:%d: p.network_mask: %u.%u.%u.%u\n", func, line,
  151. p->network_mask[0], p->network_mask[1],
  152. p->network_mask[2], p->network_mask[3]);
  153. pr_debug("%s:%d: p.default_gateway: %u.%u.%u.%u\n", func, line,
  154. p->default_gateway[0], p->default_gateway[1],
  155. p->default_gateway[2], p->default_gateway[3]);
  156. pr_debug("%s:%d: p.dns_primary: %u.%u.%u.%u\n", func, line,
  157. p->dns_primary[0], p->dns_primary[1],
  158. p->dns_primary[2], p->dns_primary[3]);
  159. pr_debug("%s:%d: p.dns_secondary: %u.%u.%u.%u\n", func, line,
  160. p->dns_secondary[0], p->dns_secondary[1],
  161. p->dns_secondary[2], p->dns_secondary[3]);
  162. }
  163. static int __init verify_header(const struct os_area_header *header)
  164. {
  165. if (memcmp(header->magic_num, "cell_ext_os_area", 16)) {
  166. pr_debug("%s:%d magic_num failed\n", __func__, __LINE__);
  167. return -1;
  168. }
  169. if (header->hdr_version < 1) {
  170. pr_debug("%s:%d hdr_version failed\n", __func__, __LINE__);
  171. return -1;
  172. }
  173. if (header->os_area_offset > header->ldr_area_offset) {
  174. pr_debug("%s:%d offsets failed\n", __func__, __LINE__);
  175. return -1;
  176. }
  177. return 0;
  178. }
  179. int __init ps3_os_area_init(void)
  180. {
  181. int result;
  182. u64 lpar_addr;
  183. unsigned int size;
  184. struct os_area_header *header;
  185. struct os_area_params *params;
  186. result = ps3_repository_read_boot_dat_info(&lpar_addr, &size);
  187. if (result) {
  188. pr_debug("%s:%d ps3_repository_read_boot_dat_info failed\n",
  189. __func__, __LINE__);
  190. return result;
  191. }
  192. header = (struct os_area_header *)__va(lpar_addr);
  193. params = (struct os_area_params *)__va(lpar_addr + OS_AREA_SEGMENT_SIZE);
  194. result = verify_header(header);
  195. if (result) {
  196. pr_debug("%s:%d verify_header failed\n", __func__, __LINE__);
  197. dump_header(header);
  198. return -EIO;
  199. }
  200. dump_header(header);
  201. dump_params(params);
  202. saved_params.rtc_diff = params->rtc_diff;
  203. saved_params.av_multi_out = params->av_multi_out;
  204. saved_params.ctrl_button = params->ctrl_button;
  205. memcpy(saved_params.static_ip_addr, params->static_ip_addr, 4);
  206. memcpy(saved_params.network_mask, params->network_mask, 4);
  207. memcpy(saved_params.default_gateway, params->default_gateway, 4);
  208. memcpy(saved_params.dns_secondary, params->dns_secondary, 4);
  209. return result;
  210. }
  211. /**
  212. * ps3_os_area_rtc_diff - Returns the ps3 rtc diff value.
  213. *
  214. * The ps3 rtc maintains a value that approximates seconds since
  215. * 2000-01-01 00:00:00 UTC. Returns the exact number of seconds from 1970 to
  216. * 2000 when saved_params.rtc_diff has not been properly set up.
  217. */
  218. u64 ps3_os_area_rtc_diff(void)
  219. {
  220. return saved_params.rtc_diff ? saved_params.rtc_diff : 946684800UL;
  221. }
  222. /**
  223. * ps3_os_area_get_av_multi_out - Returns the default video mode.
  224. */
  225. enum ps3_param_av_multi_out ps3_os_area_get_av_multi_out(void)
  226. {
  227. return saved_params.av_multi_out;
  228. }
  229. EXPORT_SYMBOL_GPL(ps3_os_area_get_av_multi_out);