You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pcibios.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  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.
  8. *
  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.
  13. *
  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., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <stdint.h>
  25. #include <ipxe/pci.h>
  26. #include <realmode.h>
  27. /** @file
  28. *
  29. * PCI configuration space access via PCI BIOS
  30. *
  31. */
  32. /**
  33. * Determine number of PCI buses within system
  34. *
  35. * @ret num_bus Number of buses
  36. */
  37. static int pcibios_num_bus ( void ) {
  38. int discard_a, discard_D;
  39. uint8_t max_bus;
  40. __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
  41. "int $0x1a\n\t"
  42. "jnc 1f\n\t"
  43. "xorw %%cx, %%cx\n\t"
  44. "\n1:\n\t" )
  45. : "=c" ( max_bus ), "=a" ( discard_a ),
  46. "=D" ( discard_D )
  47. : "a" ( PCIBIOS_INSTALLATION_CHECK >> 16 ),
  48. "D" ( 0 )
  49. : "ebx", "edx" );
  50. return ( max_bus + 1 );
  51. }
  52. /**
  53. * Read configuration space via PCI BIOS
  54. *
  55. * @v pci PCI device
  56. * @v command PCI BIOS command
  57. * @v value Value read
  58. * @ret rc Return status code
  59. */
  60. int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
  61. int discard_b, discard_D;
  62. int status;
  63. __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
  64. "int $0x1a\n\t"
  65. "jnc 1f\n\t"
  66. "xorl %%eax, %%eax\n\t"
  67. "decl %%eax\n\t"
  68. "movl %%eax, %%ecx\n\t"
  69. "\n1:\n\t" )
  70. : "=a" ( status ), "=b" ( discard_b ),
  71. "=c" ( *value ), "=D" ( discard_D )
  72. : "a" ( command >> 16 ), "D" ( command ),
  73. "b" ( pci->busdevfn )
  74. : "edx" );
  75. return ( ( status >> 8 ) & 0xff );
  76. }
  77. /**
  78. * Write configuration space via PCI BIOS
  79. *
  80. * @v pci PCI device
  81. * @v command PCI BIOS command
  82. * @v value Value to be written
  83. * @ret rc Return status code
  84. */
  85. int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
  86. int discard_b, discard_c, discard_D;
  87. int status;
  88. __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
  89. "int $0x1a\n\t"
  90. "jnc 1f\n\t"
  91. "movb $0xff, %%ah\n\t"
  92. "\n1:\n\t" )
  93. : "=a" ( status ), "=b" ( discard_b ),
  94. "=c" ( discard_c ), "=D" ( discard_D )
  95. : "a" ( command >> 16 ), "D" ( command ),
  96. "b" ( pci->busdevfn ), "c" ( value )
  97. : "edx" );
  98. return ( ( status >> 8 ) & 0xff );
  99. }
  100. PROVIDE_PCIAPI ( pcbios, pci_num_bus, pcibios_num_bus );
  101. PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_byte );
  102. PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_word );
  103. PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_dword );
  104. PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_byte );
  105. PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_word );
  106. PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_dword );