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

Configure Feed

Select the types of activity you want to include in your feed.

drm/ast: Rework I/O register setup

There are three different ways of retrieving the I/O-memory ranges
for AST devices: either from PCI BAR 1, from PCI BAR 2 or from PCI
BAR 1 by 'guessing'.

Make the respective code more readable by making each case self-
contained. Also add error checking against the length of the PCI
BARs.

v2:
* fix I/O range length to 128 bytes
* fix length test for PCI BAR 2

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231116100240.22975-3-tzimmermann@suse.de

+32 -11
+31 -11
drivers/gpu/drm/ast/ast_main.c
··· 444 444 if (!ast->regs) 445 445 return ERR_PTR(-EIO); 446 446 447 - /* 448 - * After AST2500, MMIO is enabled by default, and it should be adopted 449 - * to be compatible with Arm. 450 - */ 451 447 if (pdev->revision >= 0x40) { 452 - ast->ioregs = ast->regs + AST_IO_MM_OFFSET; 453 - } else if (!(pci_resource_flags(pdev, 2) & IORESOURCE_IO)) { 454 - drm_info(dev, "platform has no IO space, trying MMIO\n"); 455 - ast->ioregs = ast->regs + AST_IO_MM_OFFSET; 456 - } 448 + /* 449 + * On AST2500 and later models, MMIO is enabled by 450 + * default. Adopt it to be compatible with ARM. 451 + */ 452 + resource_size_t len = pci_resource_len(pdev, 1); 457 453 458 - /* "map" IO regs if the above hasn't done so already */ 459 - if (!ast->ioregs) { 454 + if (len < AST_IO_MM_OFFSET) 455 + return ERR_PTR(-EIO); 456 + if ((len - AST_IO_MM_OFFSET) < AST_IO_MM_LENGTH) 457 + return ERR_PTR(-EIO); 458 + ast->ioregs = ast->regs + AST_IO_MM_OFFSET; 459 + } else if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) { 460 + /* 461 + * Map I/O registers if we have a PCI BAR for I/O. 462 + */ 463 + resource_size_t len = pci_resource_len(pdev, 2); 464 + 465 + if (len < AST_IO_MM_LENGTH) 466 + return -EIO; 460 467 ast->ioregs = pcim_iomap(pdev, 2, 0); 461 468 if (!ast->ioregs) 462 469 return ERR_PTR(-EIO); 470 + } else { 471 + /* 472 + * Anything else is best effort. 473 + */ 474 + resource_size_t len = pci_resource_len(pdev, 1); 475 + 476 + if (len < AST_IO_MM_OFFSET) 477 + return ERR_PTR(-EIO); 478 + if ((len - AST_IO_MM_OFFSET) < AST_IO_MM_LENGTH) 479 + return ERR_PTR(-EIO); 480 + ast->ioregs = ast->regs + AST_IO_MM_OFFSET; 481 + 482 + drm_info(dev, "Platform has no I/O space, using MMIO\n"); 463 483 } 464 484 465 485 if (!ast_is_vga_enabled(dev)) {
+1
drivers/gpu/drm/ast/ast_reg.h
··· 10 10 */ 11 11 12 12 #define AST_IO_MM_OFFSET (0x380) 13 + #define AST_IO_MM_LENGTH (128) 13 14 14 15 #define AST_IO_VGAARI_W (0x40) 15 16 #define AST_IO_VGAMR_W (0x42)