Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

pcibios.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. /* We issue this call using flat real mode, to work around a
  41. * bug in some HP BIOSes.
  42. */
  43. __asm__ __volatile__ ( REAL_CODE ( "call flatten_real_mode\n\t"
  44. "stc\n\t"
  45. "int $0x1a\n\t"
  46. "jnc 1f\n\t"
  47. "xorw %%cx, %%cx\n\t"
  48. "\n1:\n\t" )
  49. : "=c" ( max_bus ), "=a" ( discard_a ),
  50. "=D" ( discard_D )
  51. : "a" ( PCIBIOS_INSTALLATION_CHECK >> 16 ),
  52. "D" ( 0 )
  53. : "ebx", "edx" );
  54. return ( max_bus + 1 );
  55. }
  56. /**
  57. * Read configuration space via PCI BIOS
  58. *
  59. * @v pci PCI device
  60. * @v command PCI BIOS command
  61. * @v value Value read
  62. * @ret rc Return status code
  63. */
  64. int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
  65. int discard_b, discard_D;
  66. uint16_t status;
  67. __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
  68. "int $0x1a\n\t"
  69. "jnc 1f\n\t"
  70. "xorl %%eax, %%eax\n\t"
  71. "decl %%eax\n\t"
  72. "movl %%eax, %%ecx\n\t"
  73. "\n1:\n\t" )
  74. : "=a" ( status ), "=b" ( discard_b ),
  75. "=c" ( *value ), "=D" ( discard_D )
  76. : "a" ( command >> 16 ), "D" ( command ),
  77. "b" ( pci->busdevfn )
  78. : "edx" );
  79. return ( status >> 8 );
  80. }
  81. /**
  82. * Write configuration space via PCI BIOS
  83. *
  84. * @v pci PCI device
  85. * @v command PCI BIOS command
  86. * @v value Value to be written
  87. * @ret rc Return status code
  88. */
  89. int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
  90. int discard_b, discard_c, discard_D;
  91. uint16_t status;
  92. __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
  93. "int $0x1a\n\t"
  94. "jnc 1f\n\t"
  95. "movb $0xff, %%ah\n\t"
  96. "\n1:\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 ), "c" ( value )
  101. : "edx" );
  102. return ( status >> 8 );
  103. }
  104. PROVIDE_PCIAPI ( pcbios, pci_num_bus, pcibios_num_bus );
  105. PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_byte );
  106. PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_word );
  107. PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_dword );
  108. PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_byte );
  109. PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_word );
  110. PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_dword );