mpacpi.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // Initialise all local and IO APICs
  16. int mpacpi(int ncleft)
  17. {
  18. char *already;
  19. int np, bp;
  20. Apic *apic;
  21. Apicst *st;
  22. Madt *mt;
  23. /* If we don't have an mpisabusno yet, it's because the MP tables failed to
  24. * parse. So we'll just take the last one available. I think we're
  25. * supposed to parse the ACPI shit with the AML to figure out the buses and
  26. * find a clear one, but fuck that. Note this busno is just for our own
  27. * RDT/Rbus bookkeeping. */
  28. if (mpisabusno == -1)
  29. mpisabusno = Nbus - 1;
  30. if (apics == nil)
  31. return ncleft;
  32. mt = apics->tbl;
  33. if (mt == nil)
  34. return ncleft;
  35. print("APIC lapic paddr %#.8llx, flags %#.8x\n",
  36. mt->lapicpa, mt->pcat);
  37. np = 0;
  38. //print("apics->st %p\n", apics->st);
  39. for (int i = 0; i < apics->nchildren; i++) {
  40. st = apics->children[i]->tbl;
  41. already = "";
  42. switch (st->type) {
  43. case ASlapic:
  44. print("ASlapic %d\n", st->lapic.id);
  45. /* this table is supposed to have all of them if it exists */
  46. if (st->lapic.id > Napic)
  47. break;
  48. apic = xlapic + st->lapic.id;
  49. bp = (np++ == 0);
  50. if (apic->useable) {
  51. already = "(mp)";
  52. } else if (ncleft != 0) {
  53. ncleft--;
  54. apicinit(st->lapic.id, mt->lapicpa, bp);
  55. } else {
  56. already = "(off)";
  57. }
  58. print("apic proc %d/%d apicid %d %s\n", np - 1, apic->Lapic.machno,
  59. st->lapic.id, already);
  60. break;
  61. case ASioapic:
  62. print("ASioapic %d\n", st->ioapic.id);
  63. if (st->ioapic.id > Napic){
  64. print("ASioapic: %d is > %d, ignoring\n", st->ioapic.id, Napic);
  65. break;
  66. }
  67. apic = xioapic + st->ioapic.id;
  68. if (apic->useable) {
  69. already = "(mp)";
  70. } else {
  71. ioapicinit(st->ioapic.id, st->ioapic.ibase, st->ioapic.addr);
  72. }
  73. apic->Ioapic.gsib = st->ioapic.ibase;
  74. print("ioapic %d ", st->ioapic.id);
  75. print("addr %p ibase %d %s\n", st->ioapic.addr, st->ioapic.ibase, already);
  76. break;
  77. }
  78. }
  79. return ncleft;
  80. }