Skip to content

Commit a7d9b5f

Browse files
bebarinogregkh
authored andcommitted
firmware: coreboot: Remap RAM with memremap() instead of ioremap()
This is all system memory, so we shouldn't be mapping this all with ioremap() as these aren't I/O regions. Instead, they're memory regions so we should use memremap(). Pick MEMREMAP_WB so we can map memory from RAM directly if that's possible, otherwise it falls back to ioremap_cache() like is being done here already. This also nicely silences the sparse warnings in this code and reduces the need to copy anything around anymore. Cc: Wei-Ning Huang <wnhuang@chromium.org> Cc: Julius Werner <jwerner@chromium.org> Cc: Brian Norris <briannorris@chromium.org> Cc: Samuel Holland <samuel@sholland.org> Signed-off-by: Stephen Boyd <swboyd@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a28aad6 commit a7d9b5f

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

‎drivers/firmware/google/coreboot_table.c‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define CB_DEV(d) container_of(d, struct coreboot_device, dev)
3333
#define CB_DRV(d) container_of(d, struct coreboot_driver, drv)
3434

35-
static struct coreboot_table_header __iomem *ptr_header;
35+
static struct coreboot_table_header *ptr_header;
3636

3737
static int coreboot_bus_match(struct device *dev, struct device_driver *drv)
3838
{
@@ -94,18 +94,18 @@ void coreboot_driver_unregister(struct coreboot_driver *driver)
9494
}
9595
EXPORT_SYMBOL(coreboot_driver_unregister);
9696

97-
static int coreboot_table_init(struct device *dev, void __iomem *ptr)
97+
static int coreboot_table_init(struct device *dev, void *ptr)
9898
{
9999
int i, ret;
100100
void *ptr_entry;
101101
struct coreboot_device *device;
102-
struct coreboot_table_entry entry;
103-
struct coreboot_table_header header;
102+
struct coreboot_table_entry *entry;
103+
struct coreboot_table_header *header;
104104

105105
ptr_header = ptr;
106-
memcpy_fromio(&header, ptr_header, sizeof(header));
106+
header = ptr;
107107

108-
if (strncmp(header.signature, "LBIO", sizeof(header.signature))) {
108+
if (strncmp(header->signature, "LBIO", sizeof(header->signature))) {
109109
pr_warn("coreboot_table: coreboot table missing or corrupt!\n");
110110
ret = -ENODEV;
111111
goto out;
@@ -115,11 +115,11 @@ static int coreboot_table_init(struct device *dev, void __iomem *ptr)
115115
if (ret)
116116
goto out;
117117

118-
ptr_entry = (void *)ptr_header + header.header_bytes;
119-
for (i = 0; i < header.table_entries; i++) {
120-
memcpy_fromio(&entry, ptr_entry, sizeof(entry));
118+
ptr_entry = ptr_header + header->header_bytes;
119+
for (i = 0; i < header->table_entries; i++) {
120+
entry = ptr_entry;
121121

122-
device = kzalloc(sizeof(struct device) + entry.size, GFP_KERNEL);
122+
device = kzalloc(sizeof(struct device) + entry->size, GFP_KERNEL);
123123
if (!device) {
124124
ret = -ENOMEM;
125125
break;
@@ -129,32 +129,31 @@ static int coreboot_table_init(struct device *dev, void __iomem *ptr)
129129
device->dev.parent = dev;
130130
device->dev.bus = &coreboot_bus_type;
131131
device->dev.release = coreboot_device_release;
132-
memcpy_fromio(&device->entry, ptr_entry, entry.size);
132+
memcpy(&device->entry, ptr_entry, entry->size);
133133

134134
ret = device_register(&device->dev);
135135
if (ret) {
136136
put_device(&device->dev);
137137
break;
138138
}
139139

140-
ptr_entry += entry.size;
140+
ptr_entry += entry->size;
141141
}
142142

143143
if (ret)
144144
bus_unregister(&coreboot_bus_type);
145145

146146
out:
147-
iounmap(ptr);
147+
memunmap(ptr);
148148
return ret;
149149
}
150150

151151
static int coreboot_table_probe(struct platform_device *pdev)
152152
{
153-
phys_addr_t phyaddr;
154153
resource_size_t len;
155-
struct coreboot_table_header __iomem *header = NULL;
154+
struct coreboot_table_header *header;
156155
struct resource *res;
157-
void __iomem *ptr = NULL;
156+
void *ptr;
158157

159158
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
160159
if (!res)
@@ -164,14 +163,13 @@ static int coreboot_table_probe(struct platform_device *pdev)
164163
if (!res->start || !len)
165164
return -EINVAL;
166165

167-
phyaddr = res->start;
168-
header = ioremap_cache(phyaddr, sizeof(*header));
166+
header = memremap(res->start, sizeof(*header), MEMREMAP_WB);
169167
if (header == NULL)
170168
return -ENOMEM;
171169

172-
ptr = ioremap_cache(phyaddr,
173-
header->header_bytes + header->table_bytes);
174-
iounmap(header);
170+
ptr = memremap(res->start, header->header_bytes + header->table_bytes,
171+
MEMREMAP_WB);
172+
memunmap(header);
175173
if (!ptr)
176174
return -ENOMEM;
177175

0 commit comments

Comments
 (0)