132b578d3Smrg/*
232b578d3Smrg * Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
332b578d3Smrg *
432b578d3Smrg * Permission to use, copy, modify, distribute, and sell this software and its
532b578d3Smrg * documentation for any purpose is hereby granted without fee, provided that
632b578d3Smrg * the above copyright notice appear in all copies and that both that copyright
732b578d3Smrg * notice and this permission notice appear in supporting documentation, and
832b578d3Smrg * that the name of Marc Aurele La France not be used in advertising or
932b578d3Smrg * publicity pertaining to distribution of the software without specific,
1032b578d3Smrg * written prior permission.  Marc Aurele La France makes no representations
1132b578d3Smrg * about the suitability of this software for any purpose.  It is provided
1232b578d3Smrg * "as-is" without express or implied warranty.
1332b578d3Smrg *
1432b578d3Smrg * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1532b578d3Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO
1632b578d3Smrg * EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1732b578d3Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1832b578d3Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1932b578d3Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2032b578d3Smrg * PERFORMANCE OF THIS SOFTWARE.
2132b578d3Smrg */
2232b578d3Smrg
2332b578d3Smrg#ifdef HAVE_CONFIG_H
2432b578d3Smrg#include "config.h"
2532b578d3Smrg#endif
2632b578d3Smrg
2732b578d3Smrg#include <string.h>
2832b578d3Smrg
2932b578d3Smrg#include "ati.h"
3032b578d3Smrg#include "atibus.h"
3132b578d3Smrg#include "atichip.h"
3232b578d3Smrg#include "atimach64io.h"
3332b578d3Smrg#include "atistruct.h"
3432b578d3Smrg
3532b578d3Smrg/*
3632b578d3Smrg * Definitions related to an adapter's system bus interface.
3732b578d3Smrg */
3832b578d3Smrg
3932b578d3Smrgconst char *ATIBusNames[] =
4032b578d3Smrg{
4132b578d3Smrg    "PCI",
4232b578d3Smrg    "AGP"
4332b578d3Smrg};
4432b578d3Smrg
4532b578d3Smrg/*
4632b578d3Smrg * ATIClaimResources --
4732b578d3Smrg *
4832b578d3Smrg * This function registers most of the bus resources used by an adapter.  The
4932b578d3Smrg * exceptions are PCI-configured resources and non-PCI non-AGP linear
5032b578d3Smrg * apertures, both of which are registered by ATIPreInit().  This function also
5132b578d3Smrg * attempts to register unshareable resources for inactive PCI adapters,
5232b578d3Smrg * whether or not they are relocatable.
5332b578d3Smrg */
5432b578d3Smrgstatic void
5532b578d3SmrgATIClaimResources
5632b578d3Smrg(
5732b578d3Smrg    ATIPtr pATI,
5832b578d3Smrg    Bool   Active
5932b578d3Smrg)
6032b578d3Smrg{
6132b578d3Smrg
622a51b5beSmrg#ifndef XSERVER_LIBPCIACCESS
6332b578d3Smrg#ifndef AVOID_CPIO
6432b578d3Smrg
6532b578d3Smrg    resRange Resources[2] = {{0, 0, 0}, _END};
6632b578d3Smrg
6732b578d3Smrg    /* Claim VGA and VGAWonder resources */
6832b578d3Smrg    if ((pATI->VGAAdapter) && (Active))
6932b578d3Smrg    {
7032b578d3Smrg        /*
7132b578d3Smrg         * 18800-x's are the only ATI controllers that decode all ISA aliases
7232b578d3Smrg         * of VGA and VGA Wonder I/O ports.  Other x8800's do not decode >any<
7332b578d3Smrg         * VGA aliases, but do decode VGA Wonder aliases whose most significant
7432b578d3Smrg         * nibble is zero.
7532b578d3Smrg         */
7632b578d3Smrg        xf86ClaimFixedResources(resVgaShared, pATI->iEntity);
7732b578d3Smrg
7832b578d3Smrg        if (pATI->CPIO_VGAWonder)
7932b578d3Smrg        {
8032b578d3Smrg            Resources[0].type = ResShrIoSparse | ResBus;
8132b578d3Smrg            Resources[0].rBase = pATI->CPIO_VGAWonder;
8232b578d3Smrg            Resources[0].rMask = 0xF3FEU;
8332b578d3Smrg
8432b578d3Smrg            xf86ClaimFixedResources(Resources, pATI->iEntity);
8532b578d3Smrg
8632b578d3Smrg            (void)memcpy(pATI->VGAWonderResources,
8732b578d3Smrg                Resources, SizeOf(Resources));
8832b578d3Smrg        }
8932b578d3Smrg    }
9032b578d3Smrg
9132b578d3Smrg    if (!Active)
9232b578d3Smrg        return;
9332b578d3Smrg
9432b578d3Smrg    /* Claim Mach64 sparse I/O resources */
9532b578d3Smrg    if ((pATI->CPIODecoding == SPARSE_IO))
9632b578d3Smrg    {
9732b578d3Smrg        Resources[0].type = ResShrIoSparse | ResBus;
9832b578d3Smrg        Resources[0].rBase = pATI->CPIOBase;
9932b578d3Smrg        Resources[0].rMask = 0x03FCU;
10032b578d3Smrg
10132b578d3Smrg        xf86ClaimFixedResources(Resources, pATI->iEntity);
10232b578d3Smrg    }
10332b578d3Smrg
10432b578d3Smrg#endif /* AVOID_CPIO */
1052a51b5beSmrg#endif
10632b578d3Smrg}
10732b578d3Smrg
10832b578d3Smrg/*
10932b578d3Smrg * ATIClaimBusSlot --
11032b578d3Smrg *
11132b578d3Smrg * Claim an adapter and register its resources.
11232b578d3Smrg */
11332b578d3Smrgint
11432b578d3SmrgATIClaimBusSlot
11532b578d3Smrg(
11632b578d3Smrg    Bool      Active,
11732b578d3Smrg    ATIPtr    pATI
11832b578d3Smrg)
11932b578d3Smrg{
12032b578d3Smrg    if (pATI->iEntity >= 0)
12132b578d3Smrg        ATIClaimResources(pATI, Active);
12232b578d3Smrg
12332b578d3Smrg    return pATI->iEntity;
12432b578d3Smrg}
125