2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 FILE_LICENCE ( GPL2_OR_LATER
);
27 * PCI configuration space access via PCI BIOS
32 * Determine maximum PCI bus number within system
34 * @ret max_bus Maximum bus number
36 static int pcibios_max_bus ( void ) {
37 int discard_a
, discard_D
;
40 __asm__
__volatile__ ( REAL_CODE ( "stc\n\t"
45 : "=c" ( max_bus
), "=a" ( discard_a
),
47 : "a" ( PCIBIOS_INSTALLATION_CHECK
>> 16 ),
55 * Read configuration space via PCI BIOS
58 * @v command PCI BIOS command
60 * @ret rc Return status code
62 int pcibios_read ( struct pci_device
*pci
, uint32_t command
, uint32_t *value
){
63 int discard_b
, discard_D
;
66 __asm__
__volatile__ ( REAL_CODE ( "stc\n\t"
69 "xorl %%eax, %%eax\n\t"
71 "movl %%eax, %%ecx\n\t"
73 : "=a" ( status
), "=b" ( discard_b
),
74 "=c" ( *value
), "=D" ( discard_D
)
75 : "a" ( command
>> 16 ), "D" ( command
),
76 "b" ( PCI_BUSDEVFN ( pci
->bus
, pci
->devfn
) )
79 return ( ( status
>> 8 ) & 0xff );
83 * Write configuration space via PCI BIOS
86 * @v command PCI BIOS command
87 * @v value Value to be written
88 * @ret rc Return status code
90 int pcibios_write ( struct pci_device
*pci
, uint32_t command
, uint32_t value
){
91 int discard_b
, discard_c
, discard_D
;
94 __asm__
__volatile__ ( REAL_CODE ( "stc\n\t"
97 "movb $0xff, %%ah\n\t"
99 : "=a" ( status
), "=b" ( discard_b
),
100 "=c" ( discard_c
), "=D" ( discard_D
)
101 : "a" ( command
>> 16 ), "D" ( command
),
102 "b" ( PCI_BUSDEVFN ( pci
->bus
, pci
->devfn
) ),
106 return ( ( status
>> 8 ) & 0xff );
109 PROVIDE_PCIAPI ( pcbios
, pci_max_bus
, pcibios_max_bus
);
110 PROVIDE_PCIAPI_INLINE ( pcbios
, pci_read_config_byte
);
111 PROVIDE_PCIAPI_INLINE ( pcbios
, pci_read_config_word
);
112 PROVIDE_PCIAPI_INLINE ( pcbios
, pci_read_config_dword
);
113 PROVIDE_PCIAPI_INLINE ( pcbios
, pci_write_config_byte
);
114 PROVIDE_PCIAPI_INLINE ( pcbios
, pci_write_config_word
);
115 PROVIDE_PCIAPI_INLINE ( pcbios
, pci_write_config_dword
);