[U-Boot] [PATCH v2 12/26] dm: pci: video: Convert video and pci_rom to use DM PCI API

Bin Meng bmeng.cn at gmail.com
Mon Dec 7 11:53:27 CET 2015


On Mon, Nov 30, 2015 at 4:17 AM, Simon Glass <sjg at chromium.org> wrote:
> Adjust these files to use the driver-model PCI API instead of the legacy
> functions.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> Changes in v2:
> - Rename pci_run_vga_bios() to dm_pci_run_vga_bios()
> - Require driver model with pci_rom.c
> - Use dev_get_parent_platdata() instead of re-reading values from the device
>
>  arch/x86/cpu/ivybridge/gma.c |  4 ++--
>  drivers/pci/Makefile         |  3 ++-
>  drivers/pci/pci_rom.c        | 51 +++++++++++++++++++++-----------------------
>  drivers/video/vesa_fb.c      | 10 ++++-----
>  include/pci_rom.h            |  6 +++---
>  5 files changed, 36 insertions(+), 38 deletions(-)
>
> diff --git a/arch/x86/cpu/ivybridge/gma.c b/arch/x86/cpu/ivybridge/gma.c
> index 695578b..85a09c6 100644
> --- a/arch/x86/cpu/ivybridge/gma.c
> +++ b/arch/x86/cpu/ivybridge/gma.c
> @@ -756,8 +756,8 @@ int gma_func0_init(struct udevice *dev, const void *blob, int node)
>
>  #ifdef CONFIG_VIDEO
>         start = get_timer(0);
> -       ret = pci_run_vga_bios(dm_pci_get_bdf(dev), int15_handler,
> -                              PCI_ROM_USE_NATIVE | PCI_ROM_ALLOW_FALLBACK);
> +       ret = dm_pci_run_vga_bios(dev, int15_handler,
> +                                 PCI_ROM_USE_NATIVE | PCI_ROM_ALLOW_FALLBACK);
>         debug("BIOS ran in %lums\n", get_timer(start));
>  #endif
>         /* Post VBIOS init */
> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
> index 62232fc..f8be9bf 100644
> --- a/drivers/pci/Makefile
> +++ b/drivers/pci/Makefile
> @@ -6,6 +6,7 @@
>  #
>
>  ifneq ($(CONFIG_DM_PCI),)
> +obj-y += pci_rom.o
>  obj-$(CONFIG_PCI) += pci-uclass.o pci_auto.o
>  obj-$(CONFIG_DM_PCI_COMPAT) += pci_compat.o
>  obj-$(CONFIG_PCI_SANDBOX) += pci_sandbox.o
> @@ -14,7 +15,7 @@ obj-$(CONFIG_X86) += pci_x86.o
>  else
>  obj-$(CONFIG_PCI) += pci.o pci_auto_old.o
>  endif
> -obj-$(CONFIG_PCI) += pci_auto_common.o pci_common.o pci_rom.o
> +obj-$(CONFIG_PCI) += pci_auto_common.o pci_common.o
>
>  obj-$(CONFIG_FSL_PCI_INIT) += fsl_pci_init.o
>  obj-$(CONFIG_PCI_INDIRECT_BRIDGE) += pci_indirect.o
> diff --git a/drivers/pci/pci_rom.c b/drivers/pci/pci_rom.c
> index d244543..5989bad 100644
> --- a/drivers/pci/pci_rom.c
> +++ b/drivers/pci/pci_rom.c
> @@ -25,6 +25,7 @@
>
>  #include <common.h>
>  #include <bios_emul.h>
> +#include <dm.h>
>  #include <errno.h>
>  #include <malloc.h>
>  #include <pci.h>
> @@ -37,12 +38,12 @@
>  #include <asm/acpi.h>
>  #endif
>
> -__weak bool board_should_run_oprom(pci_dev_t dev)
> +__weak bool board_should_run_oprom(struct udevice *dev)
>  {
>         return true;
>  }
>
> -static bool should_load_oprom(pci_dev_t dev)
> +static bool should_load_oprom(struct udevice *dev)
>  {
>  #ifdef CONFIG_HAVE_ACPI_RESUME
>         if (acpi_get_slp_type() == 3)
> @@ -61,21 +62,18 @@ __weak uint32_t board_map_oprom_vendev(uint32_t vendev)
>         return vendev;
>  }
>
> -static int pci_rom_probe(pci_dev_t dev, uint class,
> -                        struct pci_rom_header **hdrp)
> +static int pci_rom_probe(struct udevice *dev, struct pci_rom_header **hdrp)
>  {
> +       struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
>         struct pci_rom_header *rom_header;
>         struct pci_rom_data *rom_data;
> -       u16 vendor, device;
>         u16 rom_vendor, rom_device;
>         u32 rom_class;
>         u32 vendev;
>         u32 mapped_vendev;
>         u32 rom_address;
>
> -       pci_read_config_word(dev, PCI_VENDOR_ID, &vendor);
> -       pci_read_config_word(dev, PCI_DEVICE_ID, &device);
> -       vendev = vendor << 16 | device;
> +       vendev = pplat->vendor << 16 | pplat->device;
>         mapped_vendev = board_map_oprom_vendev(vendev);
>         if (vendev != mapped_vendev)
>                 debug("Device ID mapped to %#08x\n", mapped_vendev);
> @@ -84,15 +82,15 @@ static int pci_rom_probe(pci_dev_t dev, uint class,
>         rom_address = CONFIG_VGA_BIOS_ADDR;
>  #else
>
> -       pci_read_config_dword(dev, PCI_ROM_ADDRESS, &rom_address);
> +       dm_pci_read_config32(dev, PCI_ROM_ADDRESS, &rom_address);
>         if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
>                 debug("%s: rom_address=%x\n", __func__, rom_address);
>                 return -ENOENT;
>         }
>
>         /* Enable expansion ROM address decoding. */
> -       pci_write_config_dword(dev, PCI_ROM_ADDRESS,
> -                              rom_address | PCI_ROM_ADDRESS_ENABLE);
> +       dm_pci_write_config32(dev, PCI_ROM_ADDRESS,
> +                             rom_address | PCI_ROM_ADDRESS_ENABLE);
>  #endif
>         debug("Option ROM address %x\n", rom_address);
>         rom_header = (struct pci_rom_header *)(unsigned long)rom_address;
> @@ -106,7 +104,7 @@ static int pci_rom_probe(pci_dev_t dev, uint class,
>                        le16_to_cpu(rom_header->signature));
>  #ifndef CONFIG_VGA_BIOS_ADDR
>                 /* Disable expansion ROM address decoding */
> -               pci_write_config_dword(dev, PCI_ROM_ADDRESS, rom_address);
> +               dm_pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address);
>  #endif
>                 return -EINVAL;
>         }
> @@ -119,7 +117,7 @@ static int pci_rom_probe(pci_dev_t dev, uint class,
>               rom_vendor, rom_device);
>
>         /* If the device id is mapped, a mismatch is expected */
> -       if ((vendor != rom_vendor || device != rom_device) &&
> +       if ((pplat->vendor != rom_vendor || pplat->device != rom_device) &&
>             (vendev == mapped_vendev)) {
>                 printf("ID mismatch: vendor ID %04x, device ID %04x\n",
>                        rom_vendor, rom_device);
> @@ -130,9 +128,9 @@ static int pci_rom_probe(pci_dev_t dev, uint class,
>         debug("PCI ROM image, Class Code %06x, Code Type %02x\n",
>               rom_class, rom_data->type);
>
> -       if (class != rom_class) {
> +       if (pplat->class != rom_class) {
>                 debug("Class Code mismatch ROM %06x, dev %06x\n",
> -                     rom_class, class);
> +                     rom_class, pplat->class);
>         }
>         *hdrp = rom_header;
>
> @@ -259,27 +257,26 @@ void setup_video(struct screen_info *screen_info)
>         screen_info->rsvd_pos = vesa->reserved_mask_pos;
>  }
>
> -int pci_run_vga_bios(pci_dev_t dev, int (*int15_handler)(void), int exec_method)
> +int dm_pci_run_vga_bios(struct udevice *dev, int (*int15_handler)(void),
> +                       int exec_method)
>  {
> +       struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
>         struct pci_rom_header *rom, *ram;
>         int vesa_mode = -1;
> -       uint class;
>         bool emulate;
>         int ret;
>
>         /* Only execute VGA ROMs */
> -       pci_read_config_dword(dev, PCI_REVISION_ID, &class);
> -       if (((class >> 16) ^ PCI_CLASS_DISPLAY_VGA) & 0xff00) {
> -               debug("%s: Class %#x, should be %#x\n", __func__, class,
> +       if (((pplat->class >> 8) ^ PCI_CLASS_DISPLAY_VGA) & 0xff00) {
> +               debug("%s: Class %#x, should be %#x\n", __func__, pplat->class,
>                       PCI_CLASS_DISPLAY_VGA);
>                 return -ENODEV;
>         }
> -       class >>= 8;
>
>         if (!should_load_oprom(dev))
>                 return -ENXIO;
>
> -       ret = pci_rom_probe(dev, class, &rom);
> +       ret = pci_rom_probe(dev, &rom);
>         if (ret)
>                 return ret;
>
> @@ -322,12 +319,12 @@ int pci_run_vga_bios(pci_dev_t dev, int (*int15_handler)(void), int exec_method)
>  #ifdef CONFIG_BIOSEMU
>                 BE_VGAInfo *info;
>
> -               ret = biosemu_setup(dev, &info);
> +               ret = biosemu_setup(dm_pci_get_bdf(dev), &info);
>                 if (ret)
>                         return ret;
>                 biosemu_set_interrupt_handler(0x15, int15_handler);
> -               ret = biosemu_run(dev, (uchar *)ram, 1 << 16, info, true,
> -                                 vesa_mode, &mode_info);
> +               ret = biosemu_run(dm_pci_get_bdf(dev), (uchar *)ram, 1 << 16,
> +                                 info, true, vesa_mode, &mode_info);
>                 if (ret)
>                         return ret;
>  #endif
> @@ -335,8 +332,8 @@ int pci_run_vga_bios(pci_dev_t dev, int (*int15_handler)(void), int exec_method)
>  #ifdef CONFIG_X86
>                 bios_set_interrupt_handler(0x15, int15_handler);
>
> -               bios_run_on_x86(dev, (unsigned long)ram, vesa_mode,
> -                               &mode_info);
> +               bios_run_on_x86(dm_pci_get_bdf(dev), (unsigned long)ram,
> +                               vesa_mode, &mode_info);
>  #endif
>         }
>         debug("Final vesa mode %#x\n", mode_info.video_mode);
> diff --git a/drivers/video/vesa_fb.c b/drivers/video/vesa_fb.c
> index a19651f..021c1d6 100644
> --- a/drivers/video/vesa_fb.c
> +++ b/drivers/video/vesa_fb.c
> @@ -19,8 +19,8 @@ GraphicDevice ctfb;
>  void *video_hw_init(void)
>  {
>         GraphicDevice *gdev = &ctfb;
> +       struct udevice *dev;
>         int bits_per_pixel;
> -       pci_dev_t dev;
>         int ret;
>
>         printf("Video: ");
> @@ -33,14 +33,14 @@ void *video_hw_init(void)
>                 return NULL;
>         }
>         if (vbe_get_video_info(gdev)) {
> -               dev = pci_find_class(PCI_CLASS_DISPLAY_VGA << 8, 0);
> -               if (dev < 0) {
> +               ret = dm_pci_find_class(PCI_CLASS_DISPLAY_VGA << 8, 0, &dev);
> +               if (ret) {
>                         printf("no card detected\n");
>                         return NULL;
>                 }
>                 bootstage_start(BOOTSTAGE_ID_ACCUM_LCD, "vesa display");
> -               ret = pci_run_vga_bios(dev, NULL, PCI_ROM_USE_NATIVE |
> -                                      PCI_ROM_ALLOW_FALLBACK);
> +               ret = dm_pci_run_vga_bios(dev, NULL, PCI_ROM_USE_NATIVE |
> +                                         PCI_ROM_ALLOW_FALLBACK);
>                 bootstage_accum(BOOTSTAGE_ID_ACCUM_LCD);
>                 if (ret) {
>                         printf("failed to run video BIOS: %d\n", ret);
> diff --git a/include/pci_rom.h b/include/pci_rom.h
> index 2f1665d..95c6d07 100644
> --- a/include/pci_rom.h
> +++ b/include/pci_rom.h
> @@ -44,14 +44,14 @@ enum pci_rom_emul {
>  };
>
>   /**
> - * pci_run_vga_bios() - Run the VGA BIOS in an x86 PC
> + * dm_pci_run_vga_bios() - Run the VGA BIOS in an x86 PC
>   *
>   * @dev:       Video device containing the BIOS
>   * @int15_handler:     Function to call to handle int 0x15
>   * @exec_method:       flags from enum pci_rom_emul
>   */
> -int pci_run_vga_bios(pci_dev_t dev, int (*int15_handler)(void),
> -                    int exec_method);
> +int dm_pci_run_vga_bios(struct udevice *dev, int (*int15_handler)(void),
> +                       int exec_method);
>
>  /**
>   * board_map_oprom_vendev() - map several PCI IDs to the one the ROM expects
> --

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
Tested-by: Bin Meng <bmeng.cn at gmail.com>


More information about the U-Boot mailing list