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.
25 * PCI configuration space access via PCI BIOS
30 * Determine maximum PCI bus number within system
32 * @ret max_bus Maximum bus number
34 static int pcibios_max_bus ( void ) {
35 int discard_a, discard_D;
38 __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
43 : "=c" ( max_bus ), "=a" ( discard_a ),
45 : "a" ( PCIBIOS_INSTALLATION_CHECK >> 16 ),
53 * Read configuration space via PCI BIOS
56 * @v command PCI BIOS command
58 * @ret rc Return status code
60 int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
61 int discard_b, discard_D;
64 __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
67 "xorl %%eax, %%eax\n\t"
69 "movl %%eax, %%ecx\n\t"
71 : "=a" ( status ), "=b" ( discard_b ),
72 "=c" ( *value ), "=D" ( discard_D )
73 : "a" ( command >> 16 ), "D" ( command ),
74 "b" ( PCI_BUSDEVFN ( pci->bus, pci->devfn ) )
77 return ( ( status >> 8 ) & 0xff );
81 * Write configuration space via PCI BIOS
84 * @v command PCI BIOS command
85 * @v value Value to be written
86 * @ret rc Return status code
88 int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
89 int discard_b, discard_c, discard_D;
92 __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
95 "movb $0xff, %%ah\n\t"
97 : "=a" ( status ), "=b" ( discard_b ),
98 "=c" ( discard_c ), "=D" ( discard_D )
99 : "a" ( command >> 16 ), "D" ( command ),
100 "b" ( PCI_BUSDEVFN ( pci->bus, pci->devfn ) ),
104 return ( ( status >> 8 ) & 0xff );
107 PROVIDE_PCIAPI ( pcbios, pci_max_bus, pcibios_max_bus );
108 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_byte );
109 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_word );
110 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_dword );
111 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_byte );
112 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_word );
113 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_dword );