pci.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * (C) Copyright 2008,2009
  4. * Graeme Russ, <graeme.russ@gmail.com>
  5. *
  6. * (C) Copyright 2002
  7. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <errno.h>
  13. #include <malloc.h>
  14. #include <pci.h>
  15. #include <asm/pci.h>
  16. static struct pci_controller x86_hose;
  17. int pci_early_init_hose(struct pci_controller **hosep)
  18. {
  19. struct pci_controller *hose;
  20. hose = calloc(1, sizeof(struct pci_controller));
  21. if (!hose)
  22. return -ENOMEM;
  23. board_pci_setup_hose(hose);
  24. pci_setup_type1(hose);
  25. gd->arch.hose = hose;
  26. *hosep = hose;
  27. return 0;
  28. }
  29. __weak int board_pci_pre_scan(struct pci_controller *hose)
  30. {
  31. return 0;
  32. }
  33. __weak int board_pci_post_scan(struct pci_controller *hose)
  34. {
  35. return 0;
  36. }
  37. void pci_init_board(void)
  38. {
  39. struct pci_controller *hose = &x86_hose;
  40. /* Stop using the early hose */
  41. gd->arch.hose = NULL;
  42. board_pci_setup_hose(hose);
  43. pci_setup_type1(hose);
  44. pci_register_hose(hose);
  45. board_pci_pre_scan(hose);
  46. hose->last_busno = pci_hose_scan(hose);
  47. board_pci_post_scan(hose);
  48. }
  49. static struct pci_controller *get_hose(void)
  50. {
  51. if (gd->arch.hose)
  52. return gd->arch.hose;
  53. return pci_bus_to_hose(0);
  54. }
  55. unsigned int pci_read_config8(pci_dev_t dev, unsigned where)
  56. {
  57. uint8_t value;
  58. pci_hose_read_config_byte(get_hose(), dev, where, &value);
  59. return value;
  60. }
  61. unsigned int pci_read_config16(pci_dev_t dev, unsigned where)
  62. {
  63. uint16_t value;
  64. pci_hose_read_config_word(get_hose(), dev, where, &value);
  65. return value;
  66. }
  67. unsigned int pci_read_config32(pci_dev_t dev, unsigned where)
  68. {
  69. uint32_t value;
  70. pci_hose_read_config_dword(get_hose(), dev, where, &value);
  71. return value;
  72. }
  73. void pci_write_config8(pci_dev_t dev, unsigned where, unsigned value)
  74. {
  75. pci_hose_write_config_byte(get_hose(), dev, where, value);
  76. }
  77. void pci_write_config16(pci_dev_t dev, unsigned where, unsigned value)
  78. {
  79. pci_hose_write_config_word(get_hose(), dev, where, value);
  80. }
  81. void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value)
  82. {
  83. pci_hose_write_config_dword(get_hose(), dev, where, value);
  84. }