iPXE
pcibios.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <stdint.h>
00027 #include <ipxe/pci.h>
00028 #include <realmode.h>
00029 
00030 /** @file
00031  *
00032  * PCI configuration space access via PCI BIOS
00033  *
00034  */
00035 
00036 /**
00037  * Determine number of PCI buses within system
00038  *
00039  * @ret num_bus         Number of buses
00040  */
00041 static int pcibios_num_bus ( void ) {
00042         int discard_a, discard_D;
00043         uint8_t max_bus;
00044 
00045         /* We issue this call using flat real mode, to work around a
00046          * bug in some HP BIOSes.
00047          */
00048         __asm__ __volatile__ ( REAL_CODE ( "call flatten_real_mode\n\t"
00049                                            "stc\n\t"
00050                                            "int $0x1a\n\t"
00051                                            "jnc 1f\n\t"
00052                                            "xorw %%cx, %%cx\n\t"
00053                                            "\n1:\n\t" )
00054                                : "=c" ( max_bus ), "=a" ( discard_a ),
00055                                  "=D" ( discard_D )
00056                                : "a" ( PCIBIOS_INSTALLATION_CHECK >> 16 ),
00057                                  "D" ( 0 )
00058                                : "ebx", "edx" );
00059 
00060         return ( max_bus + 1 );
00061 }
00062 
00063 /**
00064  * Read configuration space via PCI BIOS
00065  *
00066  * @v pci       PCI device
00067  * @v command   PCI BIOS command
00068  * @v value     Value read
00069  * @ret rc      Return status code
00070  */
00071 int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
00072         int discard_b, discard_D;
00073         uint16_t status;
00074 
00075         __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
00076                                            "int $0x1a\n\t"
00077                                            "jnc 1f\n\t"
00078                                            "xorl %%eax, %%eax\n\t"
00079                                            "decl %%eax\n\t"
00080                                            "movl %%eax, %%ecx\n\t"
00081                                            "\n1:\n\t" )
00082                                : "=a" ( status ), "=b" ( discard_b ),
00083                                  "=c" ( *value ), "=D" ( discard_D )
00084                                : "a" ( command >> 16 ), "D" ( command ),
00085                                  "b" ( pci->busdevfn )
00086                                : "edx" );
00087 
00088         return ( status >> 8 );
00089 }
00090 
00091 /**
00092  * Write configuration space via PCI BIOS
00093  *
00094  * @v pci       PCI device
00095  * @v command   PCI BIOS command
00096  * @v value     Value to be written
00097  * @ret rc      Return status code
00098  */
00099 int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
00100         int discard_b, discard_c, discard_D;
00101         uint16_t status;
00102 
00103         __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
00104                                            "int $0x1a\n\t"
00105                                            "jnc 1f\n\t"
00106                                            "movb $0xff, %%ah\n\t"
00107                                            "\n1:\n\t" )
00108                                : "=a" ( status ), "=b" ( discard_b ),
00109                                  "=c" ( discard_c ), "=D" ( discard_D )
00110                                : "a" ( command >> 16 ), "D" ( command ),
00111                                  "b" ( pci->busdevfn ), "c" ( value )
00112                                : "edx" );
00113         
00114         return ( status >> 8 );
00115 }
00116 
00117 PROVIDE_PCIAPI ( pcbios, pci_num_bus, pcibios_num_bus );
00118 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_byte );
00119 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_word );
00120 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_dword );
00121 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_byte );
00122 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_word );
00123 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_dword );