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., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 #include <stdint.h>
00022 #include <gpxe/pci.h>
00023 #include <realmode.h>
00024 
00025 /** @file
00026  *
00027  * PCI configuration space access via PCI BIOS
00028  *
00029  */
00030 
00031 /**
00032  * Determine maximum PCI bus number within system
00033  *
00034  * @ret max_bus         Maximum bus number
00035  */
00036 static int pcibios_max_bus ( void ) {
00037         int discard_a, discard_D;
00038         uint8_t max_bus;
00039 
00040         __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
00041                                            "int $0x1a\n\t"
00042                                            "jnc 1f\n\t"
00043                                            "xorw %%cx, %%cx\n\t"
00044                                            "\n1:\n\t" )
00045                                : "=c" ( max_bus ), "=a" ( discard_a ),
00046                                  "=D" ( discard_D )
00047                                : "a" ( PCIBIOS_INSTALLATION_CHECK >> 16 ),
00048                                  "D" ( 0 )
00049                                : "ebx", "edx" );
00050 
00051         return max_bus;
00052 }
00053 
00054 /**
00055  * Read configuration space via PCI BIOS
00056  *
00057  * @v pci       PCI device
00058  * @v command   PCI BIOS command
00059  * @v value     Value read
00060  * @ret rc      Return status code
00061  */
00062 int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
00063         int discard_b, discard_D;
00064         int status;
00065 
00066         __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
00067                                            "int $0x1a\n\t"
00068                                            "jnc 1f\n\t"
00069                                            "xorl %%eax, %%eax\n\t"
00070                                            "decl %%eax\n\t"
00071                                            "movl %%eax, %%ecx\n\t"
00072                                            "\n1:\n\t" )
00073                                : "=a" ( status ), "=b" ( discard_b ),
00074                                  "=c" ( *value ), "=D" ( discard_D )
00075                                : "a" ( command >> 16 ), "D" ( command ),
00076                                  "b" ( PCI_BUSDEVFN ( pci->bus, pci->devfn ) )
00077                                : "edx" );
00078 
00079         return ( ( status >> 8 ) & 0xff );
00080 }
00081 
00082 /**
00083  * Write configuration space via PCI BIOS
00084  *
00085  * @v pci       PCI device
00086  * @v command   PCI BIOS command
00087  * @v value     Value to be written
00088  * @ret rc      Return status code
00089  */
00090 int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
00091         int discard_b, discard_c, discard_D;
00092         int status;
00093 
00094         __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
00095                                            "int $0x1a\n\t"
00096                                            "jnc 1f\n\t"
00097                                            "movb $0xff, %%ah\n\t"
00098                                            "\n1:\n\t" )
00099                                : "=a" ( status ), "=b" ( discard_b ),
00100                                  "=c" ( discard_c ), "=D" ( discard_D )
00101                                : "a" ( command >> 16 ), "D" ( command ),
00102                                  "b" ( PCI_BUSDEVFN ( pci->bus, pci->devfn ) ),
00103                                  "c" ( value )
00104                                : "edx" );
00105         
00106         return ( ( status >> 8 ) & 0xff );
00107 }
00108 
00109 PROVIDE_PCIAPI ( pcbios, pci_max_bus, pcibios_max_bus );
00110 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_byte );
00111 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_word );
00112 PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_dword );
00113 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_byte );
00114 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_word );
00115 PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_dword );

Generated on Tue Apr 6 20:00:50 2010 for gPXE by  doxygen 1.5.7.1