x86_64_ipi.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "x86_64_ipi.h"
  2. void ipi_send_IPI(uint32_t dest_mode, uint32_t deliver_status, uint32_t level, uint32_t trigger,
  3. uint32_t vector, uint32_t deliver_mode, uint32_t dest_shorthand, bool apic_type, uint32_t destination)
  4. {
  5. struct INT_CMD_REG icr_entry;
  6. icr_entry.dest_mode = dest_mode;
  7. icr_entry.deliver_status = deliver_status;
  8. icr_entry.res_1 = 0;
  9. icr_entry.level = level;
  10. icr_entry.trigger = trigger;
  11. icr_entry.res_2 = 0;
  12. icr_entry.res_3 = 0;
  13. icr_entry.vector = vector;
  14. icr_entry.deliver_mode = deliver_mode;
  15. icr_entry.dest_shorthand = dest_shorthand;
  16. // x2APIC下,ICR寄存器地址为0x830
  17. // xAPIC下则为0xfee00300(31-0) 0xfee00310 (63-32)
  18. if (apic_type) // x2APIC
  19. {
  20. icr_entry.destination.x2apic_destination = destination;
  21. wrmsr(0x830, *(unsigned long *)&icr_entry); // 发送ipi
  22. }
  23. else // xAPIC
  24. {
  25. icr_entry.destination.apic_destination.dest_field = destination & 0xff;
  26. icr_entry.destination.apic_destination.res_4 = 0;
  27. // 先向高32bit写数据,然后再向低32bit写数据,不能调转
  28. *(uint32_t *)(APIC_LOCAL_APIC_VIRT_BASE_ADDR + 0x310) = (uint32_t)(((*(ul *)&icr_entry) >> 32) & 0xffff);
  29. *(uint32_t *)(APIC_LOCAL_APIC_VIRT_BASE_ADDR + 0x300) = (uint32_t)((*(ul *)&icr_entry) & 0xffff);
  30. }
  31. }
  32. int ipi_regiserIPI(uint64_t irq_num, void *arg,
  33. void (*handler)(uint64_t irq_num, uint64_t param, struct pt_regs *regs),
  34. uint64_t param, hardware_intr_controller *controller, char *irq_name)
  35. {
  36. irq_desc_t *p = &SMP_IPI_desc[irq_num-200];
  37. p->controller = NULL; // 由于ipi不涉及到具体的硬件操作,因此不需要controller
  38. p->irq_name = irq_name;
  39. p->parameter = param;
  40. p->flags = 0;
  41. p->handler = handler;
  42. return 0;
  43. }