12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697 |
- /*
- Copyright (c) 2000 by Juliusz Chroboczek
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- */
- #ifdef HAVE_CONFIG_H
- #include <kdrive-config.h>
- #endif
- #include "vesa.h"
- #include "vga.h"
- #include "vbe.h"
- #include <randrstr.h>
- static int vesa_video_mode = 0;
- static Bool vesa_force_mode = FALSE;
- static Bool vesa_swap_rgb = FALSE;
- static Bool vesa_shadow = TRUE;
- static Bool vesa_linear_fb = TRUE;
- static Bool vesa_verbose = FALSE;
- static Bool vesa_force_text = FALSE;
- static Bool vesa_restore_font = TRUE;
- static Bool vesa_map_holes = TRUE;
- static Bool vesa_boot = FALSE;
- #define VesaPriv(scr) ((VesaScreenPrivPtr) (scr)->driver)
- #define vesaWidth(scr,vmib) ((vmib)->XResolution)
- #define vesaHeight(scr,vmib) ((vmib)->YResolution)
- static Bool vesaComputeFramebufferMapping(KdScreenInfo * screen);
- static Bool vesaMapFramebuffer(KdScreenInfo * screen);
- static Bool vesaModeSupportable(VesaModePtr mode, Bool complain)
- {
- if ((mode->ModeAttributes & 0x10) == 0) {
- if (complain)
- ErrorF("Text mode specified.\n");
- return FALSE;
- }
- if (mode->MemoryModel != 0x06 && mode->MemoryModel != 0x04
- && mode->MemoryModel != 0x03) {
- if (complain)
- ErrorF("Unsupported memory model 0x%X\n",
- mode->MemoryModel);
- return FALSE;
- }
- if ((mode->ModeAttributes & 0x80) == 0) {
- if ((mode->ModeAttributes & 0x40) != 0) {
- if (complain)
- ErrorF
- ("Neither linear nor windowed framebuffer available in this mode\n");
- return FALSE;
- }
- }
- if (!(mode->ModeAttributes & 1)) {
- if (complain)
- ErrorF("Mode not supported on this hardware\n");
- return FALSE;
- }
- if (mode->BitsPerPixel < 5) {
- if (complain)
- ErrorF("Skipping low color mode\n");
- return FALSE;
- }
- return TRUE;
- }
- static Bool
- vesaModeSupported(VesaCardPrivPtr priv, VesaModePtr mode, Bool complain)
- {
- if (!priv->vbeInfo && mode->vbe) {
- if (complain)
- ErrorF("VBE bios mode not usable.\n");
- return FALSE;
- }
- return vesaModeSupportable(mode, complain);
- }
- static int vesaDepth(VesaModePtr mode)
- {
- if (mode->MemoryModel == MEMORY_DIRECT)
- return (mode->RedMaskSize +
- mode->GreenMaskSize + mode->BlueMaskSize);
- else
- return mode->BitsPerPixel;
- }
- static void vesaReportMode(VesaModePtr mode)
- {
- int supported = (mode->ModeAttributes & MODE_SUPPORTED) ? 1 : 0;
- int colour = (mode->ModeAttributes & MODE_COLOUR) ? 1 : 0;
- int graphics = (mode->ModeAttributes & MODE_GRAPHICS) ? 1 : 0;
- int vga_compatible = !((mode->ModeAttributes & MODE_VGA) ? 1 : 0);
- int linear_fb = (mode->ModeAttributes & MODE_LINEAR) ? 1 : 0;
- ErrorF("0x%04X: %dx%dx%d%s%s%s%s",
- (unsigned)mode->mode,
- (int)mode->XResolution, (int)mode->YResolution,
- vesaDepth(mode),
- colour ? "" : " (monochrome)",
- graphics ? "" : " (graphics)",
- vga_compatible ? "" : " (vga compatible)",
- linear_fb ? "" : " (linear frame buffer)");
- switch (mode->MemoryModel) {
- case MEMORY_TEXT:
- ErrorF(" text mode");
- break;
- case MEMORY_CGA:
- ErrorF(" CGA graphics");
- break;
- case MEMORY_HERCULES:
- ErrorF(" Hercules graphics");
- break;
- case MEMORY_PLANAR:
- ErrorF(" Planar (%d planes)", mode->NumberOfPlanes);
- break;
- case MEMORY_PSEUDO:
- ErrorF(" PseudoColor");
- break;
- case MEMORY_NONCHAIN:
- ErrorF(" Non-chain 4, 256 colour");
- break;
- case MEMORY_DIRECT:
- if (mode->DirectColorModeInfo & MODE_DIRECT)
- ErrorF(" DirectColor");
- else
- ErrorF(" TrueColor");
- ErrorF(" [%d:%d:%d:%d]",
- mode->RedMaskSize, mode->GreenMaskSize,
- mode->BlueMaskSize, mode->RsvdMaskSize);
- if (mode->DirectColorModeInfo & 2)
- ErrorF(" (reserved bits are reserved)");
- break;
- case MEMORY_YUV:
- ErrorF("YUV");
- break;
- default:
- ErrorF("unknown MemoryModel 0x%X ", mode->MemoryModel);
- }
- if (!supported)
- ErrorF(" (unsupported)");
- else if (!linear_fb)
- ErrorF(" (no linear framebuffer)");
- ErrorF("\n");
- }
- static VesaModePtr vesaGetModes(Vm86InfoPtr vi, int *ret_nmode)
- {
- VesaModePtr modes;
- int nmode, nmodeVbe, nmodeVga;
- int code;
- code = VgaGetNmode(vi);
- if (code <= 0)
- nmodeVga = 0;
- else
- nmodeVga = code;
- code = VbeGetNmode(vi);
- if (code <= 0)
- nmodeVbe = 0;
- else
- nmodeVbe = code;
- nmode = nmodeVga + nmodeVbe;
- if (nmode <= 0)
- return 0;
- modes = malloc(nmode * sizeof(VesaModeRec));
- memset(modes, '\0', nmode * sizeof(VesaModeRec));
- if (nmodeVga) {
- code = VgaGetModes(vi, modes, nmodeVga);
- if (code <= 0)
- nmodeVga = 0;
- else
- nmodeVga = code;
- }
- if (nmodeVbe) {
- code = VbeGetModes(vi, modes + nmodeVga, nmodeVbe);
- if (code <= 0)
- nmodeVbe = 0;
- else
- nmodeVbe = code;
- }
- nmode = nmodeVga + nmodeVbe;
- if (nmode == 0) {
- free(modes);
- modes = 0;
- return 0;
- }
- *ret_nmode = nmode;
- return modes;
- }
- static Bool vesaInitialize(KdCardInfo * card, VesaCardPrivPtr priv)
- {
- priv->vi = Vm86Setup(vesa_map_holes);
- if (!priv->vi)
- goto fail;
- if (vesa_boot)
- VbeBoot(priv->vi);
- priv->modes = vesaGetModes(priv->vi, &priv->nmode);
- if (!priv->modes)
- goto fail;
- priv->vbeInfo = VbeInit(priv->vi);
- card->driver = priv;
- return TRUE;
- fail:
- if (priv->vi)
- Vm86Cleanup(priv->vi);
- return FALSE;
- }
- static void vesaListModes(void)
- {
- Vm86InfoPtr vi;
- VesaModePtr modes;
- int nmode;
- int n;
- vi = Vm86Setup(vesa_map_holes);
- if (!vi) {
- ErrorF("Can't setup vm86\n");
- } else {
- modes = vesaGetModes(vi, &nmode);
- if (!modes) {
- ErrorF("No modes available\n");
- } else {
- VbeReportInfo(vi);
- for (n = 0; n < nmode; n++) {
- if (vesa_force_mode
- || vesaModeSupportable(modes + n, 0))
- vesaReportMode(modes + n);
- }
- free(modes);
- }
- Vm86Cleanup(vi);
- }
- }
- static void vesaTestMode(void)
- {
- Vm86InfoPtr vi;
- VesaModePtr modes;
- VesaModePtr mode;
- VbeInfoPtr vbeInfo;
- int nmode;
- int n;
- vi = Vm86Setup(vesa_map_holes);
- if (!vi) {
- ErrorF("Can't setup vm86\n");
- return;
- }
- modes = vesaGetModes(vi, &nmode);
- if (!modes) {
- ErrorF("No modes available\n");
- return;
- }
- VbeReportInfo(vi);
- vbeInfo = VbeInit(vi);
- for (n = 0; n < nmode; n++) {
- if (modes[n].mode == vesa_video_mode)
- break;
- }
- if (n == nmode) {
- ErrorF("no mode specified\n");
- return;
- }
- mode = &modes[n];
- if (mode->vbe) {
- ErrorF("Enable VBE mode 0x%x\n", mode->mode);
- VbeSetMode(vi, vbeInfo, mode->mode, FALSE, FALSE);
- } else {
- ErrorF("Enable BIOS mode 0x%x\n", mode->mode);
- VgaSetMode(vi, mode->mode);
- }
- sleep(2);
- ErrorF("Restore BIOS mode 0x%x\n", 3);
- VgaSetMode(vi, 3);
- free(modes);
- Vm86Cleanup(vi);
- }
- Bool vesaCardInit(KdCardInfo * card)
- {
- VesaCardPrivPtr priv;
- priv = malloc(sizeof(VesaCardPrivRec));
- if (!priv)
- return FALSE;
- if (!vesaInitialize(card, priv)) {
- free(priv);
- return FALSE;
- }
- return TRUE;
- }
- static Bool vesaModeGood(KdScreenInfo * screen, VesaModePtr a)
- {
- if (vesaWidth(screen, a) <= screen->width &&
- vesaHeight(screen, a) <= screen->height &&
- vesaDepth(a) >= screen->fb.depth) {
- return TRUE;
- }
- return FALSE;
- }
- #define vabs(a) ((a) >= 0 ? (a) : -(a))
- static int vesaSizeError(KdScreenInfo * screen, VesaModePtr a)
- {
- int xdist, ydist;
- xdist = vabs(screen->width - vesaWidth(screen, a));
- ydist = vabs(screen->height - vesaHeight(screen, a));
- return xdist * xdist + ydist * ydist;
- }
- static Bool vesaModeBetter(KdScreenInfo * screen, VesaModePtr a, VesaModePtr b)
- {
- int aerr, berr;
- if (vesaModeGood(screen, a)) {
- if (!vesaModeGood(screen, b))
- return TRUE;
- } else {
- if (vesaModeGood(screen, b))
- return FALSE;
- }
- aerr = vesaSizeError(screen, a);
- berr = vesaSizeError(screen, b);
- if (aerr < berr)
- return TRUE;
- if (berr < aerr)
- return FALSE;
- if (vabs(screen->fb.depth - vesaDepth(a)) <
- vabs(screen->fb.depth - vesaDepth(b)))
- return TRUE;
- if (a->BitsPerPixel == 32 && b->BitsPerPixel == 24)
- return TRUE;
- return FALSE;
- }
- static VesaModePtr vesaSelectMode(KdScreenInfo * screen)
- {
- VesaCardPrivPtr priv = screen->card->driver;
- int i, best;
- if (vesa_video_mode) {
- for (best = 0; best < priv->nmode; best++)
- if (priv->modes[best].mode == vesa_video_mode &&
- (vesaModeSupported(priv, &priv->modes[best], FALSE)
- || vesa_force_mode))
- return &priv->modes[best];
- }
- for (best = 0; best < priv->nmode; best++) {
- if (vesaModeSupported(priv, &priv->modes[best], FALSE))
- break;
- }
- if (best == priv->nmode)
- return 0;
- for (i = best + 1; i < priv->nmode; i++)
- if (vesaModeSupported(priv, &priv->modes[i], FALSE) &&
- vesaModeBetter(screen, &priv->modes[i], &priv->modes[best]))
- best = i;
- return &priv->modes[best];
- }
- static Bool vesaScreenInitialize(KdScreenInfo * screen, VesaScreenPrivPtr pscr)
- {
- VesaModePtr mode;
- screen->driver = pscr;
- if (!screen->width || !screen->height) {
- screen->width = 800;
- screen->height = 600;
- }
- if (!screen->fb.depth)
- screen->fb.depth = 16;
- if (vesa_verbose)
- ErrorF("Mode requested %dx%dx%d\n",
- screen->width, screen->height, screen->fb.depth);
- mode = vesaSelectMode(screen);
- if (!mode) {
- if (vesa_verbose)
- ErrorF("No selectable mode\n");
- return FALSE;
- }
- pscr->mode = *mode;
- if (vesa_verbose) {
- ErrorF("\t");
- vesaReportMode(&pscr->mode);
- }
- pscr->randr = screen->randr;
- pscr->shadow = vesa_shadow;
- pscr->origDepth = screen->fb.depth;
- /*
- * Compute visual support for the selected depth
- */
- switch (pscr->mode.MemoryModel) {
- case MEMORY_DIRECT:
- /* TrueColor or DirectColor */
- screen->fb.visuals = (1 << TrueColor);
- screen->fb.redMask =
- FbStipMask(pscr->mode.RedFieldPosition,
- pscr->mode.RedMaskSize);
- screen->fb.greenMask =
- FbStipMask(pscr->mode.GreenFieldPosition,
- pscr->mode.GreenMaskSize);
- screen->fb.blueMask =
- FbStipMask(pscr->mode.BlueFieldPosition,
- pscr->mode.BlueMaskSize);
- break;
- case MEMORY_PSEUDO:
- /* PseudoColor */
- screen->fb.visuals = ((1 << StaticGray) |
- (1 << GrayScale) |
- (1 << StaticColor) |
- (1 << PseudoColor) |
- (1 << TrueColor) | (1 << DirectColor));
- screen->fb.blueMask = 0x00;
- screen->fb.greenMask = 0x00;
- screen->fb.redMask = 0x00;
- break;
- case MEMORY_PLANAR:
- /* 4 plane planar */
- if (pscr->mode.ModeAttributes & MODE_COLOUR)
- screen->fb.visuals = (1 << StaticColor);
- else
- screen->fb.visuals = (1 << StaticGray);
- screen->fb.blueMask = 0x00;
- screen->fb.greenMask = 0x00;
- screen->fb.redMask = 0x00;
- break;
- default:
- ErrorF("Unsupported VESA MemoryModel 0x%02X\n",
- pscr->mode.MemoryModel);
- return FALSE;
- }
- screen->rate = 72;
- if (!vesaComputeFramebufferMapping(screen))
- return FALSE;
- if (!vesaMapFramebuffer(screen))
- return FALSE;
- return TRUE;
- }
- Bool vesaScreenInit(KdScreenInfo * screen)
- {
- VesaScreenPrivPtr pscr;
- pscr = calloc(1, sizeof(VesaScreenPrivRec));
- if (!pscr)
- return FALSE;
- if (!vesaScreenInitialize(screen, pscr))
- return FALSE;
- return TRUE;
- }
- static void *vesaSetWindowPlanar(ScreenPtr pScreen,
- CARD32 row, CARD32 offset, int mode, CARD32 * size)
- {
- KdScreenPriv(pScreen);
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- static int plane;
- int winSize;
- void *base;
- plane = offset & 3;
- VgaSetWritePlaneMask(priv->vi, (1 << plane));
- offset = offset >> 2;
- if (pscr->mode.vbe) {
- base = VbeSetWindow(priv->vi,
- priv->vbeInfo,
- pscr->mode.BytesPerScanLine * row + offset,
- mode, &winSize);
- } else {
- base = VgaSetWindow(priv->vi,
- pscr->mode.mode,
- pscr->mode.BytesPerScanLine * row + offset,
- mode, &winSize);
- }
- *size = (CARD32) winSize;
- return base;
- }
- static void *vesaSetWindowLinear(ScreenPtr pScreen,
- CARD32 row, CARD32 offset, int mode, CARD32 * size)
- {
- KdScreenPriv(pScreen);
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- *size = pscr->mode.BytesPerScanLine;
- return (CARD8 *) pscr->fb + row * pscr->mode.BytesPerScanLine + offset;
- }
- static void *vesaSetWindowWindowed(ScreenPtr pScreen,
- CARD32 row, CARD32 offset, int mode, CARD32 * size)
- {
- KdScreenPriv(pScreen);
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- int winSize;
- void *base;
- if (pscr->mode.vbe) {
- base = VbeSetWindow(priv->vi,
- priv->vbeInfo,
- pscr->mode.BytesPerScanLine * row + offset,
- mode, &winSize);
- } else {
- base = VgaSetWindow(priv->vi,
- pscr->mode.mode,
- pscr->mode.BytesPerScanLine * row + offset,
- mode, &winSize);
- }
- *size = (CARD32) winSize;
- return base;
- }
- static void *vesaWindowPlanar(ScreenPtr pScreen,
- CARD32 row,
- CARD32 offset, int mode, CARD32 * size, void *closure)
- {
- KdScreenPriv(pScreen);
- if (!pScreenPriv->enabled)
- return 0;
- return vesaSetWindowPlanar(pScreen, row, offset, mode, size);
- }
- static void *vesaWindowLinear(ScreenPtr pScreen,
- CARD32 row,
- CARD32 offset, int mode, CARD32 * size, void *closure)
- {
- KdScreenPriv(pScreen);
- if (!pScreenPriv->enabled)
- return 0;
- return vesaSetWindowLinear(pScreen, row, offset, mode, size);
- }
- static void *vesaWindowWindowed(ScreenPtr pScreen,
- CARD32 row,
- CARD32 offset, int mode, CARD32 * size, void *closure)
- {
- KdScreenPriv(pScreen);
- if (!pScreenPriv->enabled)
- return 0;
- return vesaSetWindowWindowed(pScreen, row, offset, mode, size);
- }
- #define vesaInvertBits32(v) { \
- v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555); \
- v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333); \
- v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f); \
- }
- static void *vesaWindowCga(ScreenPtr pScreen,
- CARD32 row,
- CARD32 offset, int mode, CARD32 * size, void *closure)
- {
- KdScreenPriv(pScreen);
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- int line;
- if (!pScreenPriv->enabled)
- return 0;
- *size = pscr->mode.BytesPerScanLine;
- line = ((row & 1) << 13) + (row >> 1) * pscr->mode.BytesPerScanLine;
- return (CARD8 *) pscr->fb + line + offset;
- }
- static void vesaUpdateMono(ScreenPtr pScreen, shadowBufPtr pBuf)
- {
- RegionPtr damage = shadowDamage(pBuf);
- PixmapPtr pShadow = pBuf->pPixmap;
- int nbox = REGION_NUM_RECTS(damage);
- BoxPtr pbox = REGION_RECTS(damage);
- FbBits *shaBase, *shaLine, *sha;
- FbStride shaStride;
- int scrBase, scrLine, scr;
- int shaBpp;
- int shaXoff _X_UNUSED, shaYoff _X_UNUSED; /* XXX assumed to be zero */
- int x, y, w, h, width;
- int i;
- FbBits *winBase = 0, *win;
- CARD32 winSize;
- FbBits bits;
- fbGetDrawable(&pShadow->drawable, shaBase, shaStride, shaBpp, shaXoff,
- shaYoff);
- while (nbox--) {
- x = pbox->x1 * shaBpp;
- y = pbox->y1;
- w = (pbox->x2 - pbox->x1) * shaBpp;
- h = pbox->y2 - pbox->y1;
- scrLine = (x >> FB_SHIFT);
- shaLine = shaBase + y * shaStride + (x >> FB_SHIFT);
- x &= FB_MASK;
- w = (w + x + FB_MASK) >> FB_SHIFT;
- while (h--) {
- winSize = 0;
- scrBase = 0;
- width = w;
- scr = scrLine;
- sha = shaLine;
- while (width) {
- /* how much remains in this window */
- i = scrBase + winSize - scr;
- if (i <= 0 || scr < scrBase) {
- winBase =
- (FbBits *) (*pBuf->window) (pScreen,
- y,
- scr *
- sizeof
- (FbBits),
- SHADOW_WINDOW_WRITE,
- &winSize,
- pBuf->closure);
- if (!winBase)
- return;
- scrBase = scr;
- winSize /= sizeof(FbBits);
- i = winSize;
- }
- win = winBase + (scr - scrBase);
- if (i > width)
- i = width;
- width -= i;
- scr += i;
- while (i--) {
- bits = *sha++;
- vesaInvertBits32(bits);
- *win++ = bits;
- }
- }
- shaLine += shaStride;
- y++;
- }
- pbox++;
- }
- }
- static const CARD16 vga16Colors[16][3] = {
- {0, 0, 0,}, /* 0 */
- {0, 0, 0xAA,}, /* 1 */
- {0, 0xAA, 0,}, /* 2 */
- {0, 0xAA, 0xAA,}, /* 3 */
- {0xAA, 0, 0,}, /* 4 */
- {0xAA, 0, 0xAA,}, /* 5 */
- {0xAA, 0x55, 0,}, /* 6 */
- {0xAA, 0xAA, 0xAA,}, /* 7 */
- {0x55, 0x55, 0x55,}, /* 8 */
- {0x55, 0x55, 0xFF,}, /* 9 */
- {0x55, 0xFF, 0x55,}, /* 10 */
- {0x55, 0xFF, 0xFF,}, /* 11 */
- {0xFF, 0x55, 0x55,}, /* 12 */
- {0xFF, 0x55, 0xFF,}, /* 13 */
- {0xFF, 0xFF, 0x55,}, /* 14 */
- {0xFF, 0xFF, 0xFF,}, /* 15 */
- };
- static Bool vesaCreateColormap16(ColormapPtr pmap)
- {
- int i, j;
- if (pmap->pVisual->ColormapEntries == 16)
- for (i = 0; i < pmap->pVisual->ColormapEntries; i++) {
- j = i & 0xf;
- pmap->red[i].co.local.red =
- (vga16Colors[j][0] << 8) | vga16Colors[j][0];
- pmap->red[i].co.local.green =
- (vga16Colors[j][1] << 8) | vga16Colors[j][1];
- pmap->red[i].co.local.blue =
- (vga16Colors[j][2] << 8) | vga16Colors[j][2];
- }
- return TRUE;
- }
- static void vesaSetScreenSizes(ScreenPtr pScreen)
- {
- KdScreenPriv(pScreen);
- KdScreenInfo *screen = pScreenPriv->screen;
- VesaScreenPrivPtr pscr = screen->driver;
- if (pscr->randr & (RR_Rotate_0 | RR_Rotate_180)) {
- pScreen->width = pscr->mode.XResolution;
- pScreen->height = pscr->mode.YResolution;
- pScreen->mmWidth = screen->width_mm;
- pScreen->mmHeight = screen->height_mm;
- } else {
- pScreen->width = pscr->mode.YResolution;
- pScreen->height = pscr->mode.XResolution;
- pScreen->mmWidth = screen->height_mm;
- pScreen->mmHeight = screen->width_mm;
- }
- }
- static Bool vesaSetShadow(ScreenPtr pScreen)
- {
- KdScreenPriv(pScreen);
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- ShadowUpdateProc update;
- ShadowWindowProc window = 0;
- if (pscr->randr != RR_Rotate_0)
- update = shadowUpdateRotatePacked;
- else
- update = shadowUpdatePacked;
- switch (pscr->mapping) {
- case VESA_LINEAR:
- window = vesaWindowLinear;
- break;
- case VESA_WINDOWED:
- window = vesaWindowWindowed;
- break;
- case VESA_PLANAR:
- if (pScreenPriv->screen->fb.bitsPerPixel == 8)
- update = shadowUpdatePlanar4x8;
- else
- update = shadowUpdatePlanar4;
- window = vesaWindowPlanar;
- break;
- case VESA_MONO:
- update = vesaUpdateMono;
- if (pscr->mode.mode < 8)
- window = vesaWindowCga;
- else
- window = vesaWindowLinear;
- break;
- }
- return KdShadowSet(pScreen, pscr->randr, update, window);
- }
- static Bool vesaComputeFramebufferMapping(KdScreenInfo * screen)
- {
- VesaScreenPrivPtr pscr = screen->driver;
- int depth, bpp, fbbpp;
- Pixel allbits;
- KdMouseMatrix m;
- if (vesa_linear_fb) {
- pscr->mapping = VESA_LINEAR;
- pscr->shadow = FALSE;
- } else {
- pscr->mapping = VESA_WINDOWED;
- pscr->shadow = TRUE;
- }
- depth = vesaDepth(&pscr->mode);
- bpp = pscr->mode.BitsPerPixel;
- if (bpp > 24)
- bpp = 32;
- else if (bpp > 16)
- bpp = 24;
- else if (bpp > 8)
- bpp = 16;
- else if (bpp > 4)
- bpp = 8;
- else if (bpp > 1)
- bpp = 4;
- else
- bpp = 1;
- fbbpp = bpp;
- switch (pscr->mode.MemoryModel) {
- case MEMORY_DIRECT:
- allbits = (screen->fb.redMask |
- screen->fb.greenMask | screen->fb.blueMask);
- depth = 32;
- while (depth && !(allbits & (1 << (depth - 1))))
- depth--;
- if (vesa_verbose)
- ErrorF
- ("\tTrue Color %d/%d red 0x%x green 0x%x blue 0x%x\n",
- bpp, depth, screen->fb.redMask,
- screen->fb.greenMask, screen->fb.blueMask);
- break;
- case MEMORY_PSEUDO:
- if (vesa_verbose)
- ErrorF("\tPseudo Color bpp %d depth %d\n", bpp, depth);
- break;
- case MEMORY_PLANAR:
- if (bpp == 4) {
- bpp = screen->fb.bitsPerPixel;
- if (bpp != 8)
- bpp = 4;
- depth = bpp;
- }
- if (bpp == 1) {
- pscr->mapping = VESA_MONO;
- if (vesa_verbose)
- ErrorF("\tMonochrome\n");
- } else {
- pscr->mapping = VESA_PLANAR;
- if (vesa_verbose)
- ErrorF("\tStatic color bpp %d depth %d\n",
- bpp, depth);
- }
- pscr->randr = RR_Rotate_0;
- pscr->shadow = TRUE;
- break;
- default:
- return FALSE;
- }
- switch (fbbpp) {
- case 8:
- case 16:
- case 32:
- break;
- default:
- pscr->randr = RR_Rotate_0;
- break;
- }
- if (pscr->randr != RR_Rotate_0)
- pscr->shadow = TRUE;
- if (vesa_shadow)
- pscr->shadow = vesa_shadow;
- if (pscr->mapping == VESA_LINEAR
- && !(pscr->mode.ModeAttributes & MODE_LINEAR)) {
- pscr->mapping = VESA_WINDOWED;
- pscr->shadow = TRUE;
- }
- KdComputeMouseMatrix(&m, pscr->randr,
- pscr->mode.XResolution, pscr->mode.YResolution);
- KdSetMouseMatrix(&m);
- screen->width = pscr->mode.XResolution;
- screen->height = pscr->mode.YResolution;
- screen->fb.depth = depth;
- screen->fb.bitsPerPixel = bpp;
- return TRUE;
- }
- static Bool vesaMapFramebuffer(KdScreenInfo * screen)
- {
- VesaCardPrivPtr priv = screen->card->driver;
- VesaScreenPrivPtr pscr = screen->driver;
- if (pscr->mapped)
- return TRUE;
- switch (pscr->mapping) {
- case VESA_MONO:
- case VESA_LINEAR:
- if (pscr->mode.vbe)
- pscr->fb = VbeMapFramebuffer(priv->vi, priv->vbeInfo,
- pscr->mode.mode,
- &pscr->fb_size,
- &pscr->fb_phys);
- else
- pscr->fb = VgaMapFramebuffer(priv->vi,
- pscr->mode.mode,
- &pscr->fb_size,
- &pscr->fb_phys);
- if (!pscr->fb)
- return FALSE;
- break;
- case VESA_WINDOWED:
- pscr->fb = NULL;
- break;
- case VESA_PLANAR:
- pscr->fb = NULL;
- break;
- }
- screen->memory_base = pscr->fb;
- screen->memory_size = pscr->fb_size;
- if (pscr->shadow) {
- if (!KdShadowFbAlloc(screen,
- pscr->randr & (RR_Rotate_90 |
- RR_Rotate_270)))
- return FALSE;
- screen->off_screen_base = screen->memory_size;
- } else {
- screen->fb.frameBuffer = (CARD8 *) (pscr->fb);
- screen->fb.byteStride = pscr->mode.BytesPerScanLine;
- screen->fb.pixelStride = ((pscr->mode.BytesPerScanLine * 8) /
- screen->fb.bitsPerPixel);
- screen->off_screen_base =
- screen->fb.byteStride * screen->height;
- }
- pscr->mapped = TRUE;
- return TRUE;
- }
- static void vesaUnmapFramebuffer(KdScreenInfo * screen)
- {
- VesaCardPrivPtr priv = screen->card->driver;
- VesaScreenPrivPtr pscr = screen->driver;
- if (!pscr->mapped)
- return;
- pscr->mapped = FALSE;
- KdShadowFbFree(screen);
- if (pscr->fb) {
- if (pscr->mode.vbe)
- VbeUnmapFramebuffer(priv->vi, priv->vbeInfo,
- pscr->mode.mode, pscr->fb);
- else
- VgaUnmapFramebuffer(priv->vi);
- pscr->fb = 0;
- }
- }
- static Bool vesaSetMode(ScreenPtr pScreen, VesaModePtr mode);
- static Bool vesaRandRGetInfo(ScreenPtr pScreen, Rotation * rotations)
- {
- KdScreenPriv(pScreen);
- VesaModePtr modes, mode;
- KdScreenInfo *screen = pScreenPriv->screen;
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- int nmode;
- int n;
- RRScreenSizePtr pSize;
- *rotations =
- (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270 |
- RR_Reflect_X | RR_Reflect_Y);
- /*
- * Get mode information from BIOS -- every time in case
- * something changes, like an external monitor is plugged in
- */
- modes = vesaGetModes(priv->vi, &nmode);
- if (!modes)
- return FALSE;
- if (priv->modes)
- free(priv->modes);
- priv->modes = modes;
- priv->nmode = nmode;
- for (n = 0; n < nmode; n++) {
- mode = &priv->modes[n];
- if (vesaModeSupported(priv, mode, FALSE)) {
- /*
- * XXX limit reported modes to those matching the current
- * format
- */
- if (mode->NumberOfPlanes == pscr->mode.NumberOfPlanes &&
- mode->BitsPerPixel == pscr->mode.BitsPerPixel &&
- mode->MemoryModel == pscr->mode.MemoryModel &&
- mode->RedMaskSize == pscr->mode.RedMaskSize &&
- mode->RedFieldPosition ==
- pscr->mode.RedFieldPosition
- && mode->GreenMaskSize == pscr->mode.GreenMaskSize
- && mode->GreenFieldPosition ==
- pscr->mode.GreenFieldPosition
- && mode->BlueMaskSize == pscr->mode.BlueMaskSize
- && mode->BlueFieldPosition ==
- pscr->mode.BlueFieldPosition) {
- int width, height, width_mm, height_mm;
- if (screen->randr &
- (RR_Rotate_0 | RR_Rotate_180)) {
- width = mode->XResolution;
- height = mode->YResolution;
- width_mm = screen->width_mm;
- height_mm = screen->height_mm;
- } else {
- width = mode->YResolution;
- height = mode->XResolution;
- width_mm = screen->height_mm;
- height_mm = screen->width_mm;
- }
- pSize = RRRegisterSize(pScreen,
- width, height,
- width_mm, height_mm);
- if (mode->XResolution == screen->width &&
- mode->YResolution == screen->height) {
- int randr = KdSubRotation(pscr->randr,
- screen->
- randr);
- RRSetCurrentConfig(pScreen, randr, 0,
- pSize);
- }
- }
- }
- }
- return TRUE;
- }
- static Bool
- vesaRandRSetConfig(ScreenPtr pScreen,
- Rotation randr, int rate, RRScreenSizePtr pSize)
- {
- KdScreenPriv(pScreen);
- VesaModePtr mode = 0;
- KdScreenInfo *screen = pScreenPriv->screen;
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- int n;
- Bool wasEnabled = pScreenPriv->enabled;
- Bool ret = FALSE;
- VesaScreenPrivRec oldscr;
- int oldwidth;
- int oldheight;
- int oldmmwidth;
- int oldmmheight;
- int newwidth, newheight;
- if (screen->randr & (RR_Rotate_0 | RR_Rotate_180)) {
- newwidth = pSize->width;
- newheight = pSize->height;
- } else {
- newwidth = pSize->height;
- newheight = pSize->width;
- }
- for (n = 0; n < priv->nmode; n++) {
- mode = &priv->modes[n];
- if (vesaModeSupported(priv, mode, FALSE)) {
- /*
- * XXX all we have to match is the size
- */
- if (mode->XResolution == newwidth &&
- mode->YResolution == newheight &&
- mode->NumberOfPlanes == pscr->mode.NumberOfPlanes &&
- mode->BitsPerPixel == pscr->mode.BitsPerPixel &&
- mode->RedMaskSize == pscr->mode.RedMaskSize &&
- mode->RedFieldPosition ==
- pscr->mode.RedFieldPosition
- && mode->GreenMaskSize == pscr->mode.GreenMaskSize
- && mode->GreenFieldPosition ==
- pscr->mode.GreenFieldPosition
- && mode->BlueMaskSize == pscr->mode.BlueMaskSize
- && mode->BlueFieldPosition ==
- pscr->mode.BlueFieldPosition)
- break;
- }
- }
- if (n == priv->nmode)
- goto bail0;
- if (wasEnabled)
- KdDisableScreen(pScreen);
- if (mode->mode != pscr->mode.mode) {
- ret = vesaSetMode(pScreen, mode);
- if (!ret)
- goto bail1;
- }
- oldscr = *pscr;
- oldwidth = screen->width;
- oldheight = screen->height;
- oldmmwidth = pScreen->mmWidth;
- oldmmheight = pScreen->mmHeight;
- /*
- * Set new configuration
- */
- pscr->mode = *mode;
- pscr->randr = KdAddRotation(screen->randr, randr);
- /*
- * Can't rotate some formats
- */
- switch (screen->fb.bitsPerPixel) {
- case 8:
- case 16:
- case 32:
- break;
- default:
- if (pscr->randr)
- goto bail2;
- break;
- }
- vesaUnmapFramebuffer(screen);
- if (!vesaComputeFramebufferMapping(screen))
- goto bail3;
- if (!vesaMapFramebuffer(screen))
- goto bail3;
- vesaSetScreenSizes(screen->pScreen);
- if (!vesaSetShadow(screen->pScreen))
- goto bail4;
- /*
- * Set frame buffer mapping
- */
- (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap(pScreen),
- pScreen->width,
- pScreen->height,
- screen->fb.depth,
- screen->fb.bitsPerPixel,
- screen->fb.byteStride,
- screen->fb.frameBuffer);
- /* set the subpixel order */
- KdSetSubpixelOrder(pScreen, pscr->randr);
- if (wasEnabled)
- KdEnableScreen(pScreen);
- return TRUE;
- bail4:
- vesaUnmapFramebuffer(screen);
- *pscr = oldscr;
- (void)vesaComputeFramebufferMapping(screen);
- (void)vesaMapFramebuffer(screen);
- bail3:
- pScreen->width = oldwidth;
- pScreen->height = oldheight;
- pScreen->mmWidth = oldmmwidth;
- pScreen->mmHeight = oldmmheight;
- bail2:
- *pscr = oldscr;
- (void)vesaSetMode(pScreen, &pscr->mode);
- bail1:
- if (wasEnabled)
- KdEnableScreen(pScreen);
- bail0:
- return FALSE;
- }
- static Bool vesaRandRInit(ScreenPtr pScreen)
- {
- rrScrPrivPtr pScrPriv;
- if (!RRScreenInit(pScreen))
- return FALSE;
- pScrPriv = rrGetScrPriv(pScreen);
- pScrPriv->rrGetInfo = vesaRandRGetInfo;
- pScrPriv->rrSetConfig = vesaRandRSetConfig;
- return TRUE;
- }
- Bool vesaInitScreen(ScreenPtr pScreen)
- {
- KdScreenPriv(pScreen);
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- switch (pscr->mapping) {
- case VESA_PLANAR:
- pScreen->CreateColormap = vesaCreateColormap16;
- break;
- }
- return TRUE;
- }
- Bool vesaFinishInitScreen(ScreenPtr pScreen)
- {
- if (!shadowSetup(pScreen))
- return FALSE;
- if (!vesaRandRInit(pScreen))
- return FALSE;
- return TRUE;
- }
- Bool vesaCreateResources(ScreenPtr pScreen)
- {
- return vesaSetShadow(pScreen);
- }
- static Bool vesaSetMode(ScreenPtr pScreen, VesaModePtr mode)
- {
- KdScreenPriv(pScreen);
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- int code;
- if (mode->vbe) {
- if (vesa_verbose)
- ErrorF("Enable VBE mode 0x%x\n", mode->mode);
- code = VbeSetMode(priv->vi, priv->vbeInfo, mode->mode,
- pscr->mapping == VESA_LINEAR,
- mode->MemoryModel == MEMORY_DIRECT);
- } else {
- if (vesa_verbose)
- ErrorF("Enable BIOS mode 0x%x\n", mode->mode);
- code = VgaSetMode(priv->vi, mode->mode);
- }
- if (code < 0)
- return FALSE;
- return TRUE;
- }
- Bool vesaEnable(ScreenPtr pScreen)
- {
- KdScreenPriv(pScreen);
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- KdScreenInfo *screen = pScreenPriv->screen;
- int i;
- CARD32 size;
- char *p;
- Bool was_mapped = pscr->mapped;
- if (!vesaMapFramebuffer(screen))
- return FALSE;
- if (!vesaSetMode(pScreen, &pscr->mode))
- return FALSE;
- switch (pscr->mapping) {
- case VESA_MONO:
- VgaSetWritePlaneMask(priv->vi, 0x1);
- case VESA_LINEAR:
- if (vesa_restore_font)
- memcpy(priv->text, pscr->fb, VESA_TEXT_SAVE);
- break;
- case VESA_WINDOWED:
- if (vesa_restore_font) {
- for (i = 0; i < VESA_TEXT_SAVE;) {
- p = vesaSetWindowWindowed(pScreen, 0, i,
- VBE_WINDOW_READ,
- &size);
- if (!p) {
- ErrorF
- ("Couldn't set window for saving VGA font\n");
- break;
- }
- if (i + size > VESA_TEXT_SAVE)
- size = VESA_TEXT_SAVE - i;
- memcpy(((char *)priv->text) + i, p, size);
- i += size;
- }
- }
- break;
- case VESA_PLANAR:
- if (vesa_restore_font) {
- for (i = 0; i < 4; i++) {
- p = vesaSetWindowPlanar(pScreen, 0, i,
- VBE_WINDOW_READ, &size);
- memcpy(((char *)priv->text) +
- i * (VESA_TEXT_SAVE / 4), p,
- (VESA_TEXT_SAVE / 4));
- }
- }
- break;
- }
- if (!was_mapped) {
- (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap(pScreen),
- pScreen->width,
- pScreen->height,
- screen->fb.depth,
- screen->fb.bitsPerPixel,
- screen->fb.byteStride,
- screen->fb.frameBuffer);
- }
- return TRUE;
- }
- #ifndef TOSHIBA_SMM
- # ifdef linux
- # define TOSHIBA_SMM 1
- # endif
- # ifndef TOSHIBA_SMM
- # define TOSHIBA_SMM 0
- # endif
- #endif
- #if TOSHIBA_SMM
- /*
- * Toshiba laptops use a special interface to operate the backlight
- */
- #include <sys/ioctl.h>
- #define TOSH_PROC "/proc/toshiba"
- #define TOSH_DEVICE "/dev/toshiba"
- #define TOSH_SMM _IOWR('t', 0x90, SMMRegisters)
- typedef struct {
- unsigned int eax;
- unsigned int ebx __attribute__ ((packed));
- unsigned int ecx __attribute__ ((packed));
- unsigned int edx __attribute__ ((packed));
- unsigned int esi __attribute__ ((packed));
- unsigned int edi __attribute__ ((packed));
- } SMMRegisters;
- #define HCI_BACKLIGHT 0x0002
- #define HCI_DISABLE 0x0000
- #define HCI_ENABLE 0x0001
- #define HCI_GET 0xfe00,
- #define HCI_SET 0xff00
- static Bool toshibaDPMS(ScreenPtr pScreen, int mode)
- {
- SMMRegisters regs;
- static int fd;
- if (!fd)
- fd = open(TOSH_DEVICE, 2);
- if (fd < 0)
- return FALSE;
- regs.eax = HCI_SET;
- regs.ebx = HCI_BACKLIGHT;
- regs.ecx = mode ? HCI_DISABLE : HCI_ENABLE;
- if (ioctl(fd, TOSH_SMM, ®s) < 0)
- return FALSE;
- return TRUE;
- }
- #endif /* TOSHIBA_SMM */
- Bool vesaDPMS(ScreenPtr pScreen, int mode)
- {
- KdScreenPriv(pScreen);
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- #if TOSHIBA_SMM
- if (toshibaDPMS(pScreen, mode))
- return TRUE;
- #endif
- if (pscr->mode.vbe)
- return VbeDPMS(priv->vi, mode);
- return FALSE;
- }
- void vesaDisable(ScreenPtr pScreen)
- {
- KdScreenPriv(pScreen);
- KdScreenInfo *screen = pScreenPriv->screen;
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- VesaScreenPrivPtr pscr = screen->driver;
- int i = 0;
- CARD32 size;
- char *p;
- if (vesa_restore_font) {
- switch (pscr->mapping) {
- case VESA_LINEAR:
- case VESA_MONO:
- memcpy(pscr->fb, priv->text, VESA_TEXT_SAVE);
- break;
- case VESA_WINDOWED:
- while (i < VESA_TEXT_SAVE) {
- p = vesaSetWindowWindowed(pScreen, 0, i,
- VBE_WINDOW_WRITE,
- &size);
- if (!p) {
- ErrorF
- ("Couldn't set window for restoring VGA font\n");
- break;
- }
- if (i + size > VESA_TEXT_SAVE)
- size = VESA_TEXT_SAVE - i;
- memcpy(p, ((char *)priv->text) + i, size);
- i += size;
- }
- break;
- case VESA_PLANAR:
- for (i = 0; i < 4; i++) {
- p = vesaSetWindowPlanar(pScreen, 0, i,
- VBE_WINDOW_WRITE,
- &size);
- memcpy(p,
- ((char *)priv->text) +
- i * (VESA_TEXT_SAVE / 4),
- (VESA_TEXT_SAVE / 4));
- }
- break;
- }
- }
- vesaUnmapFramebuffer(screen);
- }
- void vesaPreserve(KdCardInfo * card)
- {
- VesaCardPrivPtr priv = card->driver;
- /* The framebuffer might not be valid at this point, so we cannot
- save the VGA fonts now; we do it in vesaEnable. */
- if (VbeGetMode(priv->vi, &priv->old_vbe_mode) < 0)
- priv->old_vbe_mode = -1;
- if (VgaGetMode(priv->vi, &priv->old_vga_mode) < 0)
- priv->old_vga_mode = -1;
- if (vesa_verbose)
- ErrorF("Previous modes: VBE 0x%x BIOS 0x%x\n",
- priv->old_vbe_mode, priv->old_vga_mode);
- }
- void vesaRestore(KdCardInfo * card)
- {
- VesaCardPrivPtr priv = card->driver;
- int n;
- if (vesa_force_text) {
- if (vesa_verbose)
- ErrorF("Forcing switch back to mode 3 text\n");
- priv->old_vbe_mode = -1;
- priv->old_vga_mode = 3;
- }
- for (n = 0; n < priv->nmode; n++)
- if (priv->modes[n].vbe
- && priv->modes[n].mode == (priv->old_vbe_mode & 0x3fff))
- break;
- if (n < priv->nmode) {
- if (vesa_verbose)
- ErrorF("Restore VBE mode 0x%x\n", priv->old_vbe_mode);
- VbeSetMode(priv->vi, priv->vbeInfo, priv->old_vbe_mode, 0, 0);
- } else {
- if (vesa_verbose)
- ErrorF("Restore BIOS mode 0x%x\n", priv->old_vga_mode);
- VgaSetMode(priv->vi, priv->old_vga_mode);
- }
- }
- void vesaCardFini(KdCardInfo * card)
- {
- VesaCardPrivPtr priv = card->driver;
- if (priv->vbeInfo)
- VbeCleanup(priv->vi, priv->vbeInfo);
- if (priv->modes)
- free(priv->modes);
- Vm86Cleanup(priv->vi);
- free(priv);
- }
- void vesaScreenFini(KdScreenInfo * screen)
- {
- VesaScreenPrivPtr pscr = screen->driver;
- KdShadowFbFree(screen);
- vesaUnmapFramebuffer(screen);
- screen->fb.depth = pscr->origDepth;
- free(pscr);
- }
- static int vesaSetPalette(VesaCardPrivPtr priv, int first, int number, U8 * entries)
- {
- if (priv->vga_palette)
- return VgaSetPalette(priv->vi, first, number, entries);
- else
- return VbeSetPalette(priv->vi, priv->vbeInfo, first, number,
- entries);
- }
- static int vesaGetPalette(VesaCardPrivPtr priv, int first, int number, U8 * entries)
- {
- int code;
- if (priv->vga_palette)
- code = VgaGetPalette(priv->vi, first, number, entries);
- else {
- code =
- VbeGetPalette(priv->vi, priv->vbeInfo, first, number,
- entries);
- if (code < 0) {
- priv->vga_palette = 1;
- code = VgaGetPalette(priv->vi, first, number, entries);
- }
- }
- return code;
- }
- void vesaPutColors(ScreenPtr pScreen, int n, xColorItem * pdefs)
- {
- KdScreenPriv(pScreen);
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- int p;
- CARD8 *scratch;
- int red, green, blue;
- int min, max;
- if (vesa_swap_rgb) {
- red = 2;
- green = 1;
- blue = 0;
- } else {
- red = 0;
- green = 1;
- blue = 2;
- }
- min = 256;
- max = 0;
- while (n--) {
- p = pdefs->pixel;
- if (p < min)
- min = p;
- if (p > max)
- max = p;
- scratch = priv->cmap + (p * 4);
- scratch[red] = pdefs->red >> 8;
- scratch[green] = pdefs->green >> 8;
- scratch[blue] = pdefs->blue >> 8;
- scratch[3] = 0;
- pdefs++;
- if (pscr->mapping == VESA_PLANAR) {
- /*
- * VGA modes are strange; this code covers all
- * possible modes by duplicating the color information
- * however the attribute registers might be set
- */
- if (p < 16) {
- vesaSetPalette(priv, p, 1, scratch);
- if (p >= 8)
- vesaSetPalette(priv, p + 0x30, 1,
- scratch);
- else if (p == 6)
- vesaSetPalette(priv, 0x14, 1, scratch);
- }
- }
- }
- if (pscr->mapping != VESA_PLANAR)
- vesaSetPalette(priv, min, max - min + 1, priv->cmap + min * 4);
- }
- void vesaGetColors(ScreenPtr pScreen, int n, xColorItem * pdefs)
- {
- KdScreenPriv(pScreen);
- VesaScreenPrivPtr pscr = pScreenPriv->screen->driver;
- VesaCardPrivPtr priv = pScreenPriv->card->driver;
- int i;
- int red, green, blue;
- int min, max;
- int p;
- CARD8 *scratch;
- if (vesa_swap_rgb) {
- red = 2;
- green = 1;
- blue = 0;
- } else {
- red = 0;
- green = 1;
- blue = 2;
- }
- min = 256;
- max = 0;
- for (i = 0; i < n; i++) {
- p = pdefs[i].pixel;
- if (p < min)
- min = p;
- if (p > max)
- max = p;
- if (pscr->mapping == VESA_PLANAR)
- vesaGetPalette(priv, p, 1, priv->cmap + p * 4);
- }
- if (pscr->mapping != VESA_PLANAR)
- vesaGetPalette(priv, min, max - min + 1, priv->cmap + min * 4);
- for (i = 0; i < n; i++) {
- p = pdefs[i].pixel;
- scratch = priv->cmap + p * 4;
- pdefs[i].red = scratch[red] << 8;
- pdefs[i].green = scratch[green] << 8;
- pdefs[i].blue = scratch[blue] << 8;
- }
- }
- void vesaUseMsg(void)
- {
- ErrorF("\nTinyX VESA Usage:\n");
- ErrorF("-mode VESA video mode to use (Be careful!)\n");
- ErrorF("-listmodes List supported video modes\n");
- ErrorF("-force Attempt even unsupported modes\n");
- ErrorF("-no-shadow Don't use a shadow framebuffer (default on)\n");
- ErrorF("-nolinear Never use linear framebuffer (Not useful)\n");
- ErrorF
- ("-swaprgb Use if colors are wrong in PseudoColor and 16 color modes\n");
- ErrorF
- ("-map-holes Use contiguous memory map (For seg fault with rare BIOS)\n");
- ErrorF
- ("-verbose Emit diagnostic messages during BIOS initialization\n");
- ErrorF
- ("-force-text Always use standard 25x80 text mode on server exit or VT switch\n");
- ErrorF("-boot Soft boot video card\n");
- /* XXX: usage for -vesatest, -no-map-holes (don't need?),
- * XXX: and -trash-font. Also in man page. */
- }
- int vesaProcessArgument(int argc, char **argv, int i)
- {
- if (!strcmp(argv[i], "-mode")) {
- if (i + 1 < argc) {
- vesa_video_mode = strtol(argv[i + 1], NULL, 0);
- } else
- UseMsg();
- return 2;
- } else if (!strcmp(argv[i], "-force")) {
- vesa_force_mode = TRUE;
- return 1;
- } else if (!strcmp(argv[i], "-listmodes")) {
- vesaListModes();
- exit(0);
- } else if (!strcmp(argv[i], "-vesatest")) {
- vesaTestMode();
- exit(0);
- } else if (!strcmp(argv[i], "-swaprgb")) {
- vesa_swap_rgb = TRUE;
- return 1;
- } else if (!strcmp(argv[i], "-shadow")) {
- vesa_shadow = TRUE;
- return 1;
- } else if (!strcmp(argv[i], "-no-shadow")) {
- vesa_shadow = FALSE;
- return 1;
- } else if (!strcmp(argv[i], "-nolinear")) {
- vesa_linear_fb = FALSE;
- return 1;
- } else if (!strcmp(argv[i], "-verbose")) {
- vesa_verbose = TRUE;
- return 1;
- } else if (!strcmp(argv[i], "-force-text")) {
- vesa_force_text = TRUE;
- return 1;
- } else if (!strcmp(argv[i], "-map-holes")) {
- vesa_map_holes = TRUE;
- return 1;
- } else if (!strcmp(argv[i], "-no-map-holes")) {
- vesa_map_holes = FALSE;
- return 1;
- } else if (!strcmp(argv[i], "-trash-font")) {
- vesa_restore_font = FALSE;
- return 1;
- } else if (!strcmp(argv[i], "-boot")) {
- vesa_boot = TRUE;
- return 1;
- }
- return 0;
- }
|