@ -25,6 +25,7 @@
# include <common.h>
# include <common.h>
# include <bios_emul.h>
# include <bios_emul.h>
# include <dm.h>
# include <errno.h>
# include <errno.h>
# include <malloc.h>
# include <malloc.h>
# include <pci.h>
# include <pci.h>
@ -33,12 +34,12 @@
# include <video_fb.h>
# include <video_fb.h>
# include <linux/screen_info.h>
# include <linux/screen_info.h>
__weak bool board_should_run_oprom ( pci_dev_t dev )
__weak bool board_should_run_oprom ( struct udevice * dev )
{
{
return true ;
return true ;
}
}
static bool should_load_oprom ( pci_dev_t dev )
static bool should_load_oprom ( struct udevice * dev )
{
{
if ( IS_ENABLED ( CONFIG_ALWAYS_LOAD_OPROM ) )
if ( IS_ENABLED ( CONFIG_ALWAYS_LOAD_OPROM ) )
return 1 ;
return 1 ;
@ -53,21 +54,18 @@ __weak uint32_t board_map_oprom_vendev(uint32_t vendev)
return vendev ;
return vendev ;
}
}
static int pci_rom_probe ( pci_dev_t dev , uint class ,
static int pci_rom_probe ( struct udevice * dev , struct pci_rom_header * * hdrp )
struct pci_rom_header * * hdrp )
{
{
struct pci_child_platdata * pplat = dev_get_parent_platdata ( dev ) ;
struct pci_rom_header * rom_header ;
struct pci_rom_header * rom_header ;
struct pci_rom_data * rom_data ;
struct pci_rom_data * rom_data ;
u16 vendor , device ;
u16 rom_vendor , rom_device ;
u16 rom_vendor , rom_device ;
u32 rom_class ;
u32 rom_class ;
u32 vendev ;
u32 vendev ;
u32 mapped_vendev ;
u32 mapped_vendev ;
u32 rom_address ;
u32 rom_address ;
pci_read_config_word ( dev , PCI_VENDOR_ID , & vendor ) ;
vendev = pplat - > vendor < < 16 | pplat - > device ;
pci_read_config_word ( dev , PCI_DEVICE_ID , & device ) ;
vendev = vendor < < 16 | device ;
mapped_vendev = board_map_oprom_vendev ( vendev ) ;
mapped_vendev = board_map_oprom_vendev ( vendev ) ;
if ( vendev ! = mapped_vendev )
if ( vendev ! = mapped_vendev )
debug ( " Device ID mapped to %#08x \n " , mapped_vendev ) ;
debug ( " Device ID mapped to %#08x \n " , mapped_vendev ) ;
@ -76,15 +74,15 @@ static int pci_rom_probe(pci_dev_t dev, uint class,
rom_address = CONFIG_VGA_BIOS_ADDR ;
rom_address = CONFIG_VGA_BIOS_ADDR ;
# else
# 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 ) {
if ( rom_address = = 0x00000000 | | rom_address = = 0xffffffff ) {
debug ( " %s: rom_address=%x \n " , __func__ , rom_address ) ;
debug ( " %s: rom_address=%x \n " , __func__ , rom_address ) ;
return - ENOENT ;
return - ENOENT ;
}
}
/* Enable expansion ROM address decoding. */
/* Enable expansion ROM address decoding. */
pci_write_config_dword ( dev , PCI_ROM_ADDRESS ,
dm_pci_write_config32 ( dev , PCI_ROM_ADDRESS ,
rom_address | PCI_ROM_ADDRESS_ENABLE ) ;
rom_address | PCI_ROM_ADDRESS_ENABLE ) ;
# endif
# endif
debug ( " Option ROM address %x \n " , rom_address ) ;
debug ( " Option ROM address %x \n " , rom_address ) ;
rom_header = ( struct pci_rom_header * ) ( unsigned long ) rom_address ;
rom_header = ( struct pci_rom_header * ) ( unsigned long ) rom_address ;
@ -98,7 +96,7 @@ static int pci_rom_probe(pci_dev_t dev, uint class,
le16_to_cpu ( rom_header - > signature ) ) ;
le16_to_cpu ( rom_header - > signature ) ) ;
# ifndef CONFIG_VGA_BIOS_ADDR
# ifndef CONFIG_VGA_BIOS_ADDR
/* Disable expansion ROM address decoding */
/* 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
# endif
return - EINVAL ;
return - EINVAL ;
}
}
@ -111,7 +109,7 @@ static int pci_rom_probe(pci_dev_t dev, uint class,
rom_vendor , rom_device ) ;
rom_vendor , rom_device ) ;
/* If the device id is mapped, a mismatch is expected */
/* 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 ) ) {
( vendev = = mapped_vendev ) ) {
printf ( " ID mismatch: vendor ID %04x, device ID %04x \n " ,
printf ( " ID mismatch: vendor ID %04x, device ID %04x \n " ,
rom_vendor , rom_device ) ;
rom_vendor , rom_device ) ;
@ -122,9 +120,9 @@ static int pci_rom_probe(pci_dev_t dev, uint class,
debug ( " PCI ROM image, Class Code %06x, Code Type %02x \n " ,
debug ( " PCI ROM image, Class Code %06x, Code Type %02x \n " ,
rom_class , rom_data - > type ) ;
rom_class , rom_data - > type ) ;
if ( class ! = rom_class ) {
if ( pplat - > class ! = rom_class ) {
debug ( " Class Code mismatch ROM %06x, dev %06x \n " ,
debug ( " Class Code mismatch ROM %06x, dev %06x \n " ,
rom_class , class ) ;
rom_class , pplat - > class ) ;
}
}
* hdrp = rom_header ;
* hdrp = rom_header ;
@ -251,27 +249,26 @@ void setup_video(struct screen_info *screen_info)
screen_info - > rsvd_pos = vesa - > reserved_mask_pos ;
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 ;
struct pci_rom_header * rom , * ram ;
int vesa_mode = - 1 ;
int vesa_mode = - 1 ;
uint class ;
bool emulate ;
bool emulate ;
int ret ;
int ret ;
/* Only execute VGA ROMs */
/* Only execute VGA ROMs */
pci_read_config_dword ( dev , PCI_REVISION_ID , & class ) ;
if ( ( ( pplat - > class > > 8 ) ^ PCI_CLASS_DISPLAY_VGA ) & 0xff00 ) {
if ( ( ( class > > 16 ) ^ PCI_CLASS_DISPLAY_VGA ) & 0xff00 ) {
debug ( " %s: Class %#x, should be %#x \n " , __func__ , pplat - > class ,
debug ( " %s: Class %#x, should be %#x \n " , __func__ , class ,
PCI_CLASS_DISPLAY_VGA ) ;
PCI_CLASS_DISPLAY_VGA ) ;
return - ENODEV ;
return - ENODEV ;
}
}
class > > = 8 ;
if ( ! should_load_oprom ( dev ) )
if ( ! should_load_oprom ( dev ) )
return - ENXIO ;
return - ENXIO ;
ret = pci_rom_probe ( dev , class , & rom ) ;
ret = pci_rom_probe ( dev , & rom ) ;
if ( ret )
if ( ret )
return ret ;
return ret ;
@ -314,12 +311,12 @@ int pci_run_vga_bios(pci_dev_t dev, int (*int15_handler)(void), int exec_method)
# ifdef CONFIG_BIOSEMU
# ifdef CONFIG_BIOSEMU
BE_VGAInfo * info ;
BE_VGAInfo * info ;
ret = biosemu_setup ( dev , & info ) ;
ret = biosemu_setup ( dm_pci_get_bdf ( d ev ) , & info ) ;
if ( ret )
if ( ret )
return ret ;
return ret ;
biosemu_set_interrupt_handler ( 0x15 , int15_handler ) ;
biosemu_set_interrupt_handler ( 0x15 , int15_handler ) ;
ret = biosemu_run ( dev , ( uchar * ) ram , 1 < < 16 , info , true ,
ret = biosemu_run ( dm_pci_get_bdf ( d ev ) , ( uchar * ) ram , 1 < < 16 ,
vesa_mode , & mode_info ) ;
info , true , vesa_mode , & mode_info ) ;
if ( ret )
if ( ret )
return ret ;
return ret ;
# endif
# endif
@ -327,8 +324,8 @@ int pci_run_vga_bios(pci_dev_t dev, int (*int15_handler)(void), int exec_method)
# ifdef CONFIG_X86
# ifdef CONFIG_X86
bios_set_interrupt_handler ( 0x15 , int15_handler ) ;
bios_set_interrupt_handler ( 0x15 , int15_handler ) ;
bios_run_on_x86 ( dev , ( unsigned long ) ram , vesa_mode ,
bios_run_on_x86 ( dm_pci_get_bdf ( d ev ) , ( unsigned long ) ram ,
& mode_info ) ;
vesa_mode , & mode_info ) ;
# endif
# endif
}
}
debug ( " Final vesa mode %#x \n " , mode_info . video_mode ) ;
debug ( " Final vesa mode %#x \n " , mode_info . video_mode ) ;