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