sunxi_sid.c (a52079dad4718fa924ae81a939f8a665366f562b) sunxi_sid.c (d16abd30b3faee8efab30ed6198d3696e0304b57)
1/*
2 * Allwinner sunXi SoCs Security ID support.
3 *
4 * Copyright (c) 2013 Oliver Schinagl <oliver@schinagl.nl>
5 * Copyright (C) 2014 Maxime Ripard <maxime.ripard@free-electrons.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
1/*
2 * Allwinner sunXi SoCs Security ID support.
3 *
4 * Copyright (c) 2013 Oliver Schinagl <oliver@schinagl.nl>
5 * Copyright (C) 2014 Maxime Ripard <maxime.ripard@free-electrons.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
16 */
17
19
20#include <linux/device.h>
21#include <linux/io.h>
22#include <linux/module.h>
23#include <linux/nvmem-provider.h>
24#include <linux/of.h>
25#include <linux/platform_device.h>
26#include <linux/regmap.h>
27#include <linux/slab.h>
28#include <linux/random.h>
29
18#include <linux/device.h>
19#include <linux/io.h>
20#include <linux/module.h>
21#include <linux/nvmem-provider.h>
22#include <linux/of.h>
23#include <linux/platform_device.h>
24#include <linux/regmap.h>
25#include <linux/slab.h>
26#include <linux/random.h>
27
30
31static struct nvmem_config econfig = {
32 .name = "sunxi-sid",
33 .read_only = true,
34 .owner = THIS_MODULE,
35};
36
37struct sunxi_sid {
38 void __iomem *base;

--- 11 unchanged lines hidden (view full) ---

50
51 sid_key = ioread32be(sid->base + round_down(offset, 4));
52 sid_key >>= (offset % 4) * 8;
53
54 return sid_key; /* Only return the last byte */
55}
56
57static int sunxi_sid_read(void *context,
28static struct nvmem_config econfig = {
29 .name = "sunxi-sid",
30 .read_only = true,
31 .owner = THIS_MODULE,
32};
33
34struct sunxi_sid {
35 void __iomem *base;

--- 11 unchanged lines hidden (view full) ---

47
48 sid_key = ioread32be(sid->base + round_down(offset, 4));
49 sid_key >>= (offset % 4) * 8;
50
51 return sid_key; /* Only return the last byte */
52}
53
54static int sunxi_sid_read(void *context,
58 const void *reg, size_t reg_size,
59 void *val, size_t val_size)
55 const void *reg, size_t reg_size,
56 void *val, size_t val_size)
60{
61 struct sunxi_sid *sid = context;
62 unsigned int offset = *(u32 *)reg;
63 u8 *buf = val;
64
65 while (val_size) {
66 *buf++ = sunxi_sid_read_byte(sid, offset);
67 val_size--;

--- 57 unchanged lines hidden (view full) ---

125 return PTR_ERR(regmap);
126 }
127
128 econfig.dev = dev;
129 nvmem = nvmem_register(&econfig);
130 if (IS_ERR(nvmem))
131 return PTR_ERR(nvmem);
132
57{
58 struct sunxi_sid *sid = context;
59 unsigned int offset = *(u32 *)reg;
60 u8 *buf = val;
61
62 while (val_size) {
63 *buf++ = sunxi_sid_read_byte(sid, offset);
64 val_size--;

--- 57 unchanged lines hidden (view full) ---

122 return PTR_ERR(regmap);
123 }
124
125 econfig.dev = dev;
126 nvmem = nvmem_register(&econfig);
127 if (IS_ERR(nvmem))
128 return PTR_ERR(nvmem);
129
133 randomness = kzalloc(sizeof(u8) * size, GFP_KERNEL);
130 randomness = kzalloc(sizeof(u8) * (size), GFP_KERNEL);
134 if (!randomness) {
135 ret = -EINVAL;
136 goto err_unreg_nvmem;
137 }
138
139 for (i = 0; i < size; i++)
140 randomness[i] = sunxi_sid_read_byte(sid, i);
141

--- 39 unchanged lines hidden ---
131 if (!randomness) {
132 ret = -EINVAL;
133 goto err_unreg_nvmem;
134 }
135
136 for (i = 0; i < size; i++)
137 randomness[i] = sunxi_sid_read_byte(sid, i);
138

--- 39 unchanged lines hidden ---