nvram.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. * Copyright (C) 2002 Benjamin Herrenschmidt (benh@kernel.crashing.org)
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Todo: - add support for the OF persistent properties
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/stddef.h>
  14. #include <linux/string.h>
  15. #include <linux/nvram.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/errno.h>
  19. #include <linux/adb.h>
  20. #include <linux/pmu.h>
  21. #include <linux/bootmem.h>
  22. #include <linux/completion.h>
  23. #include <linux/spinlock.h>
  24. #include <asm/sections.h>
  25. #include <asm/io.h>
  26. #include <asm/system.h>
  27. #include <asm/prom.h>
  28. #include <asm/machdep.h>
  29. #include <asm/nvram.h>
  30. #include "pmac.h"
  31. #define DEBUG
  32. #ifdef DEBUG
  33. #define DBG(x...) printk(x)
  34. #else
  35. #define DBG(x...)
  36. #endif
  37. #define NVRAM_SIZE 0x2000 /* 8kB of non-volatile RAM */
  38. #define CORE99_SIGNATURE 0x5a
  39. #define CORE99_ADLER_START 0x14
  40. /* On Core99, nvram is either a sharp, a micron or an AMD flash */
  41. #define SM_FLASH_STATUS_DONE 0x80
  42. #define SM_FLASH_STATUS_ERR 0x38
  43. #define SM_FLASH_CMD_ERASE_CONFIRM 0xd0
  44. #define SM_FLASH_CMD_ERASE_SETUP 0x20
  45. #define SM_FLASH_CMD_RESET 0xff
  46. #define SM_FLASH_CMD_WRITE_SETUP 0x40
  47. #define SM_FLASH_CMD_CLEAR_STATUS 0x50
  48. #define SM_FLASH_CMD_READ_STATUS 0x70
  49. /* CHRP NVRAM header */
  50. struct chrp_header {
  51. u8 signature;
  52. u8 cksum;
  53. u16 len;
  54. char name[12];
  55. u8 data[0];
  56. };
  57. struct core99_header {
  58. struct chrp_header hdr;
  59. u32 adler;
  60. u32 generation;
  61. u32 reserved[2];
  62. };
  63. /*
  64. * Read and write the non-volatile RAM on PowerMacs and CHRP machines.
  65. */
  66. static int nvram_naddrs;
  67. static volatile unsigned char __iomem *nvram_data;
  68. static int is_core_99;
  69. static int core99_bank = 0;
  70. static int nvram_partitions[3];
  71. // XXX Turn that into a sem
  72. static DEFINE_RAW_SPINLOCK(nv_lock);
  73. static int (*core99_write_bank)(int bank, u8* datas);
  74. static int (*core99_erase_bank)(int bank);
  75. static char *nvram_image;
  76. static unsigned char core99_nvram_read_byte(int addr)
  77. {
  78. if (nvram_image == NULL)
  79. return 0xff;
  80. return nvram_image[addr];
  81. }
  82. static void core99_nvram_write_byte(int addr, unsigned char val)
  83. {
  84. if (nvram_image == NULL)
  85. return;
  86. nvram_image[addr] = val;
  87. }
  88. static ssize_t core99_nvram_read(char *buf, size_t count, loff_t *index)
  89. {
  90. int i;
  91. if (nvram_image == NULL)
  92. return -ENODEV;
  93. if (*index > NVRAM_SIZE)
  94. return 0;
  95. i = *index;
  96. if (i + count > NVRAM_SIZE)
  97. count = NVRAM_SIZE - i;
  98. memcpy(buf, &nvram_image[i], count);
  99. *index = i + count;
  100. return count;
  101. }
  102. static ssize_t core99_nvram_write(char *buf, size_t count, loff_t *index)
  103. {
  104. int i;
  105. if (nvram_image == NULL)
  106. return -ENODEV;
  107. if (*index > NVRAM_SIZE)
  108. return 0;
  109. i = *index;
  110. if (i + count > NVRAM_SIZE)
  111. count = NVRAM_SIZE - i;
  112. memcpy(&nvram_image[i], buf, count);
  113. *index = i + count;
  114. return count;
  115. }
  116. static ssize_t core99_nvram_size(void)
  117. {
  118. if (nvram_image == NULL)
  119. return -ENODEV;
  120. return NVRAM_SIZE;
  121. }
  122. #ifdef CONFIG_PPC32
  123. static volatile unsigned char __iomem *nvram_addr;
  124. static int nvram_mult;
  125. static unsigned char direct_nvram_read_byte(int addr)
  126. {
  127. return in_8(&nvram_data[(addr & (NVRAM_SIZE - 1)) * nvram_mult]);
  128. }
  129. static void direct_nvram_write_byte(int addr, unsigned char val)
  130. {
  131. out_8(&nvram_data[(addr & (NVRAM_SIZE - 1)) * nvram_mult], val);
  132. }
  133. static unsigned char indirect_nvram_read_byte(int addr)
  134. {
  135. unsigned char val;
  136. unsigned long flags;
  137. raw_spin_lock_irqsave(&nv_lock, flags);
  138. out_8(nvram_addr, addr >> 5);
  139. val = in_8(&nvram_data[(addr & 0x1f) << 4]);
  140. raw_spin_unlock_irqrestore(&nv_lock, flags);
  141. return val;
  142. }
  143. static void indirect_nvram_write_byte(int addr, unsigned char val)
  144. {
  145. unsigned long flags;
  146. raw_spin_lock_irqsave(&nv_lock, flags);
  147. out_8(nvram_addr, addr >> 5);
  148. out_8(&nvram_data[(addr & 0x1f) << 4], val);
  149. raw_spin_unlock_irqrestore(&nv_lock, flags);
  150. }
  151. #ifdef CONFIG_ADB_PMU
  152. static void pmu_nvram_complete(struct adb_request *req)
  153. {
  154. if (req->arg)
  155. complete((struct completion *)req->arg);
  156. }
  157. static unsigned char pmu_nvram_read_byte(int addr)
  158. {
  159. struct adb_request req;
  160. DECLARE_COMPLETION_ONSTACK(req_complete);
  161. req.arg = system_state == SYSTEM_RUNNING ? &req_complete : NULL;
  162. if (pmu_request(&req, pmu_nvram_complete, 3, PMU_READ_NVRAM,
  163. (addr >> 8) & 0xff, addr & 0xff))
  164. return 0xff;
  165. if (system_state == SYSTEM_RUNNING)
  166. wait_for_completion(&req_complete);
  167. while (!req.complete)
  168. pmu_poll();
  169. return req.reply[0];
  170. }
  171. static void pmu_nvram_write_byte(int addr, unsigned char val)
  172. {
  173. struct adb_request req;
  174. DECLARE_COMPLETION_ONSTACK(req_complete);
  175. req.arg = system_state == SYSTEM_RUNNING ? &req_complete : NULL;
  176. if (pmu_request(&req, pmu_nvram_complete, 4, PMU_WRITE_NVRAM,
  177. (addr >> 8) & 0xff, addr & 0xff, val))
  178. return;
  179. if (system_state == SYSTEM_RUNNING)
  180. wait_for_completion(&req_complete);
  181. while (!req.complete)
  182. pmu_poll();
  183. }
  184. #endif /* CONFIG_ADB_PMU */
  185. #endif /* CONFIG_PPC32 */
  186. static u8 chrp_checksum(struct chrp_header* hdr)
  187. {
  188. u8 *ptr;
  189. u16 sum = hdr->signature;
  190. for (ptr = (u8 *)&hdr->len; ptr < hdr->data; ptr++)
  191. sum += *ptr;
  192. while (sum > 0xFF)
  193. sum = (sum & 0xFF) + (sum>>8);
  194. return sum;
  195. }
  196. static u32 core99_calc_adler(u8 *buffer)
  197. {
  198. int cnt;
  199. u32 low, high;
  200. buffer += CORE99_ADLER_START;
  201. low = 1;
  202. high = 0;
  203. for (cnt=0; cnt<(NVRAM_SIZE-CORE99_ADLER_START); cnt++) {
  204. if ((cnt % 5000) == 0) {
  205. high %= 65521UL;
  206. high %= 65521UL;
  207. }
  208. low += buffer[cnt];
  209. high += low;
  210. }
  211. low %= 65521UL;
  212. high %= 65521UL;
  213. return (high << 16) | low;
  214. }
  215. static u32 core99_check(u8* datas)
  216. {
  217. struct core99_header* hdr99 = (struct core99_header*)datas;
  218. if (hdr99->hdr.signature != CORE99_SIGNATURE) {
  219. DBG("Invalid signature\n");
  220. return 0;
  221. }
  222. if (hdr99->hdr.cksum != chrp_checksum(&hdr99->hdr)) {
  223. DBG("Invalid checksum\n");
  224. return 0;
  225. }
  226. if (hdr99->adler != core99_calc_adler(datas)) {
  227. DBG("Invalid adler\n");
  228. return 0;
  229. }
  230. return hdr99->generation;
  231. }
  232. static int sm_erase_bank(int bank)
  233. {
  234. int stat, i;
  235. unsigned long timeout;
  236. u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
  237. DBG("nvram: Sharp/Micron Erasing bank %d...\n", bank);
  238. out_8(base, SM_FLASH_CMD_ERASE_SETUP);
  239. out_8(base, SM_FLASH_CMD_ERASE_CONFIRM);
  240. timeout = 0;
  241. do {
  242. if (++timeout > 1000000) {
  243. printk(KERN_ERR "nvram: Sharp/Micron flash erase timeout !\n");
  244. break;
  245. }
  246. out_8(base, SM_FLASH_CMD_READ_STATUS);
  247. stat = in_8(base);
  248. } while (!(stat & SM_FLASH_STATUS_DONE));
  249. out_8(base, SM_FLASH_CMD_CLEAR_STATUS);
  250. out_8(base, SM_FLASH_CMD_RESET);
  251. for (i=0; i<NVRAM_SIZE; i++)
  252. if (base[i] != 0xff) {
  253. printk(KERN_ERR "nvram: Sharp/Micron flash erase failed !\n");
  254. return -ENXIO;
  255. }
  256. return 0;
  257. }
  258. static int sm_write_bank(int bank, u8* datas)
  259. {
  260. int i, stat = 0;
  261. unsigned long timeout;
  262. u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
  263. DBG("nvram: Sharp/Micron Writing bank %d...\n", bank);
  264. for (i=0; i<NVRAM_SIZE; i++) {
  265. out_8(base+i, SM_FLASH_CMD_WRITE_SETUP);
  266. udelay(1);
  267. out_8(base+i, datas[i]);
  268. timeout = 0;
  269. do {
  270. if (++timeout > 1000000) {
  271. printk(KERN_ERR "nvram: Sharp/Micron flash write timeout !\n");
  272. break;
  273. }
  274. out_8(base, SM_FLASH_CMD_READ_STATUS);
  275. stat = in_8(base);
  276. } while (!(stat & SM_FLASH_STATUS_DONE));
  277. if (!(stat & SM_FLASH_STATUS_DONE))
  278. break;
  279. }
  280. out_8(base, SM_FLASH_CMD_CLEAR_STATUS);
  281. out_8(base, SM_FLASH_CMD_RESET);
  282. for (i=0; i<NVRAM_SIZE; i++)
  283. if (base[i] != datas[i]) {
  284. printk(KERN_ERR "nvram: Sharp/Micron flash write failed !\n");
  285. return -ENXIO;
  286. }
  287. return 0;
  288. }
  289. static int amd_erase_bank(int bank)
  290. {
  291. int i, stat = 0;
  292. unsigned long timeout;
  293. u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
  294. DBG("nvram: AMD Erasing bank %d...\n", bank);
  295. /* Unlock 1 */
  296. out_8(base+0x555, 0xaa);
  297. udelay(1);
  298. /* Unlock 2 */
  299. out_8(base+0x2aa, 0x55);
  300. udelay(1);
  301. /* Sector-Erase */
  302. out_8(base+0x555, 0x80);
  303. udelay(1);
  304. out_8(base+0x555, 0xaa);
  305. udelay(1);
  306. out_8(base+0x2aa, 0x55);
  307. udelay(1);
  308. out_8(base, 0x30);
  309. udelay(1);
  310. timeout = 0;
  311. do {
  312. if (++timeout > 1000000) {
  313. printk(KERN_ERR "nvram: AMD flash erase timeout !\n");
  314. break;
  315. }
  316. stat = in_8(base) ^ in_8(base);
  317. } while (stat != 0);
  318. /* Reset */
  319. out_8(base, 0xf0);
  320. udelay(1);
  321. for (i=0; i<NVRAM_SIZE; i++)
  322. if (base[i] != 0xff) {
  323. printk(KERN_ERR "nvram: AMD flash erase failed !\n");
  324. return -ENXIO;
  325. }
  326. return 0;
  327. }
  328. static int amd_write_bank(int bank, u8* datas)
  329. {
  330. int i, stat = 0;
  331. unsigned long timeout;
  332. u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
  333. DBG("nvram: AMD Writing bank %d...\n", bank);
  334. for (i=0; i<NVRAM_SIZE; i++) {
  335. /* Unlock 1 */
  336. out_8(base+0x555, 0xaa);
  337. udelay(1);
  338. /* Unlock 2 */
  339. out_8(base+0x2aa, 0x55);
  340. udelay(1);
  341. /* Write single word */
  342. out_8(base+0x555, 0xa0);
  343. udelay(1);
  344. out_8(base+i, datas[i]);
  345. timeout = 0;
  346. do {
  347. if (++timeout > 1000000) {
  348. printk(KERN_ERR "nvram: AMD flash write timeout !\n");
  349. break;
  350. }
  351. stat = in_8(base) ^ in_8(base);
  352. } while (stat != 0);
  353. if (stat != 0)
  354. break;
  355. }
  356. /* Reset */
  357. out_8(base, 0xf0);
  358. udelay(1);
  359. for (i=0; i<NVRAM_SIZE; i++)
  360. if (base[i] != datas[i]) {
  361. printk(KERN_ERR "nvram: AMD flash write failed !\n");
  362. return -ENXIO;
  363. }
  364. return 0;
  365. }
  366. static void __init lookup_partitions(void)
  367. {
  368. u8 buffer[17];
  369. int i, offset;
  370. struct chrp_header* hdr;
  371. if (pmac_newworld) {
  372. nvram_partitions[pmac_nvram_OF] = -1;
  373. nvram_partitions[pmac_nvram_XPRAM] = -1;
  374. nvram_partitions[pmac_nvram_NR] = -1;
  375. hdr = (struct chrp_header *)buffer;
  376. offset = 0;
  377. buffer[16] = 0;
  378. do {
  379. for (i=0;i<16;i++)
  380. buffer[i] = ppc_md.nvram_read_val(offset+i);
  381. if (!strcmp(hdr->name, "common"))
  382. nvram_partitions[pmac_nvram_OF] = offset + 0x10;
  383. if (!strcmp(hdr->name, "APL,MacOS75")) {
  384. nvram_partitions[pmac_nvram_XPRAM] = offset + 0x10;
  385. nvram_partitions[pmac_nvram_NR] = offset + 0x110;
  386. }
  387. offset += (hdr->len * 0x10);
  388. } while(offset < NVRAM_SIZE);
  389. } else {
  390. nvram_partitions[pmac_nvram_OF] = 0x1800;
  391. nvram_partitions[pmac_nvram_XPRAM] = 0x1300;
  392. nvram_partitions[pmac_nvram_NR] = 0x1400;
  393. }
  394. DBG("nvram: OF partition at 0x%x\n", nvram_partitions[pmac_nvram_OF]);
  395. DBG("nvram: XP partition at 0x%x\n", nvram_partitions[pmac_nvram_XPRAM]);
  396. DBG("nvram: NR partition at 0x%x\n", nvram_partitions[pmac_nvram_NR]);
  397. }
  398. static void core99_nvram_sync(void)
  399. {
  400. struct core99_header* hdr99;
  401. unsigned long flags;
  402. if (!is_core_99 || !nvram_data || !nvram_image)
  403. return;
  404. raw_spin_lock_irqsave(&nv_lock, flags);
  405. if (!memcmp(nvram_image, (u8*)nvram_data + core99_bank*NVRAM_SIZE,
  406. NVRAM_SIZE))
  407. goto bail;
  408. DBG("Updating nvram...\n");
  409. hdr99 = (struct core99_header*)nvram_image;
  410. hdr99->generation++;
  411. hdr99->hdr.signature = CORE99_SIGNATURE;
  412. hdr99->hdr.cksum = chrp_checksum(&hdr99->hdr);
  413. hdr99->adler = core99_calc_adler(nvram_image);
  414. core99_bank = core99_bank ? 0 : 1;
  415. if (core99_erase_bank)
  416. if (core99_erase_bank(core99_bank)) {
  417. printk("nvram: Error erasing bank %d\n", core99_bank);
  418. goto bail;
  419. }
  420. if (core99_write_bank)
  421. if (core99_write_bank(core99_bank, nvram_image))
  422. printk("nvram: Error writing bank %d\n", core99_bank);
  423. bail:
  424. raw_spin_unlock_irqrestore(&nv_lock, flags);
  425. #ifdef DEBUG
  426. mdelay(2000);
  427. #endif
  428. }
  429. static int __init core99_nvram_setup(struct device_node *dp, unsigned long addr)
  430. {
  431. int i;
  432. u32 gen_bank0, gen_bank1;
  433. if (nvram_naddrs < 1) {
  434. printk(KERN_ERR "nvram: no address\n");
  435. return -EINVAL;
  436. }
  437. nvram_image = alloc_bootmem(NVRAM_SIZE);
  438. if (nvram_image == NULL) {
  439. printk(KERN_ERR "nvram: can't allocate ram image\n");
  440. return -ENOMEM;
  441. }
  442. nvram_data = ioremap(addr, NVRAM_SIZE*2);
  443. nvram_naddrs = 1; /* Make sure we get the correct case */
  444. DBG("nvram: Checking bank 0...\n");
  445. gen_bank0 = core99_check((u8 *)nvram_data);
  446. gen_bank1 = core99_check((u8 *)nvram_data + NVRAM_SIZE);
  447. core99_bank = (gen_bank0 < gen_bank1) ? 1 : 0;
  448. DBG("nvram: gen0=%d, gen1=%d\n", gen_bank0, gen_bank1);
  449. DBG("nvram: Active bank is: %d\n", core99_bank);
  450. for (i=0; i<NVRAM_SIZE; i++)
  451. nvram_image[i] = nvram_data[i + core99_bank*NVRAM_SIZE];
  452. ppc_md.nvram_read_val = core99_nvram_read_byte;
  453. ppc_md.nvram_write_val = core99_nvram_write_byte;
  454. ppc_md.nvram_read = core99_nvram_read;
  455. ppc_md.nvram_write = core99_nvram_write;
  456. ppc_md.nvram_size = core99_nvram_size;
  457. ppc_md.nvram_sync = core99_nvram_sync;
  458. ppc_md.machine_shutdown = core99_nvram_sync;
  459. /*
  460. * Maybe we could be smarter here though making an exclusive list
  461. * of known flash chips is a bit nasty as older OF didn't provide us
  462. * with a useful "compatible" entry. A solution would be to really
  463. * identify the chip using flash id commands and base ourselves on
  464. * a list of known chips IDs
  465. */
  466. if (of_device_is_compatible(dp, "amd-0137")) {
  467. core99_erase_bank = amd_erase_bank;
  468. core99_write_bank = amd_write_bank;
  469. } else {
  470. core99_erase_bank = sm_erase_bank;
  471. core99_write_bank = sm_write_bank;
  472. }
  473. return 0;
  474. }
  475. int __init pmac_nvram_init(void)
  476. {
  477. struct device_node *dp;
  478. struct resource r1, r2;
  479. unsigned int s1 = 0, s2 = 0;
  480. int err = 0;
  481. nvram_naddrs = 0;
  482. dp = of_find_node_by_name(NULL, "nvram");
  483. if (dp == NULL) {
  484. printk(KERN_ERR "Can't find NVRAM device\n");
  485. return -ENODEV;
  486. }
  487. /* Try to obtain an address */
  488. if (of_address_to_resource(dp, 0, &r1) == 0) {
  489. nvram_naddrs = 1;
  490. s1 = (r1.end - r1.start) + 1;
  491. if (of_address_to_resource(dp, 1, &r2) == 0) {
  492. nvram_naddrs = 2;
  493. s2 = (r2.end - r2.start) + 1;
  494. }
  495. }
  496. is_core_99 = of_device_is_compatible(dp, "nvram,flash");
  497. if (is_core_99) {
  498. err = core99_nvram_setup(dp, r1.start);
  499. goto bail;
  500. }
  501. #ifdef CONFIG_PPC32
  502. if (machine_is(chrp) && nvram_naddrs == 1) {
  503. nvram_data = ioremap(r1.start, s1);
  504. nvram_mult = 1;
  505. ppc_md.nvram_read_val = direct_nvram_read_byte;
  506. ppc_md.nvram_write_val = direct_nvram_write_byte;
  507. } else if (nvram_naddrs == 1) {
  508. nvram_data = ioremap(r1.start, s1);
  509. nvram_mult = (s1 + NVRAM_SIZE - 1) / NVRAM_SIZE;
  510. ppc_md.nvram_read_val = direct_nvram_read_byte;
  511. ppc_md.nvram_write_val = direct_nvram_write_byte;
  512. } else if (nvram_naddrs == 2) {
  513. nvram_addr = ioremap(r1.start, s1);
  514. nvram_data = ioremap(r2.start, s2);
  515. ppc_md.nvram_read_val = indirect_nvram_read_byte;
  516. ppc_md.nvram_write_val = indirect_nvram_write_byte;
  517. } else if (nvram_naddrs == 0 && sys_ctrler == SYS_CTRLER_PMU) {
  518. #ifdef CONFIG_ADB_PMU
  519. nvram_naddrs = -1;
  520. ppc_md.nvram_read_val = pmu_nvram_read_byte;
  521. ppc_md.nvram_write_val = pmu_nvram_write_byte;
  522. #endif /* CONFIG_ADB_PMU */
  523. } else {
  524. printk(KERN_ERR "Incompatible type of NVRAM\n");
  525. err = -ENXIO;
  526. }
  527. #endif /* CONFIG_PPC32 */
  528. bail:
  529. of_node_put(dp);
  530. if (err == 0)
  531. lookup_partitions();
  532. return err;
  533. }
  534. int pmac_get_partition(int partition)
  535. {
  536. return nvram_partitions[partition];
  537. }
  538. u8 pmac_xpram_read(int xpaddr)
  539. {
  540. int offset = pmac_get_partition(pmac_nvram_XPRAM);
  541. if (offset < 0 || xpaddr < 0 || xpaddr > 0x100)
  542. return 0xff;
  543. return ppc_md.nvram_read_val(xpaddr + offset);
  544. }
  545. void pmac_xpram_write(int xpaddr, u8 data)
  546. {
  547. int offset = pmac_get_partition(pmac_nvram_XPRAM);
  548. if (offset < 0 || xpaddr < 0 || xpaddr > 0x100)
  549. return;
  550. ppc_md.nvram_write_val(xpaddr + offset, data);
  551. }
  552. EXPORT_SYMBOL(pmac_get_partition);
  553. EXPORT_SYMBOL(pmac_xpram_read);
  554. EXPORT_SYMBOL(pmac_xpram_write);