nvram.c 15 KB

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