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

resource: Add walk_iomem_res_desc()

Add a new interface, walk_iomem_res_desc(), which walks through
the iomem table by identifying a target with @flags and @desc.
This interface provides the same functionality as
walk_iomem_res(), but does not use strcmp() to @name for better
efficiency.

walk_iomem_res() is deprecated and will be removed in a later
patch.

Requested-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
[ Fixup comments. ]
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Hanjun Guo <hanjun.guo@linaro.org>
Cc: Jakub Sitnicki <jsitnicki@gmail.com>
Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Toshi Kani <toshi.kani@hp.com>
Cc: linux-arch@vger.kernel.org
Cc: linux-mm <linux-mm@kvack.org>
Link: http://lkml.kernel.org/r/1453841853-11383-14-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Toshi Kani and committed by
Ingo Molnar
3f33647c 1c29f25b

+59 -10
+3
include/linux/ioport.h
··· 268 268 walk_system_ram_res(u64 start, u64 end, void *arg, 269 269 int (*func)(u64, u64, void *)); 270 270 extern int 271 + walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end, 272 + void *arg, int (*func)(u64, u64, void *)); 273 + extern int 271 274 walk_iomem_res(char *name, unsigned long flags, u64 start, u64 end, void *arg, 272 275 int (*func)(u64, u64, void *)); 273 276
+56 -10
kernel/resource.c
··· 333 333 EXPORT_SYMBOL(release_resource); 334 334 335 335 /* 336 - * Finds the lowest iomem reosurce exists with-in [res->start.res->end) 337 - * the caller must specify res->start, res->end, res->flags and "name". 338 - * If found, returns 0, res is overwritten, if not found, returns -1. 339 - * This walks through whole tree and not just first level children 340 - * until and unless first_level_children_only is true. 336 + * Finds the lowest iomem resource existing within [res->start.res->end). 337 + * The caller must specify res->start, res->end, res->flags, and optionally 338 + * desc and "name". If found, returns 0, res is overwritten, if not found, 339 + * returns -1. 340 + * This function walks the whole tree and not just first level children until 341 + * and unless first_level_children_only is true. 341 342 */ 342 - static int find_next_iomem_res(struct resource *res, char *name, 343 - bool first_level_children_only) 343 + static int find_next_iomem_res(struct resource *res, unsigned long desc, 344 + char *name, bool first_level_children_only) 344 345 { 345 346 resource_size_t start, end; 346 347 struct resource *p; ··· 360 359 361 360 for (p = iomem_resource.child; p; p = next_resource(p, sibling_only)) { 362 361 if ((p->flags & res->flags) != res->flags) 362 + continue; 363 + if ((desc != IORES_DESC_NONE) && (desc != p->desc)) 363 364 continue; 364 365 if (name && strcmp(p->name, name)) 365 366 continue; ··· 388 385 * Walks through iomem resources and calls func() with matching resource 389 386 * ranges. This walks through whole tree and not just first level children. 390 387 * All the memory ranges which overlap start,end and also match flags and 388 + * desc are valid candidates. 389 + * 390 + * @desc: I/O resource descriptor. Use IORES_DESC_NONE to skip @desc check. 391 + * @flags: I/O resource flags 392 + * @start: start addr 393 + * @end: end addr 394 + * 395 + * NOTE: For a new descriptor search, define a new IORES_DESC in 396 + * <linux/ioport.h> and set it in 'desc' of a target resource entry. 397 + */ 398 + int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, 399 + u64 end, void *arg, int (*func)(u64, u64, void *)) 400 + { 401 + struct resource res; 402 + u64 orig_end; 403 + int ret = -1; 404 + 405 + res.start = start; 406 + res.end = end; 407 + res.flags = flags; 408 + orig_end = res.end; 409 + 410 + while ((res.start < res.end) && 411 + (!find_next_iomem_res(&res, desc, NULL, false))) { 412 + 413 + ret = (*func)(res.start, res.end, arg); 414 + if (ret) 415 + break; 416 + 417 + res.start = res.end + 1; 418 + res.end = orig_end; 419 + } 420 + 421 + return ret; 422 + } 423 + 424 + /* 425 + * Walks through iomem resources and calls @func with matching resource 426 + * ranges. This walks the whole tree and not just first level children. 427 + * All the memory ranges which overlap start,end and also match flags and 391 428 * name are valid candidates. 392 429 * 393 430 * @name: name of resource 394 431 * @flags: resource flags 395 432 * @start: start addr 396 433 * @end: end addr 434 + * 435 + * NOTE: This function is deprecated and should not be used in new code. 436 + * Use walk_iomem_res_desc(), instead. 397 437 */ 398 438 int walk_iomem_res(char *name, unsigned long flags, u64 start, u64 end, 399 439 void *arg, int (*func)(u64, u64, void *)) ··· 450 404 res.flags = flags; 451 405 orig_end = res.end; 452 406 while ((res.start < res.end) && 453 - (!find_next_iomem_res(&res, name, false))) { 407 + (!find_next_iomem_res(&res, IORES_DESC_NONE, name, false))) { 454 408 ret = (*func)(res.start, res.end, arg); 455 409 if (ret) 456 410 break; ··· 479 433 res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; 480 434 orig_end = res.end; 481 435 while ((res.start < res.end) && 482 - (!find_next_iomem_res(&res, NULL, true))) { 436 + (!find_next_iomem_res(&res, IORES_DESC_NONE, NULL, true))) { 483 437 ret = (*func)(res.start, res.end, arg); 484 438 if (ret) 485 439 break; ··· 509 463 res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; 510 464 orig_end = res.end; 511 465 while ((res.start < res.end) && 512 - (find_next_iomem_res(&res, NULL, true) >= 0)) { 466 + (find_next_iomem_res(&res, IORES_DESC_NONE, NULL, true) >= 0)) { 513 467 pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT; 514 468 end_pfn = (res.end + 1) >> PAGE_SHIFT; 515 469 if (end_pfn > pfn)