Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: 5625/1: fix hard coded 4K resource size in amba bus detection

This patch modifies the amba bus detection logic in the kernel
to detect the AMBA devices using the calculated resource
size information rather than the hard coded 4K size.

It also calculates the resource size when request mem region
and release mem region.

Signed-off-by: Leo Chen <leochen@broadcom.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

authored by

Leo Chen and committed by
Russell King
8afe0b96 98b0979f

+21 -5
+21 -5
drivers/amba/bus.c
··· 204 204 int amba_device_register(struct amba_device *dev, struct resource *parent) 205 205 { 206 206 u32 pid, cid; 207 + u32 size; 207 208 void __iomem *tmp; 208 209 int i, ret; 209 210 ··· 220 219 if (ret) 221 220 goto err_out; 222 221 223 - tmp = ioremap(dev->res.start, SZ_4K); 222 + /* 223 + * Dynamically calculate the size of the resource 224 + * and use this for iomap 225 + */ 226 + size = resource_size(&dev->res); 227 + tmp = ioremap(dev->res.start, size); 224 228 if (!tmp) { 225 229 ret = -ENOMEM; 226 230 goto err_release; 227 231 } 228 232 233 + /* 234 + * Read pid and cid based on size of resource 235 + * they are located at end of region 236 + */ 229 237 for (pid = 0, i = 0; i < 4; i++) 230 - pid |= (readl(tmp + 0xfe0 + 4 * i) & 255) << (i * 8); 238 + pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) << (i * 8); 231 239 for (cid = 0, i = 0; i < 4; i++) 232 - cid |= (readl(tmp + 0xff0 + 4 * i) & 255) << (i * 8); 240 + cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << (i * 8); 233 241 234 242 iounmap(tmp); 235 243 ··· 353 343 int amba_request_regions(struct amba_device *dev, const char *name) 354 344 { 355 345 int ret = 0; 346 + u32 size; 356 347 357 348 if (!name) 358 349 name = dev->dev.driver->name; 359 350 360 - if (!request_mem_region(dev->res.start, SZ_4K, name)) 351 + size = resource_size(&dev->res); 352 + 353 + if (!request_mem_region(dev->res.start, size, name)) 361 354 ret = -EBUSY; 362 355 363 356 return ret; ··· 374 361 */ 375 362 void amba_release_regions(struct amba_device *dev) 376 363 { 377 - release_mem_region(dev->res.start, SZ_4K); 364 + u32 size; 365 + 366 + size = resource_size(&dev->res); 367 + release_mem_region(dev->res.start, size); 378 368 } 379 369 380 370 EXPORT_SYMBOL(amba_driver_register);