xserver-multidpi/hw/xfree86/common/xf86sbusBus.c
Dave Airlie 1f0e8bd5eb api: rework the X server driver API to avoid global arrays.
This is a squash merge containing all the API changes, as
well as the video ABI bump.

Its been squashed to make bisection easier.

Full patch log below:

commit b202738bbf0c5a1c1172767119c2c71f1e7f8070
Author: Aaron Plattner <aplattner@nvidia.com>
Date:   Mon May 14 15:16:11 2012 -0700

    xfree86: Bump video ABI to 13.0

    The ABI was broken by changes to convert from screen index numbers to ScreenPtr
    / ScrnInfoPtr in various structures and function signatures.

    Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Dave Airlie <airlied@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 3d5f7d9f8d408bcad3f83277d255f25d3b0edbf3
Author: Dave Airlie <airlied@redhat.com>
Date:   Thu May 24 10:56:57 2012 +0100

    xf86: xf86ClearEntityListForScreen should take a pScrn

    When adding GPU screens this make life easier.

    (also fix comment, as pointed out by Alan)

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit afee8b5ab4501597ecc1ade34124d7ca227ab055
Author: Dave Airlie <airlied@redhat.com>
Date:   Thu May 24 07:07:32 2012 +0100

    xf86i2c: add pscrn for drivers to use

    This just adds a pScrn pointer into the struct for the drivers to use
    instead of scrnIndex. Mostly scrnIndex is used for logging, but some
    drivers use it to lookup xf86Screens, so let them stash a pScrn instead.

    Removing the scrnIndex is a bit more involved and I'm not sure its worth
    the effort. Doing i2c in the X server is legacy code as far as I'm concerned.

    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit ea5092f1f679691d187f1eee9427e6057beec56e
Author: Dave Airlie <airlied@redhat.com>
Date:   Wed May 23 19:25:20 2012 +0100

    dix/gc: consolidate GC object creation in one place

    The standard GC create and scratch GC create were 90% the same really,
    and I have a need in the future for creating GC objects without the
    other bits, so wanted to avoid a third copy.

    Reviewed-by: Keith Packard <keithp@keithp.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 3d91482ea9b4883e64e496f2768168e0ffa21ba1
Author: Dave Airlie <airlied@redhat.com>
Date:   Wed May 23 10:24:06 2012 +0100

    xf86: add a define to denote the new non-index interfaces are being used

    This can be used by drivers to provide compatible APIs.

    Reviewed-by: Keith Packard <keithp@keithp.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 37c3ae3e6cd4f3dedc72f371096d6743f8f99df3
Author: Dave Airlie <airlied@redhat.com>
Date:   Wed May 23 15:09:12 2012 +0100

    dix: make Create/Free scratch pixmaps take a ScreenPtr

    While technically an API/ABI change I doubt anyone uses it,
    but it helps in splitting screens up.

    Reviewed-by: Keith Packard <keithp@keithp.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 75f2062a3fe94f04764ecc7d2ff2fbbeccb9da60
Author: Dave Airlie <airlied@redhat.com>
Date:   Wed May 23 14:57:55 2012 +0100

    xf86/xv: remove scrnIndexfrom xf86FindXvOptions.

    Move this interface to taking an ScrnInfoPtr.

    Reviewed-by: Keith Packard <keithp@keithp.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit f80c2374f40ea7b2ee0556e2e76cc07406f3d843
Author: Dave Airlie <airlied@redhat.com>
Date:   Wed May 23 14:53:59 2012 +0100

    xf86: make xf86DeleteScreen take a ScrnInfoPtr (v2)

    stop passing indices into this function.

    v2: drop flags argument.

    Reviewed-by: Keith Packard <keithp@keithp.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 58824e414f35682435f15bfe6c4b656bd90b9235
Author: Dave Airlie <airlied@redhat.com>
Date:   Wed May 23 14:48:09 2012 +0100

    xf86: fix xf86IsScreenPrimary interface to take a pScrn (API/ABI)

    Reviewed-by: Keith Packard <keithp@keithp.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 6b4fc1f9d391bcdf7ca288766e49bce60f4635cd
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 14:18:59 2012 +0100

    xserver: convert block/wakeup handlers to passing ScreenPtr (ABI/API) (v2)

    Instead of passing an index, pass the actual ScreenPtr. This allows
    more moving towards not abusing xf86Screens + screenInfo.

    v2: drop the blockData/wakeupData args as per ajax's suggestion.,
    fix docs.

    Reviewed-by: Keith Packard <keithp@keithp.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 790d003de20fb47674420a24dadd92412d78620d
Author: Dave Airlie <airlied@gmail.com>
Date:   Wed Apr 11 09:53:14 2012 +0100

    xf86/common: remove some more pScrn->pScreen uses

    remove some more conversions that appeared after api cleanups.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit aac85e18d1dd093f2cad6bd29375e40bd7af0b8f
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 16:34:53 2012 +0100

    ddc: change API to take ScrnInfoPtr (v2)

    This removes all xf86Screens usage from ddc code,
    it modifies the API for some functions to avoid taking indices.

    v2: address Alan's comments about dropping DDC2Init parameter.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit fe3f57b6eaf6860a33876a54f9439f69578f03a5
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 16:31:26 2012 +0100

    vbe: don't use index for VBEInterpretPanelID (API)

    Remove use of xf86screens from vbe module.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit abf1965f4ed91529036d3fdb470d6a3ce6f29675
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 16:25:11 2012 +0100

    int10/vbe: don't use xf86Screens. (ABI) (v3)

    Pass the ScrnInfoPtr instead of the index in the int10 struct.

    This saves us using it to dereference xf86Screens.

    v2: address Alan's comment to fix struct alignment.

    v3: squash in all the int10 fixes, test the vm86 code builds,
    after comments by Keith.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 23cca612b4fb5efc33683c7624b803b457387e3d
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 15:30:18 2012 +0100

    xserver: drop index argument to ScreenInit (ABI/API) (v2)

    This drops the index argument, its the same as pScreen->myNum,
    and its the last major index abuse I can find.

    v2: address Alan's review - update docs, fix xwin/xnest/darwin

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 40d360e2d7e832407f3ed64e3a02c27ecc89a960
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 15:23:01 2012 +0100

    xf86: migrate PointerMoved from index to ScrnInfoPtr (ABI/API)

    This migrates PointerMoved from an index to ScrnInfoPtr.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit aa60a2f38679d0eeb979a9c2648c9bc771409bf9
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 15:20:46 2012 +0100

    xf86: migrate PMEvent to a ScrnInfoPtr (ABI/API)

    This migrates the PMEvent from index to ScrnInfoPtr.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit d3f28ef44371ed4a039ffc5dd7eb6408d1269ba2
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 15:18:30 2012 +0100

    xf86: migrate SetDGAMode from index to ScrnInfoPtr (ABI/API)

    This migrates the SetDGAMode callback from an index to ScrnInfoPtr.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit baf5e4818a74f2b68c3dfdcc56f54322351039a0
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 15:14:11 2012 +0100

    xf86: migrate ChangeGamma from index to ScrnInfoPtr (ABI/API) (v2)

    This migrates the ChangeGamma interface to avoid passing a index.

    v2: fix xf86RandR12.c + xf86cmap.c call

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 51e5f90ada929d6b23176090badbb42fdb3fa550
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 15:11:09 2012 +0100

    xf86/exa: migrate index to screen types for EnableDisableFBAccess (ABI/API)

    The EXA interface migrates to ScreenPtr,
    and the xf86 interface migrated to ScrnInfoPtr.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 94f1f21d17e86f96d4a54292a399160950087675
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 15:02:11 2012 +0100

    xf86: migrate ValidMode callback to ScrnInfoPtr (ABI/API)

    This migrates the ValidMode to passing a ScrnInfoPtr instead
    of an index.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 3f8f18198fed4f39ec805b508a3482e91eea26b2
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 14:59:46 2012 +0100

    xf86: migrate SwitchMode to taking ScrnInfoPtr (ABI/API) (v2)

    This migrate the SwitchMode interface to take a ScrnInfoPtr
    instead of an index.

    v2: drop flags.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit d06a038a5c49328ab3a8d969d24f9fcd22c63202
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 14:50:37 2012 +0100

    xf86: move AdjustFrame to passing ScrnInfoPtr (ABI/API) (v2)

    This converts AdjustFrame code paths to passing a ScrnInfoPtr
    instead of an integer index.

    v2: drop flags args.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 53d2f8608ffd4090d08e7d5cf2e92fb954959b90
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 14:41:27 2012 +0100

    xf86: modify FreeScreen callback to take pScrn instead of index. (ABI/API) (v2)

    Another index->pScrn conversion.

    v2: drop flags arg.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 60db37c0b247052e0f5c54b1921fe58a3609c2e3
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 14:35:41 2012 +0100

    xf86: change EnterVT/LeaveVT to take a ScrnInfoPtr (ABI/API break) (v2)

    This modifies the EnterVT/LeaveVT interfaces to take a ScrnInfoPtr
    instead of an index into xf86Screens. This allows dropping more
    public dereferences of the xf86Screens and screenInfo.

    v2: drop flags args as suggested by Keith, fix docs.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

commit 06729dbbc804a20242e6499f446acb5d94023c3c
Author: Dave Airlie <airlied@gmail.com>
Date:   Tue Apr 10 14:04:59 2012 +0100

    xserver: remove index from CloseScreen (API/ABI breakage)

    This drops the index from the CloseScreen callback,
    its always been useless really, since the pScreen contains it.

    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Acked-by: Aaron Plattner <aplattner@nvidia.com>
    Reviewed-by: Adam Jackson <ajax@redhat.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-06-05 13:22:18 +01:00

756 lines
23 KiB
C

/*
* SBUS bus-specific code.
*
* Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
*
* 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
* JAKUB JELINEK 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_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <unistd.h>
#include <X11/X.h>
#include "os.h"
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"
#include "xf86cmap.h"
#include "xf86Bus.h"
#include "xf86sbusBus.h"
#include "xf86Sbus.h"
Bool sbusSlotClaimed = FALSE;
static int xf86nSbusInfo;
static void
CheckSbusDevice(const char *device, int fbNum)
{
int fd, i;
struct fbgattr fbattr;
sbusDevicePtr psdp;
fd = open(device, O_RDONLY, 0);
if (fd < 0)
return;
memset(&fbattr, 0, sizeof(fbattr));
if (ioctl(fd, FBIOGATTR, &fbattr) < 0) {
if (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0) {
close(fd);
return;
}
}
close(fd);
for (i = 0; sbusDeviceTable[i].devId; i++)
if (sbusDeviceTable[i].fbType == fbattr.fbtype.fb_type)
break;
if (!sbusDeviceTable[i].devId)
return;
xf86SbusInfo =
xnfrealloc(xf86SbusInfo, sizeof(psdp) * (++xf86nSbusInfo + 1));
xf86SbusInfo[xf86nSbusInfo] = NULL;
xf86SbusInfo[xf86nSbusInfo - 1] = psdp = xnfcalloc(sizeof(sbusDevice), 1);
psdp->devId = sbusDeviceTable[i].devId;
psdp->fbNum = fbNum;
psdp->device = xnfstrdup(device);
psdp->width = fbattr.fbtype.fb_width;
psdp->height = fbattr.fbtype.fb_height;
psdp->fd = -1;
}
void
xf86SbusProbe(void)
{
int i, useProm = 0;
char fbDevName[32];
sbusDevicePtr psdp, *psdpp;
xf86SbusInfo = malloc(sizeof(psdp));
*xf86SbusInfo = NULL;
for (i = 0; i < 32; i++) {
snprintf(fbDevName, sizeof(fbDevName), "/dev/fb%d", i);
CheckSbusDevice(fbDevName, i);
}
if (sparcPromInit() >= 0) {
useProm = 1;
sparcPromAssignNodes();
}
for (psdpp = xf86SbusInfo; (psdp = *psdpp); psdpp++) {
for (i = 0; sbusDeviceTable[i].devId; i++)
if (sbusDeviceTable[i].devId == psdp->devId)
psdp->descr = sbusDeviceTable[i].descr;
/*
* If we can use PROM information and found the PROM node for this
* device, we can tell more about the card.
*/
if (useProm && psdp->node.node) {
char *prop, *promPath;
int len, chiprev, vmsize;
switch (psdp->devId) {
case SBUS_DEVICE_MGX:
prop = sparcPromGetProperty(&psdp->node, "fb_size", &len);
if (prop && len == 4 && *(int *) prop == 0x400000)
psdp->descr = "Quantum 3D MGXplus with 4M VRAM";
break;
case SBUS_DEVICE_CG6:
chiprev = 0;
vmsize = 0;
prop = sparcPromGetProperty(&psdp->node, "chiprev", &len);
if (prop && len == 4)
chiprev = *(int *) prop;
prop = sparcPromGetProperty(&psdp->node, "vmsize", &len);
if (prop && len == 4)
vmsize = *(int *) prop;
switch (chiprev) {
case 1:
case 2:
case 3:
case 4:
psdp->descr = "Sun Double width GX";
break;
case 5:
case 6:
case 7:
case 8:
case 9:
psdp->descr = "Sun Single width GX";
break;
case 11:
switch (vmsize) {
case 2:
psdp->descr = "Sun Turbo GX with 1M VSIMM";
break;
case 4:
psdp->descr = "Sun Turbo GX Plus";
break;
default:
psdp->descr = "Sun Turbo GX";
break;
}
}
break;
case SBUS_DEVICE_CG14:
prop = sparcPromGetProperty(&psdp->node, "reg", &len);
vmsize = 0;
if (prop && !(len % 12) && len > 0)
vmsize = *(int *) (prop + len - 4);
switch (vmsize) {
case 0x400000:
psdp->descr = "Sun SX with 4M VSIMM";
break;
case 0x800000:
psdp->descr = "Sun SX with 8M VSIMM";
break;
}
break;
case SBUS_DEVICE_LEO:
prop = sparcPromGetProperty(&psdp->node, "model", &len);
if (prop && len > 0 && !strstr(prop, "501-2503"))
psdp->descr = "Sun Turbo ZX";
break;
case SBUS_DEVICE_TCX:
if (sparcPromGetBool(&psdp->node, "tcx-8-bit"))
psdp->descr = "Sun TCX (8bit)";
else
psdp->descr = "Sun TCX (S24)";
break;
case SBUS_DEVICE_FFB:
prop = sparcPromGetProperty(&psdp->node, "name", &len);
chiprev = 0;
prop = sparcPromGetProperty(&psdp->node, "board_type", &len);
if (prop && len == 4)
chiprev = *(int *) prop;
if (strstr(prop, "afb")) {
if (chiprev == 3)
psdp->descr = "Sun|Elite3D-M6 Horizontal";
}
else {
switch (chiprev) {
case 0x08:
psdp->descr = "Sun FFB 67MHz Creator";
break;
case 0x0b:
psdp->descr = "Sun FFB 67MHz Creator 3D";
break;
case 0x1b:
psdp->descr = "Sun FFB 75MHz Creator 3D";
break;
case 0x20:
case 0x28:
psdp->descr = "Sun FFB2 Vertical Creator";
break;
case 0x23:
case 0x2b:
psdp->descr = "Sun FFB2 Vertical Creator 3D";
break;
case 0x30:
psdp->descr = "Sun FFB2+ Vertical Creator";
break;
case 0x33:
psdp->descr = "Sun FFB2+ Vertical Creator 3D";
break;
case 0x40:
case 0x48:
psdp->descr = "Sun FFB2 Horizontal Creator";
break;
case 0x43:
case 0x4b:
psdp->descr = "Sun FFB2 Horizontal Creator 3D";
break;
}
}
break;
}
xf86Msg(X_PROBED, "SBUS:(0x%08x) %s", psdp->node.node, psdp->descr);
promPath = sparcPromNode2Pathname(&psdp->node);
if (promPath) {
xf86ErrorF(" at %s", promPath);
free(promPath);
}
}
else
xf86Msg(X_PROBED, "SBUS: %s", psdp->descr);
xf86ErrorF("\n");
}
if (useProm)
sparcPromClose();
}
/*
* Parse a BUS ID string, and return the SBUS bus parameters if it was
* in the correct format for a SBUS bus id.
*/
Bool
xf86ParseSbusBusString(const char *busID, int *fbNum)
{
/*
* The format is assumed to be one of:
* "fbN", e.g. "fb1", which means the device corresponding to /dev/fbN
* "nameN", e.g. "cgsix0", which means Nth instance of card NAME
* "/prompath", e.g. "/sbus@0,10001000/cgsix@3,0" which is PROM pathname
* to the device.
*/
const char *id;
int i, len;
if (StringToBusType(busID, &id) != BUS_SBUS)
return FALSE;
if (*id != '/') {
if (!strncmp(id, "fb", 2)) {
if (!isdigit(id[2]))
return FALSE;
*fbNum = atoi(id + 2);
return TRUE;
}
else {
sbusDevicePtr *psdpp;
int devId;
for (i = 0, len = 0; sbusDeviceTable[i].devId; i++) {
len = strlen(sbusDeviceTable[i].promName);
if (!strncmp(sbusDeviceTable[i].promName, id, len)
&& isdigit(id[len]))
break;
}
devId = sbusDeviceTable[i].devId;
if (!devId)
return FALSE;
i = atoi(id + len);
for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) {
if ((*psdpp)->devId != devId)
continue;
if (!i) {
*fbNum = (*psdpp)->fbNum;
return TRUE;
}
i--;
}
}
return FALSE;
}
if (sparcPromInit() >= 0) {
i = sparcPromPathname2Node(id);
sparcPromClose();
if (i) {
sbusDevicePtr *psdpp;
for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) {
if ((*psdpp)->node.node == i) {
*fbNum = (*psdpp)->fbNum;
return TRUE;
}
}
}
}
return FALSE;
}
/*
* Compare a BUS ID string with a SBUS bus id. Return TRUE if they match.
*/
Bool
xf86CompareSbusBusString(const char *busID, int fbNum)
{
int iFbNum;
if (xf86ParseSbusBusString(busID, &iFbNum)) {
return fbNum == iFbNum;
}
else {
return FALSE;
}
}
/*
* Check if the slot requested is free. If it is already in use, return FALSE.
*/
Bool
xf86CheckSbusSlot(int fbNum)
{
int i;
EntityPtr p;
for (i = 0; i < xf86NumEntities; i++) {
p = xf86Entities[i];
/* Check if this SBUS slot is taken */
if (p->bus.type == BUS_SBUS && p->bus.id.sbus.fbNum == fbNum)
return FALSE;
}
return TRUE;
}
/*
* If the slot requested is already in use, return -1.
* Otherwise, claim the slot for the screen requesting it.
*/
int
xf86ClaimSbusSlot(sbusDevicePtr psdp, DriverPtr drvp, GDevPtr dev, Bool active)
{
EntityPtr p = NULL;
int num;
if (xf86CheckSbusSlot(psdp->fbNum)) {
num = xf86AllocateEntity();
p = xf86Entities[num];
p->driver = drvp;
p->chipset = -1;
p->bus.type = BUS_SBUS;
xf86AddDevToEntity(num, dev);
p->bus.id.sbus.fbNum = psdp->fbNum;
p->active = active;
p->inUse = FALSE;
sbusSlotClaimed = TRUE;
return num;
}
else
return -1;
}
int
xf86MatchSbusInstances(const char *driverName, int sbusDevId,
GDevPtr * devList, int numDevs, DriverPtr drvp,
int **foundEntities)
{
int i, j;
sbusDevicePtr psdp, *psdpp;
int numClaimedInstances = 0;
int allocatedInstances = 0;
int numFound = 0;
GDevPtr devBus = NULL;
GDevPtr dev = NULL;
int *retEntities = NULL;
int useProm = 0;
struct Inst {
sbusDevicePtr sbus;
GDevPtr dev;
Bool claimed; /* BusID matches with a device section */
} *instances = NULL;
*foundEntities = NULL;
for (psdpp = xf86SbusInfo, psdp = *psdpp; psdp; psdp = *++psdpp) {
if (psdp->devId != sbusDevId)
continue;
if (psdp->fd == -2)
continue;
++allocatedInstances;
instances = xnfrealloc(instances,
allocatedInstances * sizeof(struct Inst));
instances[allocatedInstances - 1].sbus = psdp;
instances[allocatedInstances - 1].dev = NULL;
instances[allocatedInstances - 1].claimed = FALSE;
numFound++;
}
/*
* This may be debatable, but if no SBUS devices with a matching vendor
* type is found, return zero now. It is probably not desirable to
* allow the config file to override this.
*/
if (allocatedInstances <= 0) {
free(instances);
return 0;
}
if (sparcPromInit() >= 0)
useProm = 1;
if (xf86DoConfigure && xf86DoConfigurePass1) {
GDevPtr pGDev;
int actualcards = 0;
for (i = 0; i < allocatedInstances; i++) {
actualcards++;
pGDev = xf86AddBusDeviceToConfigure(drvp->driverName, BUS_SBUS,
instances[i].sbus, -1);
if (pGDev) {
/*
* XF86Match???Instances() treat chipID and chipRev as
* overrides, so clobber them here.
*/
pGDev->chipID = pGDev->chipRev = -1;
}
}
free(instances);
if (useProm)
sparcPromClose();
return actualcards;
}
DebugF("%s instances found: %d\n", driverName, allocatedInstances);
for (i = 0; i < allocatedInstances; i++) {
char *promPath = NULL;
psdp = instances[i].sbus;
devBus = NULL;
dev = NULL;
if (useProm && psdp->node.node)
promPath = sparcPromNode2Pathname(&psdp->node);
for (j = 0; j < numDevs; j++) {
if (devList[j]->busID && *devList[j]->busID) {
if (xf86CompareSbusBusString(devList[j]->busID, psdp->fbNum)) {
if (devBus)
xf86MsgVerb(X_WARNING, 0,
"%s: More than one matching Device section for "
"instance (BusID: %s) found: %s\n",
driverName, devList[j]->identifier,
devList[j]->busID);
else
devBus = devList[j];
}
}
else {
if (!dev && !devBus) {
if (promPath)
xf86Msg(X_PROBED,
"Assigning device section with no busID to SBUS:%s\n",
promPath);
else
xf86Msg(X_PROBED,
"Assigning device section with no busID to SBUS:fb%d\n",
psdp->fbNum);
dev = devList[j];
}
else
xf86MsgVerb(X_WARNING, 0,
"%s: More than one matching Device section "
"found: %s\n", driverName,
devList[j]->identifier);
}
}
if (devBus)
dev = devBus; /* busID preferred */
if (!dev && psdp->fd != -2) {
if (promPath) {
xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section "
"for instance (BusID SBUS:%s) found\n",
driverName, promPath);
}
else
xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section "
"for instance (BusID SBUS:fb%d) found\n",
driverName, psdp->fbNum);
}
else if (dev) {
numClaimedInstances++;
instances[i].claimed = TRUE;
instances[i].dev = dev;
}
free(promPath);
}
DebugF("%s instances found: %d\n", driverName, numClaimedInstances);
/*
* Of the claimed instances, check that another driver hasn't already
* claimed its slot.
*/
numFound = 0;
for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) {
if (!instances[i].claimed)
continue;
psdp = instances[i].sbus;
if (!xf86CheckSbusSlot(psdp->fbNum))
continue;
DebugF("%s: card at fb%d %08x is claimed by a Device section\n",
driverName, psdp->fbNum, psdp->node.node);
/* Allocate an entry in the lists to be returned */
numFound++;
retEntities = xnfrealloc(retEntities, numFound * sizeof(int));
retEntities[numFound - 1]
= xf86ClaimSbusSlot(psdp, drvp, instances[i].dev,
instances[i].dev->active ? TRUE : FALSE);
}
free(instances);
if (numFound > 0) {
*foundEntities = retEntities;
}
if (useProm)
sparcPromClose();
return numFound;
}
/*
* xf86GetSbusInfoForEntity() -- Get the sbusDevicePtr of entity.
*/
sbusDevicePtr
xf86GetSbusInfoForEntity(int entityIndex)
{
sbusDevicePtr *psdpp;
EntityPtr p = xf86Entities[entityIndex];
if (entityIndex >= xf86NumEntities || p->bus.type != BUS_SBUS)
return NULL;
for (psdpp = xf86SbusInfo; *psdpp != NULL; psdpp++) {
if (p->bus.id.sbus.fbNum == (*psdpp)->fbNum)
return *psdpp;
}
return NULL;
}
int
xf86GetEntityForSbusInfo(sbusDevicePtr psdp)
{
int i;
for (i = 0; i < xf86NumEntities; i++) {
EntityPtr p = xf86Entities[i];
if (p->bus.type != BUS_SBUS)
continue;
if (p->bus.id.sbus.fbNum == psdp->fbNum)
return i;
}
return -1;
}
void
xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, sbusDevicePtr psdp)
{
DisplayModePtr mode;
mode = xnfcalloc(sizeof(DisplayModeRec), 1);
mode->name = "current";
mode->next = mode;
mode->prev = mode;
mode->type = M_T_BUILTIN;
mode->Clock = 100000000;
mode->HDisplay = psdp->width;
mode->HSyncStart = psdp->width;
mode->HSyncEnd = psdp->width;
mode->HTotal = psdp->width;
mode->VDisplay = psdp->height;
mode->VSyncStart = psdp->height;
mode->VSyncEnd = psdp->height;
mode->VTotal = psdp->height;
mode->SynthClock = mode->Clock;
mode->CrtcHDisplay = mode->HDisplay;
mode->CrtcHSyncStart = mode->HSyncStart;
mode->CrtcHSyncEnd = mode->HSyncEnd;
mode->CrtcHTotal = mode->HTotal;
mode->CrtcVDisplay = mode->VDisplay;
mode->CrtcVSyncStart = mode->VSyncStart;
mode->CrtcVSyncEnd = mode->VSyncEnd;
mode->CrtcVTotal = mode->VTotal;
mode->CrtcHAdjusted = FALSE;
mode->CrtcVAdjusted = FALSE;
pScrn->modes = mode;
pScrn->virtualX = psdp->width;
pScrn->virtualY = psdp->height;
}
static DevPrivateKeyRec sbusPaletteKeyRec;
#define sbusPaletteKey (&sbusPaletteKeyRec)
typedef struct _sbusCmap {
sbusDevicePtr psdp;
CloseScreenProcPtr CloseScreen;
Bool origCmapValid;
unsigned char origRed[16];
unsigned char origGreen[16];
unsigned char origBlue[16];
} sbusCmapRec, *sbusCmapPtr;
#define SBUSCMAPPTR(pScreen) ((sbusCmapPtr) \
dixLookupPrivate(&(pScreen)->devPrivates, sbusPaletteKey))
static void
xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
LOCO * colors, VisualPtr pVisual)
{
int i, index;
sbusCmapPtr cmap;
struct fbcmap fbcmap;
unsigned char *data = malloc(numColors * 3);
cmap = SBUSCMAPPTR(pScrn->pScreen);
if (!cmap)
return;
fbcmap.count = 0;
fbcmap.index = indices[0];
fbcmap.red = data;
fbcmap.green = data + numColors;
fbcmap.blue = fbcmap.green + numColors;
for (i = 0; i < numColors; i++) {
index = indices[i];
if (fbcmap.count && index != fbcmap.index + fbcmap.count) {
ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap);
fbcmap.count = 0;
fbcmap.index = index;
}
fbcmap.red[fbcmap.count] = colors[index].red;
fbcmap.green[fbcmap.count] = colors[index].green;
fbcmap.blue[fbcmap.count++] = colors[index].blue;
}
ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap);
free(data);
}
static Bool
xf86SbusCmapCloseScreen(ScreenPtr pScreen)
{
sbusCmapPtr cmap;
struct fbcmap fbcmap;
cmap = SBUSCMAPPTR(pScreen);
if (cmap->origCmapValid) {
fbcmap.index = 0;
fbcmap.count = 16;
fbcmap.red = cmap->origRed;
fbcmap.green = cmap->origGreen;
fbcmap.blue = cmap->origBlue;
ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap);
}
pScreen->CloseScreen = cmap->CloseScreen;
free(cmap);
return (*pScreen->CloseScreen) (pScreen);
}
Bool
xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp)
{
sbusCmapPtr cmap;
struct fbcmap fbcmap;
unsigned char data[2];
if (!dixRegisterPrivateKey(sbusPaletteKey, PRIVATE_SCREEN, 0))
FatalError("Cannot register sbus private key");
cmap = xnfcalloc(1, sizeof(sbusCmapRec));
dixSetPrivate(&pScreen->devPrivates, sbusPaletteKey, cmap);
cmap->psdp = psdp;
fbcmap.index = 0;
fbcmap.count = 16;
fbcmap.red = cmap->origRed;
fbcmap.green = cmap->origGreen;
fbcmap.blue = cmap->origBlue;
if (ioctl(psdp->fd, FBIOGETCMAP, &fbcmap) >= 0)
cmap->origCmapValid = TRUE;
fbcmap.index = 0;
fbcmap.count = 2;
fbcmap.red = data;
fbcmap.green = data;
fbcmap.blue = data;
if (pScreen->whitePixel == 0) {
data[0] = 255;
data[1] = 0;
}
else {
data[0] = 0;
data[1] = 255;
}
ioctl(psdp->fd, FBIOPUTCMAP, &fbcmap);
cmap->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = xf86SbusCmapCloseScreen;
return xf86HandleColormaps(pScreen, 256, 8,
xf86SbusCmapLoadPalette, NULL, 0);
}
Bool
xf86SbusConfigure(void *busData, sbusDevicePtr sBus)
{
if (sBus && sBus->fbNum == ((sbusDevicePtr) busData)->fbNum)
return 0;
return 1;
}
void
xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec * GDev)
{
char *promPath = NULL;
sBus = (sbusDevicePtr) busData;
GDev->identifier = sBus->descr;
if (sparcPromInit() >= 0) {
promPath = sparcPromNode2Pathname(&sBus->node);
sparcPromClose();
}
if (promPath) {
XNFasprintf(&GDev->busID, "SBUS:%s", promPath);
free(promPath);
}
else {
XNFasprintf(&GDev->busID, "SBUS:fb%d", sBus->fbNum);
}
}