~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/kdrive/ts300/ts300.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
Import upstream version 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Id: ts300.c,v 1.1 1999/11/02 08:17:24 keithp Exp $
 
3
 *
 
4
 * Copyright � 1999 Keith Packard
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
/* $RCSId: xc/programs/Xserver/hw/kdrive/ts300/ts300.c,v 1.3 2000/02/23 20:30:14 dawes Exp $ */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
#include <kdrive-config.h>
 
28
#endif
 
29
#include "kdrive.h"
 
30
 
 
31
extern KdCardFuncs  sisFuncs;
 
32
extern KdCardFuncs  s3Funcs;
 
33
 
 
34
/*
 
35
 * Kludgy code to parse the ascii /proc/pci file as the TS300
 
36
 * is running a 2.0 kernel
 
37
 */
 
38
BOOL
 
39
HasPCI (char *name, KdCardAttr *attr)
 
40
{
 
41
    FILE    *f;
 
42
    char    line[1024];
 
43
    BOOL    waiting;
 
44
    BOOL    found = FALSE;
 
45
    char    *mem;
 
46
 
 
47
    f = fopen ("/proc/pci", "r");
 
48
    if (!f)
 
49
        return FALSE;
 
50
    waiting = FALSE;
 
51
    attr->naddr = 0;
 
52
    while (fgets (line, sizeof (line), f))
 
53
    {
 
54
        if (waiting)
 
55
        {
 
56
            
 
57
            if (mem = strstr (line, "memory at "))
 
58
            {
 
59
                mem += strlen ("memory at ");
 
60
                attr->address[attr->naddr++] = strtoul (mem, NULL, 0);
 
61
                found = TRUE;
 
62
            }
 
63
            else if (mem = strstr (line, "I/O at "))
 
64
            {
 
65
                mem += strlen ("I/O at ");
 
66
                attr->io = strtoul (mem, NULL, 0);
 
67
                found = TRUE;
 
68
            }
 
69
            else if (strstr (line, "Bus") && strstr (line, "device") &&
 
70
                strstr (line, "function"))
 
71
                break;
 
72
        }
 
73
        else if (strstr (line, "VGA compatible controller"))
 
74
        {
 
75
            if (strstr (line, name))
 
76
                waiting = TRUE;
 
77
        }
 
78
    }
 
79
    fclose (f);
 
80
    return found;
 
81
}
 
82
 
 
83
typedef struct _PCICard {
 
84
    char        *user;
 
85
    char        *name;
 
86
    KdCardFuncs *funcs;
 
87
} PCICard;
 
88
 
 
89
PCICard PCICards[] = {
 
90
    "sis",  "Silicon Integrated Systems",   &sisFuncs,
 
91
    "s3",   "S3 Inc.",                      &s3Funcs,
 
92
};
 
93
 
 
94
#define NUM_PCI_CARDS   (sizeof (PCICards) / sizeof (PCICards[0]))
 
95
    
 
96
void
 
97
InitCard (char *name)
 
98
{
 
99
    KdCardInfo  *card;
 
100
    CARD32      fb;
 
101
    int         i;
 
102
    KdCardAttr  attr;
 
103
    
 
104
    for (i = 0; i < NUM_PCI_CARDS; i++)
 
105
    {
 
106
        if (!name || !strcmp (name, PCICards[i].user))
 
107
        {
 
108
            if (HasPCI (PCICards[i].name, &attr))
 
109
            {
 
110
                KdCardInfoAdd (PCICards[i].funcs, &attr, 0);
 
111
                return;
 
112
            }
 
113
        }
 
114
    }
 
115
}
 
116
 
 
117
void
 
118
InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv)
 
119
{
 
120
    KdInitOutput (pScreenInfo, argc, argv);
 
121
}
 
122
 
 
123
void
 
124
InitInput (int argc, char **argv)
 
125
{
 
126
    KdInitInput (&LinuxMouseFuncs, &LinuxKeyboardFuncs);
 
127
}
 
128
 
 
129
void
 
130
ddxUseMsg (void)
 
131
{
 
132
    KdUseMsg();
 
133
}
 
134
 
 
135
int
 
136
ddxProcessArgument (int argc, char **argv, int i)
 
137
{
 
138
    return KdProcessArgument (argc, argv, i);
 
139
}