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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <stdint.h>
  19. #include <gpxe/pci.h>
  20. #include <pcibios.h>
  21. #include <realmode.h>
  22. /** @file
  23. *
  24. * PCI configuration space access via PCI BIOS
  25. *
  26. */
  27. /**
  28. * Determine maximum PCI bus number within system
  29. *
  30. * @ret max_bus Maximum bus number
  31. */
  32. int pcibios_max_bus ( void ) {
  33. int discard_a, discard_D;
  34. uint8_t max_bus;
  35. __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
  36. "int $0x1a\n\t"
  37. "jnc 1f\n\t"
  38. "xorw %%cx, %%cx\n\t"
  39. "\n1:\n\t" )
  40. : "=c" ( max_bus ), "=a" ( discard_a ),
  41. "=D" ( discard_D )
  42. : "a" ( PCIBIOS_INSTALLATION_CHECK >> 16 ),
  43. "D" ( 0 )
  44. : "ebx", "edx" );
  45. return max_bus;
  46. }
  47. /**
  48. * Read configuration space via PCI BIOS
  49. *
  50. * @v pci PCI device
  51. * @v command PCI BIOS command
  52. * @v value Value read
  53. * @ret rc Return status code
  54. */
  55. int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
  56. int discard_b, discard_D;
  57. int status;
  58. __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
  59. "int $0x1a\n\t"
  60. "jnc 1f\n\t"
  61. "xorl %%eax, %%eax\n\t"
  62. "decl %%eax\n\t"
  63. "movl %%eax, %%ecx\n\t"
  64. "\n1:\n\t" )
  65. : "=a" ( status ), "=b" ( discard_b ),
  66. "=c" ( *value ), "=D" ( discard_D )
  67. : "a" ( command >> 16 ), "D" ( command ),
  68. "b" ( ( pci->bus << 8 ) | pci->devfn )
  69. : "edx" );
  70. return ( ( status >> 8 ) & 0xff );
  71. }
  72. /**
  73. * Write configuration space via PCI BIOS
  74. *
  75. * @v pci PCI device
  76. * @v command PCI BIOS command
  77. * @v value Value to be written
  78. * @ret rc Return status code
  79. */
  80. int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
  81. int discard_b, discard_c, discard_D;
  82. int status;
  83. __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
  84. "int $0x1a\n\t"
  85. "jnc 1f\n\t"
  86. "movb $0xff, %%ah\n\t"
  87. "\n1:\n\t" )
  88. : "=a" ( status ), "=b" ( discard_b ),
  89. "=c" ( discard_c ), "=D" ( discard_D )
  90. : "a" ( command >> 16 ), "D" ( command ),
  91. "b" ( ( pci->bus << 8 ) | pci->devfn ),
  92. "c" ( value )
  93. : "edx" );
  94. return ( ( status >> 8 ) & 0xff );
  95. }