vgamach64xx.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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. #define Image IMAGE
  9. #include <draw.h>
  10. #include <memdraw.h>
  11. #include <cursor.h>
  12. #include "screen.h"
  13. char Eunsupportedformat[] = "unsupported video format";
  14. char Enotconfigured[] = "device not configured";
  15. #define SCALE_ZERO_EXTEND 0x0
  16. #define SCALE_DYNAMIC 0x1
  17. #define SCALE_RED_TEMP_6500K 0x0
  18. #define SCALE_RED_TEMP_9800K 0x2
  19. #define SCALE_HORZ_BLEND 0x0
  20. #define SCALE_HORZ_REP 0x4
  21. #define SCALE_VERT_BLEND 0x0
  22. #define SCALE_VERT_REP 0x8
  23. #define SCALE_BANDWIDTH_NORMAL 0x0
  24. #define SCALE_BANDWIDTH_EXCEEDED 0x4000000
  25. #define SCALE_BANDWIDTH_RESET 0x4000000
  26. #define SCALE_CLK_ACTIVITY 0x0
  27. #define SCALE_CLK_CONTINUOUS 0x20000000
  28. #define OVERLAY_DISABLE 0x0
  29. #define OVERLAY_ENABLE 0x40000000
  30. #define SCALE_DISABLE 0x0
  31. #define SCALE_ENABLE 0x80000000
  32. #define SCALER_FRAME_READ_MODE_FULL 0x0
  33. #define SCALER_BUF_MODE_SINGLE 0x0
  34. #define SCALER_BUF_MODE_DOUBLE 0x40000
  35. #define SCALER_BUF_NEXT_0 0x0
  36. #define SCALER_BUF_NEXT_1 0x80000
  37. #define SCALER_BUF_STATUS_0 0x0
  38. #define SCALER_BUF_STATUS_1 0x100000
  39. #define OVERLAY_MIX_G_CMP 0x0
  40. #define OVERLAY_MIX_ALWAYS_G 0x100
  41. #define OVERLAY_MIX_ALWAYS_V 0x200
  42. #define OVERLAY_MIX_NOT_G 0x300
  43. #define OVERLAY_MIX_NOT_V 0x400
  44. #define OVERLAY_MIX_G_XOR_V 0x500
  45. #define OVERLAY_MIX_NOT_G_XOR_V 0x600
  46. #define OVERLAY_MIX_V_CMP 0x700
  47. #define OVERLAY_MIX_NOT_G_OR_NOT_V 0x800
  48. #define OVERLAY_MIX_G_OR_NOT_V 0x900
  49. #define OVERLAY_MIX_NOT_G_OR_V 0xA00
  50. #define OVERLAY_MIX_G_OR_V 0xB00
  51. #define OVERLAY_MIX_G_AND_V 0xC00
  52. #define OVERLAY_MIX_NOT_G_AND_V 0xD00
  53. #define OVERLAY_MIX_G_AND_NOT_V 0xE00
  54. #define OVERLAY_MIX_NOT_G_AND_NOT_V 0xF00
  55. #define OVERLAY_EXCLUSIVE_NORMAL 0x0
  56. #define OVERLAY_EXCLUSIVE_V_ONLY 0x80000000
  57. #define VIDEO_IN_8BPP 0x2
  58. #define VIDEO_IN_16BPP 0x4
  59. #define VIDEO_IN_32BPP 0x6
  60. #define VIDEO_IN_VYUY422 0xB /*16 bpp */
  61. #define VIDEO_IN_YVYU422 0xC /* 16 bpp */
  62. #define SCALE_IN_15BPP 0x30000 /* aRGB 1555 */
  63. #define SCALE_IN_16BPP 0x40000 /* RGB 565 */
  64. #define SCALE_IN_32BPP 0x60000 /* aRGB 8888 */
  65. #define SCALE_IN_YUV9 0x90000 /* planar */
  66. #define SCALE_IN_YUV12 0xA0000 /* planar */
  67. #define SCALE_IN_VYUY422 0xB0000 /* 16 bpp */
  68. #define SCALE_IN_YVYU422 0xC0000 /* 16 bpp */
  69. #define HOST_YUV_APERTURE_UPPER 0x0
  70. #define HOST_YUV_APERTURE_LOWER 0x20000000
  71. #define HOST_MEM_MODE_Y 0x40000000
  72. #define HOST_MEM_MODE_U 0x80000000
  73. #define HOST_MEM_MODE_V 0xC0000000
  74. #define HOST_MEM_MODE_NORMAL HOST_YUV_APERTURE_UPPER
  75. static Chan *ovl_chan; /* Channel of controlling process */
  76. static int ovl_width; /* Width of input overlay buffer */
  77. static int ovl_height; /* Height of input overlay buffer */
  78. static int ovl_format; /* Overlay format */
  79. static ulong ovl_fib; /* Frame in bytes */
  80. enum {
  81. VTGTB1S1 = 0x01, // Asic description for VTB1S1 and GTB1S1.
  82. VT4GTIIC = 0x3A, // asic descr for VT4 and RAGE IIC
  83. GTB1U1 = 0x19, // Asic description for GTB1U1.
  84. GTB1S2 = 0x41, // Asic description for GTB1S2.
  85. GTB2U1 = 0x1A,
  86. GTB2U2 = 0x5A,
  87. GTB2U3 = 0x9A,
  88. GTIIIC1U1 = 0x1B, // 3D RAGE PRO asic descrp.
  89. GTIIIC1U2 = 0x5B, // 3D RAGE PRO asic descrp.
  90. GTIIIC2U1 = 0x1C, // 3D RAGE PRO asic descrp.
  91. GTIIIC2U2 = 0x5C, // 3D RAGE PRO asic descrp.
  92. GTIIIC2U3 = 0x7C, // 3D RAGE PRO asic descrp.
  93. GTBC = 0x3A, // 3D RAGE IIC asic descrp.
  94. LTPRO = 0x9C, // 3D RAGE LT PRO
  95. };
  96. /*
  97. * ATI Mach64(CT|ET|G*|V*|L*).
  98. */
  99. typedef struct {
  100. ushort m64_id; /* Chip ID */
  101. int m64_vtgt; /* Is this a VT or GT chipset? */
  102. ulong m64_ovlclock; /* Max. overlay clock frequency */
  103. int m64_pro; /* Is this a PRO? */
  104. } mach64types;
  105. static ulong mach64refclock;
  106. static mach64types *mach64type;
  107. static int mach64revb; /* Revision B or greater? */
  108. static ulong mach64overlay; /* Overlay buffer */
  109. static mach64types mach64s[] = {
  110. ('C'<<8)|'T', 0, 1350000, /*?*/ 0, /* 4354: CT */
  111. ('E'<<8)|'T', 0, 1350000, /*?*/ 0, /* 4554: ET */
  112. ('G'<<8)|'B', 1, 1250000, 1, /* 4742: 264GT PRO */
  113. ('G'<<8)|'D', 1, 1250000, 1, /* 4744: 264GT PRO */
  114. ('G'<<8)|'I', 1, 1250000, 1, /* 4749: 264GT PRO */
  115. ('G'<<8)|'M', 0, 1350000, 0, /* 474D: Rage XL */
  116. ('G'<<8)|'P', 1, 1250000, 1, /* 4750: 264GT PRO */
  117. ('G'<<8)|'Q', 1, 1250000, 1, /* 4751: 264GT PRO */
  118. ('G'<<8)|'R', 1, 1250000, 1, /* 4752: */
  119. ('G'<<8)|'T', 1, 800000, 0, /* 4754: 264GT[B] */
  120. ('G'<<8)|'U', 1, 1000000, 0, /* 4755: 264GT DVD */
  121. ('G'<<8)|'V', 1, 1000000, 0, /* 4756: Rage2C */
  122. ('G'<<8)|'Z', 1, 1000000, 0, /* 475A: Rage2C */
  123. ('V'<<8)|'T', 1, 800000, 0, /* 5654: 264VT/GT/VTB */
  124. ('V'<<8)|'U', 1, 800000, 0, /* 5655: 264VT3 */
  125. ('V'<<8)|'V', 1, 1000000, 0, /* 5656: 264VT4 */
  126. ('L'<<8)|'B', 0, 1350000, 1, /* 4C42: Rage LTPro AGP */
  127. ('L'<<8)|'I', 0, 1350000, 0, /* 4C49: Rage LTPro AGP */
  128. ('L'<<8)|'M', 0, 1350000, 0, /* 4C4D: Rage Mobility */
  129. ('L'<<8)|'P', 0, 1350000, 1, /* 4C50: 264LT PRO */
  130. };
  131. static int hwfill(VGAscr*, Rectangle, ulong);
  132. static int hwscroll(VGAscr*, Rectangle, Rectangle);
  133. static void initengine(VGAscr*);
  134. static Pcidev*
  135. mach64xxpci(void)
  136. {
  137. Pcidev *p;
  138. int i;
  139. if((p = pcimatch(nil, 0x1002, 0)) == nil)
  140. return nil;
  141. for (i = 0; i != nelem(mach64s); i++)
  142. if (mach64s[i].m64_id == p->did) {
  143. mach64type = &mach64s[i];
  144. return p;
  145. }
  146. return nil;
  147. }
  148. static void
  149. mach64xxenable(VGAscr* scr)
  150. {
  151. Pcidev *p;
  152. /*
  153. * Only once, can't be disabled for now.
  154. */
  155. if(scr->io)
  156. return;
  157. if(p = mach64xxpci()){
  158. scr->id = p->did;
  159. /*
  160. * The CT doesn't always have the I/O base address
  161. * in the PCI base registers. There is a way to find
  162. * it via the vendor-specific PCI config space but
  163. * this will do for now.
  164. */
  165. scr->io = p->mem[1].bar & ~0x03;
  166. if(scr->io == 0)
  167. scr->io = 0x2EC;
  168. }
  169. }
  170. static ulong
  171. mach64xxlinear(VGAscr* scr, int* size, int* align)
  172. {
  173. ulong aperture, osize, oaperture;
  174. int i, oapsize, wasupamem;
  175. Pcidev *p;
  176. osize = *size;
  177. oaperture = scr->aperture;
  178. oapsize = scr->apsize;
  179. wasupamem = scr->isupamem;
  180. if(p = mach64xxpci()){
  181. for(i=0; i<nelem(p->mem); i++){
  182. if(p->mem[i].size >= *size
  183. && ((p->mem[i].bar & ~0x0F) & (*align-1)) == 0)
  184. break;
  185. }
  186. if(i >= nelem(p->mem)){
  187. print("vgamach64xx: aperture not found\n");
  188. return 0;
  189. }
  190. aperture = p->mem[i].bar & ~0x0F;
  191. *size = p->mem[i].size;
  192. }
  193. else
  194. aperture = 0;
  195. if(wasupamem)
  196. upafree(oaperture, oapsize);
  197. scr->isupamem = 0;
  198. aperture = upamalloc(aperture, *size, *align);
  199. if(aperture == 0){
  200. if(wasupamem && upamalloc(oaperture, oapsize, 0))
  201. scr->isupamem = 1;
  202. }
  203. else
  204. scr->isupamem = 1;
  205. scr->mmio = KADDR(aperture+osize-0x400);
  206. if(oaperture && oaperture != aperture)
  207. print("warning (BUG): redefinition of aperture does not change mach64mmio segment\n");
  208. addvgaseg("mach64mmio", aperture+osize-BY2PG, BY2PG);
  209. addvgaseg("mach64screen", aperture, osize);
  210. return aperture;
  211. }
  212. enum {
  213. CrtcOffPitch = 0x05,
  214. CrtcGenCtl = 0x07,
  215. CurClr0 = 0x0B, /* I/O Select */
  216. CurClr1 = 0x0C,
  217. CurOffset = 0x0D,
  218. CurHVposn = 0x0E,
  219. CurHVoff = 0x0F,
  220. BusCntl = 0x13,
  221. GenTestCntl = 0x19,
  222. CrtcHsyncDis = 0x04,
  223. CrtcVsyncDis = 0x08,
  224. ContextMask = 0x100, /* not accessible via I/O */
  225. FifoStat,
  226. GuiStat,
  227. DpFrgdClr,
  228. DpBkgdClr,
  229. DpWriteMask,
  230. DpMix,
  231. DpPixWidth,
  232. DpSrc,
  233. ClrCmpCntl,
  234. GuiTrajCntl,
  235. ScLeftRight,
  236. ScTopBottom,
  237. DstOffPitch,
  238. DstYX,
  239. DstHeightWidth,
  240. DstCntl,
  241. DstHeight,
  242. DstBresErr,
  243. DstBresInc,
  244. DstBresDec,
  245. SrcCntl,
  246. SrcHeight1Width1,
  247. SrcHeight2Width2,
  248. SrcYX,
  249. SrcWidth1,
  250. SrcYXstart,
  251. HostCntl,
  252. PatReg0,
  253. PatReg1,
  254. PatCntl,
  255. ScBottom,
  256. ScLeft,
  257. ScRight,
  258. ScTop,
  259. ClrCmpClr,
  260. ClrCmpMask,
  261. DpChainMask,
  262. SrcOffPitch,
  263. LcdIndex,
  264. LcdData,
  265. ClockCntl,
  266. OverlayScaleCntl,
  267. ConfigChipId,
  268. Buf0Pitch,
  269. ScalerBuf0Pitch,
  270. CaptureConfig,
  271. OverlayKeyCntl,
  272. ScalerColourCntl,
  273. ScalerHCoef0,
  274. ScalerHCoef1,
  275. ScalerHCoef2,
  276. ScalerHCoef3,
  277. ScalerHCoef4,
  278. VideoFormat,
  279. Buf0Offset,
  280. ScalerBuf0Offset,
  281. CrtcGenCntl,
  282. OverlayScaleInc,
  283. OverlayYX,
  284. OverlayYXEnd,
  285. ScalerHeightWidth,
  286. HTotalDisp,
  287. VTotalDisp,
  288. };
  289. enum {
  290. LCD_ConfigPanel = 0,
  291. LCD_GenCtrl,
  292. LCD_DstnCntl,
  293. LCD_HfbPitchAddr,
  294. LCD_HorzStretch,
  295. LCD_VertStretch,
  296. LCD_ExtVertStretch,
  297. LCD_LtGio,
  298. LCD_PowerMngmnt,
  299. LCD_ZvgPio,
  300. Nlcd,
  301. };
  302. #define Bank1 (-0x100) /* 1KB */
  303. static int mmoffset[] = {
  304. [HTotalDisp] 0x00,
  305. [VTotalDisp] 0x02,
  306. [CrtcOffPitch] 0x05,
  307. [CrtcGenCntl] 0x07,
  308. [CurClr0] 0x18,
  309. [CurClr1] 0x19,
  310. [CurOffset] 0x1A,
  311. [CurHVposn] 0x1B,
  312. [CurHVoff] 0x1C,
  313. [ClockCntl] 0x24,
  314. [BusCntl] 0x28,
  315. [LcdIndex] 0x29,
  316. [LcdData] 0x2A,
  317. [GenTestCntl] 0x34,
  318. [ConfigChipId] 0x38,
  319. [DstOffPitch] 0x40,
  320. [DstYX] 0x43,
  321. [DstHeight] 0x45,
  322. [DstHeightWidth] 0x46,
  323. [DstBresErr] 0x49,
  324. [DstBresInc] 0x4A,
  325. [DstBresDec] 0x4B,
  326. [DstCntl] 0x4C,
  327. [SrcOffPitch] 0x60,
  328. [SrcYX] 0x63,
  329. [SrcWidth1] 0x64,
  330. [SrcYXstart] 0x69,
  331. [SrcHeight1Width1] 0x66,
  332. [SrcHeight2Width2] 0x6C,
  333. [SrcCntl] 0x6D,
  334. [HostCntl] 0x90,
  335. [PatReg0] 0xA0,
  336. [PatReg1] 0xA1,
  337. [PatCntl] 0xA2,
  338. [ScLeft] 0xA8,
  339. [ScRight] 0xA9,
  340. [ScLeftRight] 0xAA,
  341. [ScTop] 0xAB,
  342. [ScBottom] 0xAC,
  343. [ScTopBottom] 0xAD,
  344. [DpBkgdClr] 0xB0,
  345. [DpFrgdClr] 0xB1,
  346. [DpWriteMask] 0xB2,
  347. [DpChainMask] 0xB3,
  348. [DpPixWidth] 0xB4,
  349. [DpMix] 0xB5,
  350. [DpSrc] 0xB6,
  351. [ClrCmpClr] 0xC0,
  352. [ClrCmpMask] 0xC1,
  353. [ClrCmpCntl] 0xC2,
  354. [FifoStat] 0xC4,
  355. [ContextMask] 0xC8,
  356. [GuiTrajCntl] 0xCC,
  357. [GuiStat] 0xCE,
  358. /* Bank1 */
  359. [OverlayYX] Bank1 + 0x00,
  360. [OverlayYXEnd] Bank1 + 0x01,
  361. [OverlayKeyCntl] Bank1 + 0x06,
  362. [OverlayScaleInc] Bank1 + 0x08,
  363. [OverlayScaleCntl] Bank1 + 0x09,
  364. [ScalerHeightWidth] Bank1 + 0x0A,
  365. [ScalerBuf0Offset] Bank1 + 0x0D,
  366. [ScalerBuf0Pitch] Bank1 + 0x0F,
  367. [VideoFormat] Bank1 + 0x12,
  368. [CaptureConfig] Bank1 + 0x14,
  369. [Buf0Offset] Bank1 + 0x20,
  370. [Buf0Pitch] Bank1 + 0x23,
  371. [ScalerColourCntl] Bank1 + 0x54,
  372. [ScalerHCoef0] Bank1 + 0x55,
  373. [ScalerHCoef1] Bank1 + 0x56,
  374. [ScalerHCoef2] Bank1 + 0x57,
  375. [ScalerHCoef3] Bank1 + 0x58,
  376. [ScalerHCoef4] Bank1 + 0x59,
  377. };
  378. static ulong
  379. ior32(VGAscr* scr, int r)
  380. {
  381. if(scr->io == 0x2EC || scr->io == 0x1C8)
  382. return inl((r<<10)+scr->io);
  383. if(r >= 0x100 && scr->mmio != nil)
  384. return scr->mmio[mmoffset[r]];
  385. return inl((mmoffset[r]<<2)+scr->io);
  386. }
  387. static void
  388. iow32(VGAscr* scr, int r, ulong l)
  389. {
  390. if(scr->io == 0x2EC || scr->io == 0x1C8)
  391. outl(((r)<<10)+scr->io, l);
  392. else if(r >= 0x100 && scr->mmio != nil)
  393. scr->mmio[mmoffset[r]] = l;
  394. else
  395. outl((mmoffset[r]<<2)+scr->io, l);
  396. }
  397. static ulong
  398. lcdr32(VGAscr *scr, ulong r)
  399. {
  400. ulong or;
  401. or = ior32(scr, LcdIndex);
  402. iow32(scr, LcdIndex, (or&~0x0F) | (r&0x0F));
  403. return ior32(scr, LcdData);
  404. }
  405. static void
  406. lcdw32(VGAscr *scr, ulong r, ulong v)
  407. {
  408. ulong or;
  409. or = ior32(scr, LcdIndex);
  410. iow32(scr, LcdIndex, (or&~0x0F) | (r&0x0F));
  411. iow32(scr, LcdData, v);
  412. }
  413. static void
  414. mach64xxcurdisable(VGAscr* scr)
  415. {
  416. ulong r;
  417. r = ior32(scr, GenTestCntl);
  418. iow32(scr, GenTestCntl, r & ~0x80);
  419. }
  420. static void
  421. mach64xxcurload(VGAscr* scr, Cursor* curs)
  422. {
  423. uchar *p;
  424. int i, y;
  425. ulong c, s, m, r;
  426. /*
  427. * Disable the cursor.
  428. */
  429. r = ior32(scr, GenTestCntl);
  430. iow32(scr, GenTestCntl, r & ~0x80);
  431. p = KADDR(scr->aperture);
  432. p += scr->storage;
  433. /*
  434. * Initialise the 64x64 cursor RAM array.
  435. * The cursor mode gives the following truth table:
  436. * p1 p0 colour
  437. * 0 0 Cursor Colour 0
  438. * 0 1 Cursor Colour 1
  439. * 1 0 Transparent
  440. * 1 1 Complement
  441. * Put the cursor into the top-right of the 64x64 array.
  442. */
  443. for(y = 0; y < 16; y++){
  444. for(i = 0; i < (64-16)/8; i++){
  445. *p++ = 0xAA;
  446. *p++ = 0xAA;
  447. }
  448. c = (curs->clr[2*y]<<8)|curs->clr[y*2 + 1];
  449. s = (curs->set[2*y]<<8)|curs->set[y*2 + 1];
  450. m = 0x00000000;
  451. for(i = 0; i < 16; i++){
  452. if(s & (1<<(15-i)))
  453. m |= 0x01<<(2*i);
  454. else if(c & (1<<(15-i))){
  455. /* nothing to do */
  456. }
  457. else
  458. m |= 0x02<<(2*i);
  459. }
  460. *p++ = m;
  461. *p++ = m>>8;
  462. *p++ = m>>16;
  463. *p++ = m>>24;
  464. }
  465. memset(p, 0xAA, (64-16)*16);
  466. /*
  467. * Set the cursor hotpoint and enable the cursor.
  468. */
  469. scr->offset = curs->offset;
  470. iow32(scr, GenTestCntl, 0x80|r);
  471. }
  472. static int
  473. ptalmostinrect(Point p, Rectangle r)
  474. {
  475. return p.x>=r.min.x && p.x<=r.max.x &&
  476. p.y>=r.min.y && p.y<=r.max.y;
  477. }
  478. /*
  479. * If necessary, translate the rectangle physr
  480. * some multiple of [dx dy] so that it includes p.
  481. * Return 1 if the rectangle changed.
  482. */
  483. static int
  484. screenpan(Point p, Rectangle *physr, int dx, int dy)
  485. {
  486. int d;
  487. if(ptalmostinrect(p, *physr))
  488. return 0;
  489. if(p.y < physr->min.y){
  490. d = physr->min.y - (p.y&~(dy-1));
  491. physr->min.y -= d;
  492. physr->max.y -= d;
  493. }
  494. if(p.y > physr->max.y){
  495. d = ((p.y+dy-1)&~(dy-1)) - physr->max.y;
  496. physr->min.y += d;
  497. physr->max.y += d;
  498. }
  499. if(p.x < physr->min.x){
  500. d = physr->min.x - (p.x&~(dx-1));
  501. physr->min.x -= d;
  502. physr->max.x -= d;
  503. }
  504. if(p.x > physr->max.x){
  505. d = ((p.x+dx-1)&~(dx-1)) - physr->max.x;
  506. physr->min.x += d;
  507. physr->max.x += d;
  508. }
  509. return 1;
  510. }
  511. static int
  512. mach64xxcurmove(VGAscr* scr, Point p)
  513. {
  514. int x, xo, y, yo;
  515. int dx;
  516. ulong off, pitch;
  517. /*
  518. * If the point we want to display is outside the current
  519. * screen rectangle, pan the screen to display it.
  520. *
  521. * We have to move in 64-bit chunks.
  522. */
  523. if(scr->gscreen->depth == 24)
  524. dx = (64*3)/24;
  525. else
  526. dx = 64 / scr->gscreen->depth;
  527. if(panning && screenpan(p, &physgscreenr, dx, 1)){
  528. off = (physgscreenr.min.y*Dx(scr->gscreen->r)+physgscreenr.min.x)/dx;
  529. pitch = Dx(scr->gscreen->r)/8;
  530. iow32(scr, CrtcOffPitch, (pitch<<22)|off);
  531. }
  532. p.x -= physgscreenr.min.x;
  533. p.y -= physgscreenr.min.y;
  534. /*
  535. * Mustn't position the cursor offscreen even partially,
  536. * or it disappears. Therefore, if x or y is -ve, adjust the
  537. * cursor presets instead. If y is negative also have to
  538. * adjust the starting offset.
  539. */
  540. if((x = p.x+scr->offset.x) < 0){
  541. xo = x;
  542. x = 0;
  543. }
  544. else
  545. xo = 0;
  546. if((y = p.y+scr->offset.y) < 0){
  547. yo = y;
  548. y = 0;
  549. }
  550. else
  551. yo = 0;
  552. iow32(scr, CurHVoff, ((64-16-yo)<<16)|(64-16-xo));
  553. iow32(scr, CurOffset, scr->storage/8 + (-yo*2));
  554. iow32(scr, CurHVposn, (y<<16)|x);
  555. return 0;
  556. }
  557. static void
  558. mach64xxcurenable(VGAscr* scr)
  559. {
  560. ulong r, storage;
  561. mach64xxenable(scr);
  562. if(scr->io == 0)
  563. return;
  564. r = ior32(scr, GenTestCntl);
  565. iow32(scr, GenTestCntl, r & ~0x80);
  566. iow32(scr, CurClr0, (Pwhite<<24)|(Pwhite<<16)|(Pwhite<<8)|Pwhite);
  567. iow32(scr, CurClr1, (Pblack<<24)|(Pblack<<16)|(Pblack<<8)|Pblack);
  568. /*
  569. * Find a place for the cursor data in display memory.
  570. * Must be 64-bit aligned.
  571. */
  572. storage = (scr->gscreen->width*BY2WD*scr->gscreen->r.max.y+7)/8;
  573. iow32(scr, CurOffset, storage);
  574. scr->storage = storage*8;
  575. /*
  576. * Cursor goes in the top right corner of the 64x64 array
  577. * so the horizontal and vertical presets are 64-16.
  578. */
  579. iow32(scr, CurHVposn, (0<<16)|0);
  580. iow32(scr, CurHVoff, ((64-16)<<16)|(64-16));
  581. /*
  582. * Load, locate and enable the 64x64 cursor.
  583. */
  584. mach64xxcurload(scr, &arrow);
  585. mach64xxcurmove(scr, ZP);
  586. iow32(scr, GenTestCntl, 0x80|r);
  587. }
  588. static void
  589. waitforfifo(VGAscr *scr, int entries)
  590. {
  591. int x;
  592. x = 0;
  593. while((ior32(scr, FifoStat)&0xFF) > (0x8000>>entries) && x++ < 1000000)
  594. ;
  595. if(x >= 1000000)
  596. iprint("fifo %d stat %.8lux %.8lux scrio %.8lux mmio %p scr %p pc %luX\n", entries, ior32(scr, FifoStat), scr->mmio[mmoffset[FifoStat]], scr->io, scr->mmio, scr, getcallerpc(&scr));
  597. }
  598. static void
  599. waitforidle(VGAscr *scr)
  600. {
  601. int x;
  602. waitforfifo(scr, 16);
  603. x = 0;
  604. while((ior32(scr, GuiStat)&1) && x++ < 1000000)
  605. ;
  606. if(x >= 1000000)
  607. iprint("idle stat %.8lux %.8lux scrio %.8lux mmio %p scr %p pc %luX\n", ior32(scr, GuiStat), scr->mmio[mmoffset[GuiStat]], scr->io, scr->mmio, scr, getcallerpc(&scr));
  608. }
  609. static void
  610. resetengine(VGAscr *scr)
  611. {
  612. ulong x;
  613. x = ior32(scr, GenTestCntl);
  614. iow32(scr, GenTestCntl, x&~0x100);
  615. iow32(scr, GenTestCntl, x|0x100);
  616. iow32(scr, BusCntl, ior32(scr, BusCntl)|0x00A00000);
  617. }
  618. static void
  619. init_overlayclock(VGAscr *scr)
  620. {
  621. uchar *cc, save, pll_ref_div, pll_vclk_cntl, vclk_post_div,
  622. vclk_fb_div, ecp_div;
  623. int i;
  624. ulong dotclock;
  625. /* Taken from GLX */
  626. /* Get monitor dotclock, check for Overlay Scaler clock limit */
  627. cc = (uchar *)&scr->mmio[mmoffset[ClockCntl]];
  628. save = cc[1]; i = cc[0] & 3;
  629. cc[1] = 2<<2; pll_ref_div = cc[2];
  630. cc[1] = 5<<2; pll_vclk_cntl = cc[2];
  631. cc[1] = 6<<2; vclk_post_div = (cc[2]>>(i+i)) & 3;
  632. cc[1] = (7+i)<<2; vclk_fb_div = cc[2];
  633. dotclock = 2 * mach64refclock * vclk_fb_div /
  634. (pll_ref_div * (1 << vclk_post_div));
  635. /* ecp_div: 0=dotclock, 1=dotclock/2, 2=dotclock/4 */
  636. ecp_div = dotclock / mach64type->m64_ovlclock;
  637. if (ecp_div>2) ecp_div = 2;
  638. /* Force a scaler clock factor of 1 if refclock *
  639. * is unknown (VCLK_SRC not PLLVCLK) */
  640. if ((pll_vclk_cntl & 0x03) != 0x03)
  641. ecp_div = 0;
  642. if ((pll_vclk_cntl & 0x30) != ecp_div<<4) {
  643. cc[1] = (5<<2)|2;
  644. cc[2] = (pll_vclk_cntl&0xCF) | (ecp_div<<4);
  645. }
  646. /* Restore PLL Register Index */
  647. cc[1] = save;
  648. }
  649. static void
  650. initengine(VGAscr *scr)
  651. {
  652. ulong pitch;
  653. uchar *bios;
  654. ushort table;
  655. pitch = Dx(scr->gscreen->r)/8;
  656. if(scr->gscreen->depth == 24)
  657. pitch *= 3;
  658. resetengine(scr);
  659. waitforfifo(scr, 14);
  660. iow32(scr, ContextMask, ~0);
  661. iow32(scr, DstOffPitch, pitch<<22);
  662. iow32(scr, DstYX, 0);
  663. iow32(scr, DstHeight, 0);
  664. iow32(scr, DstBresErr, 0);
  665. iow32(scr, DstBresInc, 0);
  666. iow32(scr, DstBresDec, 0);
  667. iow32(scr, DstCntl, 0x23);
  668. iow32(scr, SrcOffPitch, pitch<<22);
  669. iow32(scr, SrcYX, 0);
  670. iow32(scr, SrcHeight1Width1, 1);
  671. iow32(scr, SrcYXstart, 0);
  672. iow32(scr, SrcHeight2Width2, 1);
  673. iow32(scr, SrcCntl, 0x01);
  674. waitforfifo(scr, 13);
  675. iow32(scr, HostCntl, 0);
  676. iow32(scr, PatReg0, 0);
  677. iow32(scr, PatReg1, 0);
  678. iow32(scr, PatCntl, 0);
  679. iow32(scr, ScLeft, 0);
  680. iow32(scr, ScTop, 0);
  681. iow32(scr, ScBottom, 0xFFFF);
  682. iow32(scr, ScRight, 0xFFFF);
  683. iow32(scr, DpBkgdClr, 0);
  684. iow32(scr, DpFrgdClr, ~0);
  685. iow32(scr, DpWriteMask, ~0);
  686. iow32(scr, DpMix, 0x70003);
  687. iow32(scr, DpSrc, 0x00010100);
  688. waitforfifo(scr, 3);
  689. iow32(scr, ClrCmpClr, 0);
  690. iow32(scr, ClrCmpMask, ~0);
  691. iow32(scr, ClrCmpCntl, 0);
  692. waitforfifo(scr, 2);
  693. switch(scr->gscreen->depth){
  694. case 8:
  695. case 24: /* [sic] */
  696. iow32(scr, DpPixWidth, 0x00020202);
  697. iow32(scr, DpChainMask, 0x8080);
  698. break;
  699. case 16:
  700. iow32(scr, DpPixWidth, 0x00040404);
  701. iow32(scr, DpChainMask, 0x8410);
  702. break;
  703. case 32:
  704. iow32(scr, DpPixWidth, 0x00060606);
  705. iow32(scr, DpChainMask, 0x8080);
  706. break;
  707. }
  708. /* Get the base freq from the BIOS */
  709. bios = KADDR(0xC000);
  710. table = *(ushort *)(bios + 0x48);
  711. table = *(ushort *)(bios + table + 0x10);
  712. switch (*(ushort *)(bios + table + 0x08)) {
  713. case 2700:
  714. mach64refclock = 270000;
  715. break;
  716. case 2863:
  717. case 2864:
  718. mach64refclock = 286363;
  719. break;
  720. case 2950:
  721. mach64refclock = 294989;
  722. break;
  723. case 1432:
  724. default:
  725. mach64refclock = 143181;
  726. break ;
  727. }
  728. /* Figure out which revision this chip is */
  729. switch ((scr->mmio[mmoffset[ConfigChipId]] >> 24) & 0xFF) {
  730. case VTGTB1S1:
  731. case GTB1U1:
  732. case GTB1S2:
  733. case GTB2U1:
  734. case GTB2U2:
  735. case GTB2U3:
  736. case GTBC:
  737. case GTIIIC1U1:
  738. case GTIIIC1U2:
  739. case GTIIIC2U1:
  740. case GTIIIC2U2:
  741. case GTIIIC2U3:
  742. case LTPRO:
  743. mach64revb = 1;
  744. break;
  745. default:
  746. mach64revb = 0;
  747. break;
  748. }
  749. init_overlayclock(scr);
  750. waitforidle(scr);
  751. }
  752. static int
  753. mach64hwfill(VGAscr *scr, Rectangle r, ulong sval)
  754. {
  755. ulong pitch;
  756. ulong ctl;
  757. if(drawdebug)
  758. iprint("hwfill %R val %lux...\n", r, sval);
  759. /* shouldn't happen */
  760. if(scr->io == 0x2EC || scr->io == 0x1C8 || scr->io == 0)
  761. return 0;
  762. pitch = Dx(scr->gscreen->r)/8;
  763. ctl = 1|2; /* left-to-right, top-to-bottom */
  764. if(scr->gscreen->depth == 24){
  765. r.min.x *= 3;
  766. r.max.x *= 3;
  767. pitch *= 3;
  768. ctl |= (1<<7)|(((r.min.x/4)%6)<<8);
  769. }
  770. waitforfifo(scr, 11);
  771. iow32(scr, DpFrgdClr, sval);
  772. iow32(scr, DpWriteMask, 0xFFFFFFFF);
  773. iow32(scr, DpMix, 0x00070003);
  774. iow32(scr, DpSrc, 0x00000111);
  775. iow32(scr, ClrCmpCntl, 0x00000000);
  776. iow32(scr, ScLeftRight, 0x1FFF0000);
  777. iow32(scr, ScTopBottom, 0x1FFF0000);
  778. iow32(scr, DstOffPitch, pitch<<22);
  779. iow32(scr, DstCntl, ctl);
  780. iow32(scr, DstYX, (r.min.x<<16)|r.min.y);
  781. iow32(scr, DstHeightWidth, (Dx(r)<<16)|Dy(r));
  782. waitforidle(scr);
  783. return 1;
  784. }
  785. static int
  786. mach64hwscroll(VGAscr *scr, Rectangle r, Rectangle sr)
  787. {
  788. ulong pitch;
  789. Point dp, sp;
  790. ulong ctl;
  791. int dx, dy;
  792. dx = Dx(r);
  793. dy = Dy(r);
  794. pitch = Dx(scr->gscreen->r)/8;
  795. if(scr->gscreen->depth == 24){
  796. dx *= 3;
  797. pitch *= 3;
  798. r.min.x *= 3;
  799. sr.min.x *= 3;
  800. }
  801. ctl = 0;
  802. if(r.min.x <= sr.min.x){
  803. ctl |= 1;
  804. dp.x = r.min.x;
  805. sp.x = sr.min.x;
  806. }else{
  807. dp.x = r.min.x+dx-1;
  808. sp.x = sr.min.x+dx-1;
  809. }
  810. if(r.min.y <= sr.min.y){
  811. ctl |= 2;
  812. dp.y = r.min.y;
  813. sp.y = sr.min.y;
  814. }else{
  815. dp.y = r.min.y+dy-1;
  816. sp.y = sr.min.y+dy-1;
  817. }
  818. if(scr->gscreen->depth == 24)
  819. ctl |= (1<<7)|(((dp.x/4)%6)<<8);
  820. waitforfifo(scr, 6);
  821. iow32(scr, ScLeftRight, 0x1FFF0000);
  822. iow32(scr, ScTopBottom, 0x1FFF0000);
  823. iow32(scr, DpWriteMask, 0xFFFFFFFF);
  824. iow32(scr, DpMix, 0x00070003);
  825. iow32(scr, DpSrc, 0x00000300);
  826. iow32(scr, ClrCmpCntl, 0x00000000);
  827. waitforfifo(scr, 8);
  828. iow32(scr, SrcOffPitch, pitch<<22);
  829. iow32(scr, SrcCntl, 0x00000000);
  830. iow32(scr, SrcYX, (sp.x<<16)|sp.y);
  831. iow32(scr, SrcWidth1, dx);
  832. iow32(scr, DstOffPitch, pitch<<22);
  833. iow32(scr, DstCntl, ctl);
  834. iow32(scr, DstYX, (dp.x<<16)|dp.y);
  835. iow32(scr, DstHeightWidth, (dx<<16)|dy);
  836. waitforidle(scr);
  837. return 1;
  838. }
  839. /*
  840. * This should work, but doesn't.
  841. * It messes up the screen timings for some reason.
  842. */
  843. static void
  844. mach64blank(VGAscr *scr, int blank)
  845. {
  846. ulong ctl;
  847. ctl = ior32(scr, CrtcGenCtl) & ~(CrtcHsyncDis|CrtcVsyncDis);
  848. if(blank)
  849. ctl |= CrtcHsyncDis|CrtcVsyncDis;
  850. iow32(scr, CrtcGenCtl, ctl);
  851. }
  852. /*
  853. * We squirrel away whether the LCD and/or CRT were
  854. * on when we were called to blank the screen, and
  855. * restore the old state. If we are called to blank the
  856. * screen when it is already blank, we don't update the state.
  857. * Such a call sequence should not happen, though.
  858. *
  859. * We could try forcing the chip into power management
  860. * mode instead, but I'm not sure how that would interact
  861. * with screen updates going on while the screen is blanked.
  862. */
  863. static void
  864. mach64lcdblank(VGAscr *scr, int blank)
  865. {
  866. static int crtlcd;
  867. ulong x;
  868. if(blank) {
  869. x = lcdr32(scr, LCD_GenCtrl);
  870. if(x & 3) {
  871. crtlcd = x & 3;
  872. lcdw32(scr, LCD_GenCtrl, x&~3);
  873. }
  874. } else {
  875. if(crtlcd == 0)
  876. crtlcd = 2; /* lcd only */
  877. x = lcdr32(scr, LCD_GenCtrl);
  878. lcdw32(scr, LCD_GenCtrl, x | crtlcd);
  879. }
  880. }
  881. static void
  882. mach64xxdrawinit(VGAscr *scr)
  883. {
  884. if(scr->io > 0x2FF){
  885. initengine(scr);
  886. scr->fill = mach64hwfill;
  887. scr->scroll = mach64hwscroll;
  888. }
  889. /* scr->blank = mach64blank; */
  890. switch(scr->id){
  891. default:
  892. break;
  893. case ('L'<<8)|'B': /* 4C42: Rage 3D LTPro */
  894. case ('L'<<8)|'I': /* 4C49: Rage 3D LTPro */
  895. case ('L'<<8)|'M': /* 4C4D: Rage Mobility */
  896. case ('L'<<8)|'P': /* 4C50: Rage 3D LTPro */
  897. scr->blank = mach64lcdblank;
  898. hwblank = 1;
  899. break;
  900. }
  901. }
  902. static void
  903. ovl_configure(VGAscr *scr, Chan *c, char **field)
  904. {
  905. int w, h;
  906. char *format;
  907. w = (int)strtol(field[1], nil, 0);
  908. h = (int)strtol(field[2], nil, 0);
  909. format = field[3];
  910. if (c != ovl_chan)
  911. error(Einuse);
  912. if (strcmp(format, "YUYV"))
  913. error(Eunsupportedformat);
  914. ovl_width = w;
  915. ovl_height = h;
  916. ovl_fib = w * h * sizeof(ushort);
  917. waitforidle(scr);
  918. scr->mmio[mmoffset[BusCntl]] |= 0x08000000; /* Enable regblock 1 */
  919. scr->mmio[mmoffset[OverlayScaleCntl]] =
  920. SCALE_ZERO_EXTEND|SCALE_RED_TEMP_6500K|
  921. SCALE_HORZ_BLEND|SCALE_VERT_BLEND;
  922. scr->mmio[mmoffset[!mach64revb? Buf0Pitch: ScalerBuf0Pitch]] = w;
  923. scr->mmio[mmoffset[CaptureConfig]] =
  924. SCALER_FRAME_READ_MODE_FULL|
  925. SCALER_BUF_MODE_SINGLE|
  926. SCALER_BUF_NEXT_0;
  927. scr->mmio[mmoffset[OverlayKeyCntl]] = !mach64revb?
  928. OVERLAY_MIX_ALWAYS_V|(OVERLAY_EXCLUSIVE_NORMAL << 28):
  929. 0x011;
  930. if (mach64type->m64_pro) {
  931. waitforfifo(scr, 6);
  932. /* set the scaler co-efficient registers */
  933. scr->mmio[mmoffset[ScalerColourCntl]] =
  934. (0x00) | (0x10 << 8) | (0x10 << 16);
  935. scr->mmio[mmoffset[ScalerHCoef0]] =
  936. (0x00) | (0x20 << 8);
  937. scr->mmio[mmoffset[ScalerHCoef1]] =
  938. (0x0D) | (0x20 << 8) | (0x06 << 16) | (0x0D << 24);
  939. scr->mmio[mmoffset[ScalerHCoef2]] =
  940. (0x0D) | (0x1C << 8) | (0x0A << 16) | (0x0D << 24);
  941. scr->mmio[mmoffset[ScalerHCoef3]] =
  942. (0x0C) | (0x1A << 8) | (0x0E << 16) | (0x0C << 24);
  943. scr->mmio[mmoffset[ScalerHCoef4]] =
  944. (0x0C) | (0x14 << 8) | (0x14 << 16) | (0x0C << 24);
  945. }
  946. waitforfifo(scr, 3);
  947. scr->mmio[mmoffset[VideoFormat]] = SCALE_IN_YVYU422 |
  948. (!mach64revb? 0xC: 0);
  949. if (mach64overlay == 0)
  950. mach64overlay = scr->storage + 64 * 64 * sizeof(uchar);
  951. scr->mmio[mmoffset[!mach64revb? Buf0Offset: ScalerBuf0Offset]] =
  952. mach64overlay;
  953. }
  954. static void
  955. ovl_enable(VGAscr *scr, Chan *c, char **field)
  956. {
  957. int x, y, w, h;
  958. long h_inc, v_inc;
  959. x = (int)strtol(field[1], nil, 0);
  960. y = (int)strtol(field[2], nil, 0);
  961. w = (int)strtol(field[3], nil, 0);
  962. h = (int)strtol(field[4], nil, 0);
  963. if (x < 0 || x + w > physgscreenr.max.x ||
  964. y < 0 || y + h > physgscreenr.max.y)
  965. error(Ebadarg);
  966. if (c != ovl_chan)
  967. error(Einuse);
  968. if (scr->mmio[mmoffset[CrtcGenCntl]] & 1) { /* double scan enable */
  969. y *= 2;
  970. h *= 2;
  971. }
  972. waitforfifo(scr, 2);
  973. scr->mmio[mmoffset[OverlayYX]] =
  974. ((x & 0xFFFF) << 16) | (y & 0xFFFF);
  975. scr->mmio[mmoffset[OverlayYXEnd]] =
  976. (((x + w) & 0xFFFF) << 16) | ((y + h) & 0xFFFF);
  977. h_inc = (ovl_width << 12) / (w >> 1); /* ??? */
  978. v_inc = (ovl_height << 12) / h;
  979. waitforfifo(scr, 2);
  980. scr->mmio[mmoffset[OverlayScaleInc]] =
  981. ((h_inc & 0xFFFF) << 16) | (v_inc & 0xFFFF);
  982. scr->mmio[mmoffset[ScalerHeightWidth]] =
  983. ((ovl_width & 0xFFFF) << 16) | (ovl_height & 0xFFFF);
  984. waitforidle(scr);
  985. scr->mmio[mmoffset[OverlayScaleCntl]] |=
  986. (SCALE_ENABLE|OVERLAY_ENABLE);
  987. }
  988. static void
  989. ovl_status(VGAscr *scr, Chan *, char **field)
  990. {
  991. pprint("%s: %s %.4uX, VT/GT %s, PRO %s, ovlclock %d, rev B %s, refclock %ld\n",
  992. scr->dev->name, field[0], mach64type->m64_id,
  993. mach64type->m64_vtgt? "yes": "no",
  994. mach64type->m64_pro? "yes": "no",
  995. mach64type->m64_ovlclock,
  996. mach64revb? "yes": "no",
  997. mach64refclock);
  998. pprint("%s: storage @%.8luX, aperture @%8.ulX, ovl buf @%.8ulX\n",
  999. scr->dev->name, scr->storage, scr->aperture,
  1000. mach64overlay);
  1001. }
  1002. static void
  1003. ovl_openctl(VGAscr *, Chan *c, char **)
  1004. {
  1005. if (ovl_chan)
  1006. error(Einuse);
  1007. ovl_chan = c;
  1008. }
  1009. static void
  1010. ovl_closectl(VGAscr *scr, Chan *c, char **)
  1011. {
  1012. if (c != ovl_chan) return;
  1013. waitforidle(scr);
  1014. scr->mmio[mmoffset[OverlayScaleCntl]] &=
  1015. ~(SCALE_ENABLE|OVERLAY_ENABLE);
  1016. ovl_chan = nil;
  1017. ovl_width = ovl_height = ovl_fib = 0;
  1018. }
  1019. enum
  1020. {
  1021. CMclosectl,
  1022. CMconfigure,
  1023. CMenable,
  1024. CMopenctl,
  1025. CMstatus,
  1026. };
  1027. static void (*ovl_cmds[])(VGAscr *, Chan *, char **) =
  1028. {
  1029. [CMclosectl] ovl_closectl,
  1030. [CMconfigure] ovl_configure,
  1031. [CMenable] ovl_enable,
  1032. [CMopenctl] ovl_openctl,
  1033. [CMstatus] ovl_status,
  1034. };
  1035. static Cmdtab mach64xxcmd[] =
  1036. {
  1037. CMclosectl, "closectl", 1,
  1038. CMconfigure, "configure", 4,
  1039. CMenable, "enable", 5,
  1040. CMopenctl, "openctl", 1,
  1041. CMstatus, "status", 1,
  1042. };
  1043. static void
  1044. mach64xxovlctl(VGAscr *scr, Chan *c, void *a, int n)
  1045. {
  1046. Cmdbuf *cb;
  1047. Cmdtab *ct;
  1048. if (!mach64type->m64_vtgt)
  1049. error(Enodev);
  1050. cb = parsecmd(a, n);
  1051. if(waserror()){
  1052. free(cb);
  1053. nexterror();
  1054. }
  1055. ct = lookupcmd(cb, mach64xxcmd, nelem(mach64xxcmd));
  1056. ovl_cmds[ct->index](scr, c, cb->f);
  1057. poperror();
  1058. free(cb);
  1059. }
  1060. static int
  1061. mach64xxovlwrite(VGAscr *scr, void *a, int len, vlong offs)
  1062. {
  1063. uchar *src;
  1064. int _len;
  1065. if (ovl_chan == nil) return len; /* Acts as a /dev/null */
  1066. /* Calculate the destination address */
  1067. _len = len;
  1068. src = (uchar *)a;
  1069. while (len > 0) {
  1070. ulong _offs;
  1071. int nb;
  1072. _offs = (ulong)(offs % ovl_fib);
  1073. nb = (_offs + len > ovl_fib)? ovl_fib - _offs: len;
  1074. memmove((uchar *)KADDR(scr->aperture + mach64overlay + _offs),
  1075. src, nb);
  1076. offs += nb;
  1077. src += nb;
  1078. len -= nb;
  1079. }
  1080. return _len;
  1081. }
  1082. VGAdev vgamach64xxdev = {
  1083. "mach64xx",
  1084. mach64xxenable, /* enable */
  1085. 0, /* disable */
  1086. 0, /* page */
  1087. mach64xxlinear, /* linear */
  1088. mach64xxdrawinit, /* drawinit */
  1089. 0,
  1090. mach64xxovlctl, /* overlay control */
  1091. mach64xxovlwrite, /* write the overlay */
  1092. };
  1093. VGAcur vgamach64xxcur = {
  1094. "mach64xxhwgc",
  1095. mach64xxcurenable, /* enable */
  1096. mach64xxcurdisable, /* disable */
  1097. mach64xxcurload, /* load */
  1098. mach64xxcurmove, /* move */
  1099. 1 /* doespanning */
  1100. };