mpacpi.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* This file is part of the UCB release of Plan 9. It is subject to the license
  2. * terms in the LICENSE file found in the top-level directory of this
  3. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  4. * part of the UCB release of Plan 9, including this file, may be copied,
  5. * modified, propagated, or distributed except according to the terms contained
  6. * in the LICENSE file. */
  7. #include "u.h"
  8. #include "../port/lib.h"
  9. #include "mem.h"
  10. #include "dat.h"
  11. #include "fns.h"
  12. #include "apic.h"
  13. #include "acpi.h"
  14. extern int mpisabusno;
  15. int mpacpi(int ncleft)
  16. {
  17. char *already;
  18. int np, bp;
  19. Apic *apic;
  20. Apicst *st;
  21. Madt *mt;
  22. /* If we don't have an mpisabusno yet, it's because the MP tables failed to
  23. * parse. So we'll just take the last one available. I think we're
  24. * supposed to parse the ACPI shit with the AML to figure out the buses and
  25. * find a clear one, but fuck that. Note this busno is just for our own
  26. * RDT/Rbus bookkeeping. */
  27. if (mpisabusno == -1)
  28. mpisabusno = Nbus - 1;
  29. if (apics == nil)
  30. return ncleft;
  31. mt = apics->tbl;
  32. if (mt == nil)
  33. return ncleft;
  34. print("APIC lapic paddr %#.8llx, flags %#.8x\n",
  35. mt->lapicpa, mt->pcat);
  36. np = 0;
  37. //print("apics->st %p\n", apics->st);
  38. for (int i = 0; i < apics->nchildren; i++) {
  39. st = apics->children[i]->tbl;
  40. already = "";
  41. switch (st->type) {
  42. case ASlapic:
  43. print("ASlapic %d\n", st->lapic.id);
  44. /* this table is supposed to have all of them if it exists */
  45. if (st->lapic.id > Napic)
  46. break;
  47. apic = xlapic + st->lapic.id;
  48. bp = (np++ == 0);
  49. if (apic->useable) {
  50. already = "(mp)";
  51. } else if (ncleft != 0) {
  52. ncleft--;
  53. apicinit(st->lapic.id, mt->lapicpa, bp);
  54. } else
  55. already = "(off)";
  56. print("apic proc %d/%d apicid %d %s\n", np - 1, apic->Lapic.machno,
  57. st->lapic.id, already);
  58. break;
  59. case ASioapic:
  60. print("ASioapic %d\n", st->ioapic.id);
  61. if (st->ioapic.id > Napic){
  62. print("ASioapic: %d is > %d, ignoring\n", st->ioapic.id, Napic);
  63. break;
  64. }
  65. apic = xioapic + st->ioapic.id;
  66. if (apic->useable) {
  67. already = "(mp)";
  68. goto pr1;
  69. }
  70. ioapicinit(st->ioapic.id, st->ioapic.ibase, st->ioapic.addr);
  71. pr1:
  72. apic->Ioapic.gsib = st->ioapic.ibase;
  73. print("ioapic %d ", st->ioapic.id);
  74. print("addr %p ibase %d %s\n", st->ioapic.addr, st->ioapic.ibase,
  75. already);
  76. break;
  77. }
  78. }
  79. return ncleft;
  80. }