changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / sys/src/9/pc/vgaigfx.c

changeset 4350: 1f9d7811d546
parent: e5f67c75b49a
child: 766862263e0f
author: cinap_lenrek@felloff.net
date: Mon, 16 Mar 2015 05:46:08 +0100
permissions: -rw-r--r--
description: kernel: get rid of auxpage() and preserve cache index bits in Page.va in mount cache

the mount cache uses Page.va to store cached range offset and
limit, but mips kernel uses cache index bits from Page.va to
maintain page coloring. Page.va was not initialized by auxpage().

this change removes auxpage() which was primarily used only
by the mount cache and use newpage() with cache file offset
page as va so we will get a page of the right color.

mount cache keeps the index bits intact by only using the top
and buttom PGSHIFT bits of Page.va for the range offset/limit.
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 #include "io.h"
7 #include "../port/error.h"
8 
9 #define Image IMAGE
10 #include <draw.h>
11 #include <memdraw.h>
12 #include <cursor.h>
13 #include "screen.h"
14 
15 #define MB 0x100000
16 
17 static ulong
18 preallocsize(Pcidev *p)
19 {
20  switch(p->did){
21  case 0x0166: /* Ivy Bridge */
22  switch((pcicfgr16(p, 0x50) >> 3) & 0x1f){
23  case 0x01: return 32*MB - 2*MB;
24  case 0x02: return 64*MB - 2*MB;
25  case 0x03: return 96*MB - 2*MB;
26  case 0x04: return 128*MB - 2*MB;
27  case 0x05: return 32*MB - 2*MB;
28  case 0x06: return 48*MB - 2*MB;
29  case 0x07: return 64*MB - 2*MB;
30  case 0x08: return 128*MB - 2*MB;
31  case 0x09: return 256*MB - 2*MB;
32  case 0x0A: return 96*MB - 2*MB;
33  case 0x0B: return 160*MB - 2*MB;
34  case 0x0C: return 224*MB - 2*MB;
35  case 0x0D: return 352*MB - 2*MB;
36  case 0x0E: return 448*MB - 2*MB;
37  case 0x0F: return 480*MB - 2*MB;
38  case 0x10: return 512*MB - 2*MB;
39  }
40  break;
41  case 0x2a42: /* X200 */
42  switch((pcicfgr16(p, 0x52) >> 4) & 7){
43  case 0x01: return 1*MB;
44  case 0x02: return 4*MB;
45  case 0x03: return 8*MB;
46  case 0x04: return 16*MB;
47  case 0x05: return 32*MB;
48  case 0x06: return 48*MB;
49  case 0x07: return 64*MB;
50  }
51  break;
52  }
53  return 0;
54 }
55 
56 static void
57 igfxenable(VGAscr* scr)
58 {
59  Pcidev *p;
60 
61  if(scr->mmio != nil)
62  return;
63  p = scr->pci;
64  if(p == nil)
65  return;
66  scr->mmio = vmap(p->mem[0].bar&~0x0F, p->mem[0].size);
67  if(scr->mmio == nil)
68  return;
69  addvgaseg("igfxmmio", p->mem[0].bar&~0x0F, p->mem[0].size);
70  if(scr->paddr == 0)
71  vgalinearpci(scr);
72  if(scr->apsize){
73  addvgaseg("igfxscreen", scr->paddr, scr->apsize);
74  scr->storage = preallocsize(p);
75  if(scr->storage > scr->apsize)
76  scr->storage = scr->apsize;
77  if(scr->storage != 0)
78  scr->storage -= PGROUND(64*64*4);
79  }
80 }
81 
82 VGAdev vgaigfxdev = {
83  "igfx",
84  igfxenable,
85 };
86 
87 static void
88 igfxcurload(VGAscr* scr, Cursor* curs)
89 {
90  uchar set, clr;
91  u32int *p;
92  int i, j;
93 
94  if(scr->storage == 0)
95  return;
96  p = (u32int*)((uchar*)scr->vaddr + scr->storage);
97  memset(p, 0, 64*64*4);
98  for(i=0;i<32;i++) {
99  set = curs->set[i];
100  clr = curs->clr[i];
101  for(j=0x80; j; j>>=1){
102  if((set|clr)&j)
103  *p++ = (0xFF<<24) | (set&j ? 0x000000 : 0xFFFFFF);
104  else
105  *p++ = 0;
106  }
107  if(i & 1)
108  p += 64-16;
109  }
110  scr->offset = curs->offset;
111 }
112 
113 enum {
114  CURCTL = 0,
115  CURBASE,
116  CURPOS,
117 
118  NPIPE = 3,
119 };
120 
121 static u32int*
122 igfxcurregs(VGAscr* scr, int pipe)
123 {
124  u32int o;
125 
126  if(scr->mmio == nil || scr->storage == 0)
127  return nil;
128  o = pipe*0x1000;
129  /* check PIPExCONF if enabled */
130  if((scr->mmio[(0x70008 | o)/4] & (1<<31)) == 0)
131  return nil;
132  switch(scr->pci->did){
133  case 0x0116: /* Ivy Bridge */
134  if(pipe > 2)
135  return nil;
136  break;
137  case 0x2a42: /* X200 */
138  if(pipe > 1)
139  return nil;
140  o = pipe*0x40;
141  break;
142  default:
143  if(pipe > 0)
144  return nil;
145  }
146  return (u32int*)((uchar*)scr->mmio + (0x70080 + o));
147 }
148 
149 static int
150 igfxcurmove(VGAscr* scr, Point p)
151 {
152  int i, x, y;
153  u32int *r;
154 
155  for(i=0; i<NPIPE; i++){
156  if((r = igfxcurregs(scr, i)) != nil){
157  x = p.x + scr->offset.x;
158  if(x < 0) x = -x | 0x8000;
159  y = p.y + scr->offset.y;
160  if(y < 0) y = -y | 0x8000;
161  r[CURPOS] = (y << 16) | x;
162  }
163  }
164  return 0;
165 }
166 
167 static void
168 igfxcurenable(VGAscr* scr)
169 {
170  u32int *r;
171  int i;
172 
173  igfxenable(scr);
174  igfxcurload(scr, &arrow);
175  igfxcurmove(scr, ZP);
176 
177  for(i=0; i<NPIPE; i++){
178  if((r = igfxcurregs(scr, i)) != nil){
179  r[CURCTL] = (r[CURCTL] & ~(3<<28 | 1<<5)) | (i<<28) | 7;
180  r[CURBASE] = scr->storage;
181  }
182  }
183 }
184 
185 static void
186 igfxcurdisable(VGAscr* scr)
187 {
188  u32int *r;
189  int i;
190 
191  for(i=0; i<NPIPE; i++){
192  if((r = igfxcurregs(scr, i)) != nil){
193  r[CURCTL] &= ~(1<<5 | 7);
194  r[CURBASE] = 0;
195  }
196  }
197 }
198 
199 VGAcur vgaigfxcur = {
200  "igfxhwgc",
201  igfxcurenable,
202  igfxcurdisable,
203  igfxcurload,
204  igfxcurmove,
205 };