nvram.c 15 KB

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