nvram.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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/export.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;
  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. if (memchr_inv(base, 0xff, NVRAM_SIZE)) {
  252. printk(KERN_ERR "nvram: Sharp/Micron flash erase failed !\n");
  253. return -ENXIO;
  254. }
  255. return 0;
  256. }
  257. static int sm_write_bank(int bank, u8* datas)
  258. {
  259. int i, stat = 0;
  260. unsigned long timeout;
  261. u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
  262. DBG("nvram: Sharp/Micron Writing bank %d...\n", bank);
  263. for (i=0; i<NVRAM_SIZE; i++) {
  264. out_8(base+i, SM_FLASH_CMD_WRITE_SETUP);
  265. udelay(1);
  266. out_8(base+i, datas[i]);
  267. timeout = 0;
  268. do {
  269. if (++timeout > 1000000) {
  270. printk(KERN_ERR "nvram: Sharp/Micron flash write timeout !\n");
  271. break;
  272. }
  273. out_8(base, SM_FLASH_CMD_READ_STATUS);
  274. stat = in_8(base);
  275. } while (!(stat & SM_FLASH_STATUS_DONE));
  276. if (!(stat & SM_FLASH_STATUS_DONE))
  277. break;
  278. }
  279. out_8(base, SM_FLASH_CMD_CLEAR_STATUS);
  280. out_8(base, SM_FLASH_CMD_RESET);
  281. if (memcmp(base, datas, NVRAM_SIZE)) {
  282. printk(KERN_ERR "nvram: Sharp/Micron flash write failed !\n");
  283. return -ENXIO;
  284. }
  285. return 0;
  286. }
  287. static int amd_erase_bank(int bank)
  288. {
  289. int stat = 0;
  290. unsigned long timeout;
  291. u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
  292. DBG("nvram: AMD Erasing bank %d...\n", bank);
  293. /* Unlock 1 */
  294. out_8(base+0x555, 0xaa);
  295. udelay(1);
  296. /* Unlock 2 */
  297. out_8(base+0x2aa, 0x55);
  298. udelay(1);
  299. /* Sector-Erase */
  300. out_8(base+0x555, 0x80);
  301. udelay(1);
  302. out_8(base+0x555, 0xaa);
  303. udelay(1);
  304. out_8(base+0x2aa, 0x55);
  305. udelay(1);
  306. out_8(base, 0x30);
  307. udelay(1);
  308. timeout = 0;
  309. do {
  310. if (++timeout > 1000000) {
  311. printk(KERN_ERR "nvram: AMD flash erase timeout !\n");
  312. break;
  313. }
  314. stat = in_8(base) ^ in_8(base);
  315. } while (stat != 0);
  316. /* Reset */
  317. out_8(base, 0xf0);
  318. udelay(1);
  319. if (memchr_inv(base, 0xff, NVRAM_SIZE)) {
  320. printk(KERN_ERR "nvram: AMD flash erase failed !\n");
  321. return -ENXIO;
  322. }
  323. return 0;
  324. }
  325. static int amd_write_bank(int bank, u8* datas)
  326. {
  327. int i, stat = 0;
  328. unsigned long timeout;
  329. u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
  330. DBG("nvram: AMD Writing bank %d...\n", bank);
  331. for (i=0; i<NVRAM_SIZE; i++) {
  332. /* Unlock 1 */
  333. out_8(base+0x555, 0xaa);
  334. udelay(1);
  335. /* Unlock 2 */
  336. out_8(base+0x2aa, 0x55);
  337. udelay(1);
  338. /* Write single word */
  339. out_8(base+0x555, 0xa0);
  340. udelay(1);
  341. out_8(base+i, datas[i]);
  342. timeout = 0;
  343. do {
  344. if (++timeout > 1000000) {
  345. printk(KERN_ERR "nvram: AMD flash write timeout !\n");
  346. break;
  347. }
  348. stat = in_8(base) ^ in_8(base);
  349. } while (stat != 0);
  350. if (stat != 0)
  351. break;
  352. }
  353. /* Reset */
  354. out_8(base, 0xf0);
  355. udelay(1);
  356. if (memcmp(base, datas, NVRAM_SIZE)) {
  357. printk(KERN_ERR "nvram: AMD flash write failed !\n");
  358. return -ENXIO;
  359. }
  360. return 0;
  361. }
  362. static void __init lookup_partitions(void)
  363. {
  364. u8 buffer[17];
  365. int i, offset;
  366. struct chrp_header* hdr;
  367. if (pmac_newworld) {
  368. nvram_partitions[pmac_nvram_OF] = -1;
  369. nvram_partitions[pmac_nvram_XPRAM] = -1;
  370. nvram_partitions[pmac_nvram_NR] = -1;
  371. hdr = (struct chrp_header *)buffer;
  372. offset = 0;
  373. buffer[16] = 0;
  374. do {
  375. for (i=0;i<16;i++)
  376. buffer[i] = ppc_md.nvram_read_val(offset+i);
  377. if (!strcmp(hdr->name, "common"))
  378. nvram_partitions[pmac_nvram_OF] = offset + 0x10;
  379. if (!strcmp(hdr->name, "APL,MacOS75")) {
  380. nvram_partitions[pmac_nvram_XPRAM] = offset + 0x10;
  381. nvram_partitions[pmac_nvram_NR] = offset + 0x110;
  382. }
  383. offset += (hdr->len * 0x10);
  384. } while(offset < NVRAM_SIZE);
  385. } else {
  386. nvram_partitions[pmac_nvram_OF] = 0x1800;
  387. nvram_partitions[pmac_nvram_XPRAM] = 0x1300;
  388. nvram_partitions[pmac_nvram_NR] = 0x1400;
  389. }
  390. DBG("nvram: OF partition at 0x%x\n", nvram_partitions[pmac_nvram_OF]);
  391. DBG("nvram: XP partition at 0x%x\n", nvram_partitions[pmac_nvram_XPRAM]);
  392. DBG("nvram: NR partition at 0x%x\n", nvram_partitions[pmac_nvram_NR]);
  393. }
  394. static void core99_nvram_sync(void)
  395. {
  396. struct core99_header* hdr99;
  397. unsigned long flags;
  398. if (!is_core_99 || !nvram_data || !nvram_image)
  399. return;
  400. raw_spin_lock_irqsave(&nv_lock, flags);
  401. if (!memcmp(nvram_image, (u8*)nvram_data + core99_bank*NVRAM_SIZE,
  402. NVRAM_SIZE))
  403. goto bail;
  404. DBG("Updating nvram...\n");
  405. hdr99 = (struct core99_header*)nvram_image;
  406. hdr99->generation++;
  407. hdr99->hdr.signature = CORE99_SIGNATURE;
  408. hdr99->hdr.cksum = chrp_checksum(&hdr99->hdr);
  409. hdr99->adler = core99_calc_adler(nvram_image);
  410. core99_bank = core99_bank ? 0 : 1;
  411. if (core99_erase_bank)
  412. if (core99_erase_bank(core99_bank)) {
  413. printk("nvram: Error erasing bank %d\n", core99_bank);
  414. goto bail;
  415. }
  416. if (core99_write_bank)
  417. if (core99_write_bank(core99_bank, nvram_image))
  418. printk("nvram: Error writing bank %d\n", core99_bank);
  419. bail:
  420. raw_spin_unlock_irqrestore(&nv_lock, flags);
  421. #ifdef DEBUG
  422. mdelay(2000);
  423. #endif
  424. }
  425. static int __init core99_nvram_setup(struct device_node *dp, unsigned long addr)
  426. {
  427. int i;
  428. u32 gen_bank0, gen_bank1;
  429. if (nvram_naddrs < 1) {
  430. printk(KERN_ERR "nvram: no address\n");
  431. return -EINVAL;
  432. }
  433. nvram_image = alloc_bootmem(NVRAM_SIZE);
  434. if (nvram_image == NULL) {
  435. printk(KERN_ERR "nvram: can't allocate ram image\n");
  436. return -ENOMEM;
  437. }
  438. nvram_data = ioremap(addr, NVRAM_SIZE*2);
  439. nvram_naddrs = 1; /* Make sure we get the correct case */
  440. DBG("nvram: Checking bank 0...\n");
  441. gen_bank0 = core99_check((u8 *)nvram_data);
  442. gen_bank1 = core99_check((u8 *)nvram_data + NVRAM_SIZE);
  443. core99_bank = (gen_bank0 < gen_bank1) ? 1 : 0;
  444. DBG("nvram: gen0=%d, gen1=%d\n", gen_bank0, gen_bank1);
  445. DBG("nvram: Active bank is: %d\n", core99_bank);
  446. for (i=0; i<NVRAM_SIZE; i++)
  447. nvram_image[i] = nvram_data[i + core99_bank*NVRAM_SIZE];
  448. ppc_md.nvram_read_val = core99_nvram_read_byte;
  449. ppc_md.nvram_write_val = core99_nvram_write_byte;
  450. ppc_md.nvram_read = core99_nvram_read;
  451. ppc_md.nvram_write = core99_nvram_write;
  452. ppc_md.nvram_size = core99_nvram_size;
  453. ppc_md.nvram_sync = core99_nvram_sync;
  454. ppc_md.machine_shutdown = core99_nvram_sync;
  455. /*
  456. * Maybe we could be smarter here though making an exclusive list
  457. * of known flash chips is a bit nasty as older OF didn't provide us
  458. * with a useful "compatible" entry. A solution would be to really
  459. * identify the chip using flash id commands and base ourselves on
  460. * a list of known chips IDs
  461. */
  462. if (of_device_is_compatible(dp, "amd-0137")) {
  463. core99_erase_bank = amd_erase_bank;
  464. core99_write_bank = amd_write_bank;
  465. } else {
  466. core99_erase_bank = sm_erase_bank;
  467. core99_write_bank = sm_write_bank;
  468. }
  469. return 0;
  470. }
  471. int __init pmac_nvram_init(void)
  472. {
  473. struct device_node *dp;
  474. struct resource r1, r2;
  475. unsigned int s1 = 0, s2 = 0;
  476. int err = 0;
  477. nvram_naddrs = 0;
  478. dp = of_find_node_by_name(NULL, "nvram");
  479. if (dp == NULL) {
  480. printk(KERN_ERR "Can't find NVRAM device\n");
  481. return -ENODEV;
  482. }
  483. /* Try to obtain an address */
  484. if (of_address_to_resource(dp, 0, &r1) == 0) {
  485. nvram_naddrs = 1;
  486. s1 = resource_size(&r1);
  487. if (of_address_to_resource(dp, 1, &r2) == 0) {
  488. nvram_naddrs = 2;
  489. s2 = resource_size(&r2);
  490. }
  491. }
  492. is_core_99 = of_device_is_compatible(dp, "nvram,flash");
  493. if (is_core_99) {
  494. err = core99_nvram_setup(dp, r1.start);
  495. goto bail;
  496. }
  497. #ifdef CONFIG_PPC32
  498. if (machine_is(chrp) && nvram_naddrs == 1) {
  499. nvram_data = ioremap(r1.start, s1);
  500. nvram_mult = 1;
  501. ppc_md.nvram_read_val = direct_nvram_read_byte;
  502. ppc_md.nvram_write_val = direct_nvram_write_byte;
  503. } else if (nvram_naddrs == 1) {
  504. nvram_data = ioremap(r1.start, s1);
  505. nvram_mult = (s1 + NVRAM_SIZE - 1) / NVRAM_SIZE;
  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 == 2) {
  509. nvram_addr = ioremap(r1.start, s1);
  510. nvram_data = ioremap(r2.start, s2);
  511. ppc_md.nvram_read_val = indirect_nvram_read_byte;
  512. ppc_md.nvram_write_val = indirect_nvram_write_byte;
  513. } else if (nvram_naddrs == 0 && sys_ctrler == SYS_CTRLER_PMU) {
  514. #ifdef CONFIG_ADB_PMU
  515. nvram_naddrs = -1;
  516. ppc_md.nvram_read_val = pmu_nvram_read_byte;
  517. ppc_md.nvram_write_val = pmu_nvram_write_byte;
  518. #endif /* CONFIG_ADB_PMU */
  519. } else {
  520. printk(KERN_ERR "Incompatible type of NVRAM\n");
  521. err = -ENXIO;
  522. }
  523. #endif /* CONFIG_PPC32 */
  524. bail:
  525. of_node_put(dp);
  526. if (err == 0)
  527. lookup_partitions();
  528. return err;
  529. }
  530. int pmac_get_partition(int partition)
  531. {
  532. return nvram_partitions[partition];
  533. }
  534. u8 pmac_xpram_read(int xpaddr)
  535. {
  536. int offset = pmac_get_partition(pmac_nvram_XPRAM);
  537. if (offset < 0 || xpaddr < 0 || xpaddr > 0x100)
  538. return 0xff;
  539. return ppc_md.nvram_read_val(xpaddr + offset);
  540. }
  541. void pmac_xpram_write(int xpaddr, u8 data)
  542. {
  543. int offset = pmac_get_partition(pmac_nvram_XPRAM);
  544. if (offset < 0 || xpaddr < 0 || xpaddr > 0x100)
  545. return;
  546. ppc_md.nvram_write_val(xpaddr + offset, data);
  547. }
  548. EXPORT_SYMBOL(pmac_get_partition);
  549. EXPORT_SYMBOL(pmac_xpram_read);
  550. EXPORT_SYMBOL(pmac_xpram_write);