]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/powerpc/sysdev/mmio_nvram.c
[POWERPC] Remove bogus sanity check in pci -> OF node code
[mirror_ubuntu-bionic-kernel.git] / arch / powerpc / sysdev / mmio_nvram.c
CommitLineData
5f5b4e66 1/*
f3f66f59 2 * memory mapped NVRAM
5f5b4e66
UB
3 *
4 * (C) Copyright IBM Corp. 2005
5 *
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/fs.h>
24#include <linux/init.h>
25#include <linux/kernel.h>
26#include <linux/spinlock.h>
27#include <linux/types.h>
28
29#include <asm/machdep.h>
30#include <asm/nvram.h>
31#include <asm/prom.h>
32
f3f66f59
AB
33static void __iomem *mmio_nvram_start;
34static long mmio_nvram_len;
34af946a 35static DEFINE_SPINLOCK(mmio_nvram_lock);
5f5b4e66 36
f3f66f59 37static ssize_t mmio_nvram_read(char *buf, size_t count, loff_t *index)
5f5b4e66
UB
38{
39 unsigned long flags;
40
f3f66f59 41 if (*index >= mmio_nvram_len)
5f5b4e66 42 return 0;
f3f66f59
AB
43 if (*index + count > mmio_nvram_len)
44 count = mmio_nvram_len - *index;
5f5b4e66 45
f3f66f59 46 spin_lock_irqsave(&mmio_nvram_lock, flags);
5f5b4e66 47
f3f66f59 48 memcpy_fromio(buf, mmio_nvram_start + *index, count);
5f5b4e66 49
f3f66f59 50 spin_unlock_irqrestore(&mmio_nvram_lock, flags);
5f5b4e66
UB
51
52 *index += count;
53 return count;
54}
55
f3f66f59 56static ssize_t mmio_nvram_write(char *buf, size_t count, loff_t *index)
5f5b4e66
UB
57{
58 unsigned long flags;
59
f3f66f59 60 if (*index >= mmio_nvram_len)
5f5b4e66 61 return 0;
f3f66f59
AB
62 if (*index + count > mmio_nvram_len)
63 count = mmio_nvram_len - *index;
5f5b4e66 64
f3f66f59 65 spin_lock_irqsave(&mmio_nvram_lock, flags);
5f5b4e66 66
f3f66f59 67 memcpy_toio(mmio_nvram_start + *index, buf, count);
5f5b4e66 68
f3f66f59 69 spin_unlock_irqrestore(&mmio_nvram_lock, flags);
5f5b4e66
UB
70
71 *index += count;
72 return count;
73}
74
f3f66f59 75static ssize_t mmio_nvram_get_size(void)
5f5b4e66 76{
f3f66f59 77 return mmio_nvram_len;
5f5b4e66
UB
78}
79
f3f66f59 80int __init mmio_nvram_init(void)
5f5b4e66
UB
81{
82 struct device_node *nvram_node;
a7f67bdf 83 const unsigned long *buffer;
5f5b4e66
UB
84 int proplen;
85 unsigned long nvram_addr;
86 int ret;
87
88 ret = -ENODEV;
89 nvram_node = of_find_node_by_type(NULL, "nvram");
90 if (!nvram_node)
91 goto out;
92
93 ret = -EIO;
a7f67bdf 94 buffer = get_property(nvram_node, "reg", &proplen);
5f5b4e66
UB
95 if (proplen != 2*sizeof(unsigned long))
96 goto out;
97
98 ret = -ENODEV;
99 nvram_addr = buffer[0];
f3f66f59
AB
100 mmio_nvram_len = buffer[1];
101 if ( (!mmio_nvram_len) || (!nvram_addr) )
5f5b4e66
UB
102 goto out;
103
f3f66f59
AB
104 mmio_nvram_start = ioremap(nvram_addr, mmio_nvram_len);
105 if (!mmio_nvram_start)
5f5b4e66
UB
106 goto out;
107
f3f66f59
AB
108 printk(KERN_INFO "mmio NVRAM, %luk mapped to %p\n",
109 mmio_nvram_len >> 10, mmio_nvram_start);
5f5b4e66 110
f3f66f59
AB
111 ppc_md.nvram_read = mmio_nvram_read;
112 ppc_md.nvram_write = mmio_nvram_write;
113 ppc_md.nvram_size = mmio_nvram_get_size;
5f5b4e66
UB
114
115out:
116 of_node_put(nvram_node);
117 return ret;
118}