pci-host-common.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-10-24 GuEe-GUI first version
  9. */
  10. #include <rtthread.h>
  11. #include "../ecam.h"
  12. rt_err_t pci_host_common_probe(struct rt_platform_device *pdev)
  13. {
  14. void *base;
  15. rt_err_t err;
  16. struct rt_device *dev = &pdev->parent;
  17. struct pci_ecam_config_window *conf_win;
  18. struct rt_pci_host_bridge *host_bridge = rt_pci_host_bridge_alloc(0);
  19. if (!host_bridge)
  20. {
  21. return -RT_ENOMEM;
  22. }
  23. if (!(base = rt_dm_dev_iomap(dev, 0)))
  24. {
  25. err = -RT_EIO;
  26. goto _fail;
  27. }
  28. host_bridge->parent.ofw_node = dev->ofw_node;
  29. if ((err = rt_pci_host_bridge_init(host_bridge)))
  30. {
  31. goto _fail;
  32. }
  33. host_bridge->sysdata = conf_win = pci_ecam_create(host_bridge,
  34. (const struct pci_ecam_ops *)pdev->id->data);
  35. if (!conf_win)
  36. {
  37. err = -RT_ENOMEM;
  38. goto _fail;
  39. }
  40. conf_win->win = base;
  41. conf_win->priv = host_bridge;
  42. if ((err = rt_pci_host_bridge_probe(host_bridge)))
  43. {
  44. goto _fail;
  45. }
  46. dev->user_data = host_bridge;
  47. return RT_EOK;
  48. _fail:
  49. if (base)
  50. {
  51. rt_iounmap(base);
  52. }
  53. rt_pci_host_bridge_free(host_bridge);
  54. return err;
  55. }
  56. rt_err_t pci_host_common_remove(struct rt_platform_device *pdev)
  57. {
  58. struct pci_ecam_config_window *conf_win;
  59. struct rt_pci_host_bridge *host_bridge = pdev->parent.user_data;
  60. rt_pci_host_bridge_remove(host_bridge);
  61. conf_win = host_bridge->sysdata;
  62. rt_iounmap(conf_win->win);
  63. rt_pci_host_bridge_free(host_bridge);
  64. return RT_EOK;
  65. }