irq.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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-11-07 GuEe-GUI first version
  9. */
  10. #include <rtthread.h>
  11. #define DBG_TAG "pci.irq"
  12. #define DBG_LVL DBG_INFO
  13. #include <rtdbg.h>
  14. #include <drivers/pci.h>
  15. void rt_pci_assign_irq(struct rt_pci_device *pdev)
  16. {
  17. int irq = 0;
  18. rt_uint8_t pin, slot = -1;
  19. struct rt_pci_host_bridge *host_bridge = rt_pci_find_host_bridge(pdev->bus);
  20. if (!host_bridge->irq_map)
  21. {
  22. LOG_D("PCI-Device<%s> runtime IRQ mapping not provided by platform",
  23. rt_dm_dev_get_name(&pdev->parent));
  24. return;
  25. }
  26. /* Must try the swizzle when interrupt line passes through a P2P bridge */
  27. rt_pci_read_config_u8(pdev, PCIR_INTPIN, &pin);
  28. if (pin > RT_PCI_INTX_PIN_MAX)
  29. {
  30. pin = 1;
  31. }
  32. if (pin)
  33. {
  34. if (host_bridge->irq_slot)
  35. {
  36. slot = host_bridge->irq_slot(pdev, &pin);
  37. }
  38. /* Map IRQ */
  39. if ((irq = host_bridge->irq_map(pdev, slot, pin)) == -1)
  40. {
  41. irq = 0;
  42. }
  43. }
  44. pdev->irq = irq;
  45. LOG_D("PCI-Device<%s> assign IRQ: got %d", rt_dm_dev_get_name(&pdev->parent), pdev->irq);
  46. /* Save IRQ */
  47. rt_pci_write_config_u8(pdev, PCIR_INTLINE, irq);
  48. }