1445N/A/* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
691N/A *
691N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
691N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
691N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
691N/A */
691N/A
691N/A
691N/A
691N/A#if defined(__sparc)
691N/A
691N/A#ifdef HAVE_CONFIG_H
691N/A#include <config.h>
691N/A#endif
691N/A#include "xf86.h"
691N/A#include "xf86_OSproc.h"
691N/A#include "xf86cmap.h"
691N/A#include "compiler.h"
691N/A#include "vgaHW.h"
691N/A#include "mipointer.h"
691N/A#include "micmap.h"
691N/A
691N/A#include "fb.h"
691N/A#include "regionstr.h"
691N/A#include "xf86xv.h"
691N/A#include <X11/extensions/Xv.h>
691N/A#include "vbe.h"
691N/A
691N/A#include "xf86PciInfo.h"
691N/A#include "xf86Pci.h"
691N/A
691N/A/* framebuffer offscreen manager */
691N/A#include "xf86fbman.h"
691N/A
691N/A/* include xaa includes */
1351N/A#ifdef HAVE_XAA
691N/A#include "xaa.h"
1351N/A#endif
691N/A#include "xaarop.h"
691N/A
691N/A/* H/W cursor support */
691N/A#include "xf86Cursor.h"
691N/A
691N/A#include "ast.h"
1445N/A#include "ast_vgatool.h"
691N/A#include <stdlib.h>
691N/A#include <stdio.h>
691N/A#include <fcntl.h>
691N/A#include <sys/mman.h>
691N/A
851N/Aextern Bool ASTGetRec(ScrnInfoPtr pScrn);
691N/A
691N/A#define AST_REG_SIZE (256*1024)
691N/A#define AST_REG_SIZE_LOG2 18
691N/A
1264N/A#define AST_DEFAULT_DEVICE_PATH "/dev/fb0"
691N/A
691N/A#define PCI_MAP_MEMORY 0x00000000
691N/A#define PCI_MAP_IO 0x00000001
691N/A
691N/A#define PCI_MAP_MEMORY_TYPE 0x00000007
691N/A#define PCI_MAP_MEMORY_TYPE_64BIT 0x00000004
691N/A#define PCI_MAP_IO_TYPE 0x00000003
691N/A
691N/A#define PCI_MAP_MEMORY_ADDRESS_MASK 0xfffffff0
691N/A#define PCI_MAP_IO_ADDRESS_MASK 0xfffffffc
691N/A
691N/A#define PCI_MAP_IS_IO(b) ((b) & PCI_MAP_IO)
691N/A
691N/A#define PCI_MAP_IS64BITMEM(b) \
691N/A (((b) & PCI_MAP_MEMORY_TYPE) == PCI_MAP_MEMORY_TYPE_64BIT)
691N/A
691N/A#define PCIGETMEMORY(b) ((b) & PCI_MAP_MEMORY_ADDRESS_MASK)
691N/A#define PCIGETMEMORY64HIGH(b) (*((CARD32*)&(b) + 1))
691N/A#define PCIGETMEMORY64(b) \
691N/A (PCIGETMEMORY(b) | ((CARD64)PCIGETMEMORY64HIGH(b) << 32))
691N/A
691N/A#define PCIGETIO(b) ((b) & PCI_MAP_IO_ADDRESS_MASK)
691N/A
691N/A
691N/Astruct pci_device *ASTGetPciInfo(ASTRecPtr info)
691N/A{
691N/A int status;
691N/A struct pci_device *pciInfo = NULL;
691N/A int i;
691N/A struct vis_pci_cfg pciCfg;
691N/A int bar;
691N/A
691N/A if ((status = ioctl(info->fd, VIS_GETPCICONFIG, &pciCfg))
691N/A != -1) {
691N/A pciInfo = malloc(sizeof(struct pci_device));
691N/A
691N/A pciInfo->vendor_id = pciCfg.VendorID;
691N/A pciInfo->device_id = pciCfg.DeviceID;
691N/A pciInfo->revision = pciCfg.RevisionID;
691N/A pciInfo->subvendor_id = pciCfg.SubVendorID;
691N/A pciInfo->subdevice_id = pciCfg.SubSystemID;
691N/A
691N/A for (i = 0; i < 6; i++) {
691N/A bar = pciCfg.bar[i];
691N/A if (bar != 0) {
691N/A if (bar & PCI_MAP_IO) {
691N/A pciInfo->regions[i].base_addr = (memType)PCIGETIO(bar);
691N/A
691N/A } else {
691N/A pciInfo->regions[i].size = AST_REG_SIZE_LOG2;
691N/A pciInfo->regions[i].base_addr = (memType)PCIGETMEMORY(bar);
691N/A if (PCI_MAP_IS64BITMEM(bar)) {
691N/A if (i == 5) {
691N/A pciInfo->regions[i].base_addr = 0;
691N/A } else {
691N/A int bar_hi = pciCfg.bar[i+1];
691N/A /* 64 bit architecture */
691N/A pciInfo->regions[i].base_addr |= (memType)bar_hi << 32;
691N/A ++i; /* Step over the next BAR */
691N/A }
691N/A }
691N/A }
691N/A }
691N/A }
691N/A }
691N/A
691N/A return pciInfo;
691N/A}
691N/A
691N/Astatic ScrnInfoPtr
691N/Aast_get_scrninfo(int entity_num)
691N/A{
691N/A ScrnInfoPtr pScrn = NULL;
691N/A EntityInfoPtr pEnt;
691N/A
691N/A pScrn = xf86ConfigFbEntity(NULL,0,entity_num, NULL,NULL,NULL,NULL);
691N/A return pScrn;
691N/A}
691N/A
691N/AScrnInfoPtr
691N/AASTAllocScreen(DriverPtr drv, GDevPtr pDev)
691N/A{
691N/A int i;
691N/A int foundScreen = FALSE;
691N/A
691N/A char * dev;
691N/A int entity;
691N/A ASTRecPtr info;
691N/A int fd;
691N/A ScrnInfoPtr pScrn = NULL;
691N/A
691N/A entity = xf86ClaimFbSlot(drv, 0, pDev, TRUE);
691N/A if (pScrn = xf86ConfigFbEntity(NULL, 0, entity, NULL, NULL, NULL, NULL)) {
691N/A dev = xf86FindOptionValue(pDev->options, "device");
691N/A if (dev == NULL) {
691N/A dev = AST_DEFAULT_DEVICE_PATH;
691N/A }
691N/A
691N/A if (((fd = open(dev, O_RDWR, 0)) >= 0)) {
691N/A if (ASTGetRec(pScrn)) {
691N/A foundScreen = TRUE;
691N/A info = ASTPTR(pScrn);
691N/A info->deviceName = dev;
691N/A info->fd = fd;
691N/A }
1264N/A } else {
1264N/A xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
1264N/A "Cannot open device %s\n", dev);
1264N/A return NULL;
1264N/A }
691N/A }
691N/A return pScrn;
691N/A}
691N/A
691N/A
691N/Apointer
691N/AASTMapVidMem(ScrnInfoPtr pScrn, unsigned int flags, PCITAG pciTag,
691N/A unsigned long base, unsigned long size)
691N/A{
691N/A int BUS_BASE = 0;
691N/A pointer memBase;
691N/A int fdd;
691N/A int mapflags = MAP_SHARED;
691N/A int prot;
691N/A memType realBase, alignOff;
691N/A unsigned long realSize;
691N/A int pageSize;
691N/A ASTRecPtr info = ASTPTR(pScrn);
691N/A
691N/A fdd = info->fd;
691N/A realBase = base & ~(getpagesize() - 1);
691N/A alignOff = base - realBase;
691N/A
691N/A pageSize = getpagesize();
691N/A realSize = size + (pageSize - 1) & (~(pageSize - 1));
691N/A
691N/A#ifdef DEBUG
691N/A printf("base: %lx, realBase: %lx, alignOff: %lx \n",
691N/A base, realBase, alignOff);
691N/A#endif /* DEBUG */
691N/A
691N/A if (flags & VIDMEM_READONLY) {
691N/A prot = PROT_READ;
691N/A } else {
691N/A prot = PROT_READ | PROT_WRITE;
691N/A }
691N/A
691N/A memBase = mmap((caddr_t)0, realSize + alignOff, prot, mapflags, fdd,
691N/A (off_t)(off_t)realBase + BUS_BASE);
691N/A
691N/A if (memBase == MAP_FAILED) {
691N/A#ifdef DEBUG
691N/A printf("ASTMapVidMem: Could not map framebuffer\n");
691N/A#endif /* DEBUG */
691N/A return NULL;
691N/A }
691N/A
691N/A return ((char *)memBase + alignOff);
691N/A}
691N/A
691N/Avoid
691N/AASTUnmapVidMem(ScrnInfoPtr pScrn, pointer base, unsigned long size)
691N/A{
691N/A memType alignOff = (memType)base - ((memType)base & ~(getpagesize() - 1));
691N/A
691N/A munmap((caddr_t)((memType)base - alignOff), (size + alignOff));
691N/A
691N/A return;
691N/A}
691N/A
691N/A
691N/Avoid
691N/AASTNotifyModeChanged(ScrnInfoPtr pScrn)
691N/A{
691N/A struct vis_video_mode mode;
691N/A ASTRecPtr info = ASTPTR(pScrn);
691N/A int status;
691N/A
691N/A if (pScrn->currentMode->name != NULL) {
691N/A strlcpy(mode.mode_name, pScrn->currentMode->name, VIS_MAX_VMODE_LEN);
691N/A } else {
691N/A strlcpy(mode.mode_name, " ", VIS_MAX_VMODE_LEN);
691N/A }
691N/A mode.vRefresh = pScrn->currentMode->VRefresh;
691N/A
691N/A status = ioctl(info->fd, VIS_STOREVIDEOMODENAME, &mode);
691N/A}
691N/A
691N/Avoid
691N/AASTSaveHW(ScrnInfoPtr pScrn)
691N/A{
1265N/A ASTRecPtr pAST = ASTPTR(pScrn);
691N/A ASTRegPtr astReg;
691N/A int i, icount=0;
691N/A UCHAR jReg;
691N/A
691N/A astReg = &pAST->SavedReg;
691N/A
691N/A /* Save Misc */
1295N/A astReg->MISC = GetReg(MISC_PORT_READ);
691N/A
691N/A /* Save SR */
691N/A for (i=0; i<4; i++)
691N/A GetIndexReg(SEQ_PORT, (UCHAR) (i), astReg->SEQ[i]);
691N/A
691N/A /* Save CR */
691N/A for (i=0; i<25; i++)
691N/A GetIndexReg(CRTC_PORT, (UCHAR) (i), astReg->CRTC[i]);
691N/A
691N/A /* Save GR */
691N/A for (i=0; i<9; i++)
691N/A GetIndexReg(GR_PORT, (UCHAR) (i), astReg->GR[i]);
691N/A
691N/A /* Save AR */
1295N/A jReg = GetReg(INPUT_STATUS1_READ);
691N/A for (i=0; i<20; i++)
691N/A GetIndexReg(AR_PORT_WRITE, (UCHAR) (i), astReg->AR[i]);
1295N/A jReg = GetReg(INPUT_STATUS1_READ);
691N/A SetReg (AR_PORT_WRITE, 0x20); /* set POS */
691N/A
691N/A /* Save DAC */
691N/A for (i=0; i<256; i++)
691N/A VGA_GET_PALETTE_INDEX (i, astReg->DAC[i][0], astReg->DAC[i][1], astReg->DAC[i][2]);
691N/A}
691N/A
691N/A
691N/Avoid
691N/AASTRestoreHW(ScrnInfoPtr pScrn)
691N/A{
1265N/A ASTRecPtr pAST = ASTPTR(pScrn);
691N/A ASTRegPtr astReg;
691N/A int i, icount=0;
691N/A UCHAR jReg;
691N/A
692N/A astReg = &pAST->SavedReg;
692N/A
691N/A /* Restore Misc */
691N/A SetReg(MISC_PORT_WRITE, astReg->MISC);
691N/A
691N/A /* Restore SR */
691N/A for (i=0; i<4; i++)
691N/A SetIndexReg(SEQ_PORT, (UCHAR) (i), astReg->SEQ[i]);
691N/A
691N/A /* Restore CR */
691N/A SetIndexRegMask(CRTC_PORT,0x11, 0x7F, 0x00);
691N/A for (i=0; i<25; i++)
691N/A SetIndexReg(CRTC_PORT, (UCHAR) (i), astReg->CRTC[i]);
691N/A
691N/A /* Restore GR */
691N/A for (i=0; i<9; i++)
691N/A SetIndexReg(GR_PORT, (UCHAR) (i), astReg->GR[i]);
691N/A
691N/A /* Restore AR */
1295N/A jReg = GetReg(INPUT_STATUS1_READ);
691N/A for (i=0; i<20; i++)
691N/A {
691N/A SetReg(AR_PORT_WRITE, (UCHAR) i);
691N/A SetReg(AR_PORT_WRITE, astReg->AR[i]);
691N/A }
691N/A SetReg(AR_PORT_WRITE, 0x14);
691N/A SetReg(AR_PORT_WRITE, 0x00);
691N/A
1295N/A jReg = GetReg(INPUT_STATUS1_READ);
691N/A SetReg (AR_PORT_WRITE, 0x20); /* set POS */
691N/A
691N/A /* Restore DAC */
691N/A for (i=0; i<256; i++)
691N/A VGA_LOAD_PALETTE_INDEX (i, astReg->DAC[i][0], astReg->DAC[i][1], astReg->DAC[i][2]);
691N/A}
691N/A
691N/A
691N/A#endif /* __sparc__ */