deviig.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * VGA controller
  11. */
  12. #include "u.h"
  13. #include "../port/lib.h"
  14. #include "mem.h"
  15. #include "dat.h"
  16. #include "fns.h"
  17. #include "io.h"
  18. #include "../port/error.h"
  19. #define Image IMAGE
  20. #include <draw.h>
  21. #include <memdraw.h>
  22. #include <cursor.h>
  23. #include "screen.h"
  24. enum {
  25. Qdir,
  26. Qiigctl,
  27. };
  28. static Dirtab iigdir[] = {
  29. {".", { Qdir, 0, QTDIR }, 0, 0550},
  30. {"iigctl", { Qiigctl, 0 }, 0, 0660},
  31. };
  32. enum {
  33. CMsize,
  34. CMblank,
  35. CMunblank,
  36. };
  37. static Cmdtab iigctlmsg[] = {
  38. {CMsize, "size", 1},
  39. {CMblank, "blank", 1},
  40. {CMunblank, "unblank", 1},
  41. };
  42. typedef struct Iig Iig;
  43. struct Iig {
  44. struct VGAscr scr;
  45. };
  46. static Iig iig;
  47. static void
  48. iigreset(void)
  49. {
  50. iig.scr.pci = pcimatch(nil, 0x8086, 0x0116);
  51. if (iig.scr.pci)
  52. print("Found sandybridge at 0x%x\n", iig.scr.pci->tbdf);
  53. else {
  54. print("NO sandybridge found\n");
  55. return;
  56. }
  57. /* on coreboot systems, which is what this is mainly for, the graphics memory is allocated and
  58. * reserved. This little hack won't be permanent but we might as well see if we can get to that
  59. * memory.
  60. */
  61. void *x = vmap(iig.scr.pci->mem[1].bar, iig.scr.pci->mem[1].size);
  62. print("x is THIS! %p\n", x);
  63. if (x) {
  64. iig.scr.vaddr = x;
  65. iig.scr.paddr = iig.scr.pci->mem[1].bar;
  66. iig.scr.apsize = iig.scr.pci->mem[1].size;
  67. }
  68. }
  69. static Chan*
  70. iigattach(char* spec)
  71. {
  72. if(*spec && strcmp(spec, "0"))
  73. error(Eio);
  74. return devattach('G', spec);
  75. }
  76. Walkqid*
  77. iigwalk(Chan* c, Chan *nc, char** name, int nname)
  78. {
  79. return devwalk(c, nc, name, nname, iigdir, nelem(iigdir), devgen);
  80. }
  81. static int
  82. iigstat(Chan* c, unsigned char* dp, int n)
  83. {
  84. return devstat(c, dp, n, iigdir, nelem(iigdir), devgen);
  85. }
  86. static Chan*
  87. iigopen(Chan* c, int omode)
  88. {
  89. return devopen(c, omode, iigdir, nelem(iigdir), devgen);
  90. }
  91. static void
  92. iigclose(Chan* c)
  93. {
  94. }
  95. static int32_t
  96. iigread(Chan* c, void* a, int32_t n, int64_t off)
  97. {
  98. switch((uint32_t)c->qid.path){
  99. case Qdir:
  100. return devdirread(c, a, n, iigdir, nelem(iigdir), devgen);
  101. default:
  102. error(Egreg);
  103. break;
  104. }
  105. return 0;
  106. }
  107. static void
  108. iigctl(Cmdbuf *cb)
  109. {
  110. Cmdtab *ct;
  111. ct = lookupcmd(cb, iigctlmsg, nelem(iigctlmsg));
  112. switch(ct->index){
  113. case CMsize:
  114. error("nope");
  115. return;
  116. case CMblank:
  117. drawblankscreen(1);
  118. return;
  119. case CMunblank:
  120. drawblankscreen(0);
  121. return;
  122. }
  123. cmderror(cb, "bad IIG control message");
  124. }
  125. static int32_t
  126. iigwrite(Chan* c, void* a, int32_t n, int64_t off)
  127. {
  128. Proc *up = externup();
  129. Cmdbuf *cb;
  130. switch((uint32_t)c->qid.path){
  131. case Qdir:
  132. error(Eperm);
  133. case Qiigctl:
  134. if(off || n >= READSTR)
  135. error(Ebadarg);
  136. cb = parsecmd(a, n);
  137. if(waserror()){
  138. free(cb);
  139. nexterror();
  140. }
  141. iigctl(cb);
  142. poperror();
  143. free(cb);
  144. return n;
  145. default:
  146. error(Egreg);
  147. break;
  148. }
  149. return 0;
  150. }
  151. Dev iigdevtab = {
  152. .dc = 'G',
  153. .name = "iig",
  154. .reset = iigreset,
  155. .init = devinit,
  156. .shutdown = devshutdown,
  157. .attach = iigattach,
  158. .walk = iigwalk,
  159. .stat = iigstat,
  160. .open = iigopen,
  161. .create = devcreate,
  162. .close = iigclose,
  163. .read = iigread,
  164. .bread = devbread,
  165. .write = iigwrite,
  166. .bwrite = devbwrite,
  167. .remove = devremove,
  168. .wstat = devwstat,
  169. };