nsc_driver.c revision 71d7fec4
1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/nsc_driver.c,v 1.4tsi Exp $ */
2/*
3 * $Workfile: nsc_driver.c $
4 * $Revision: 1.1.1.1 $
5 * $Author: mrg $
6 *
7 * File Contents: This is the main module configures the interfacing
8 *                with the X server. The individual modules will be
9 *                loaded based upon the options selected from the
10 *                XF86Config. This file also has modules for finding
11 *                supported modes, turning on the modes based on options.
12 *
13 * Project:       Nsc Xfree Frame buffer device driver.
14 *
15 */
16
17/*
18 * NSC_LIC_ALTERNATIVE_PREAMBLE
19 *
20 * Revision 1.0
21 *
22 * National Semiconductor Alternative GPL-BSD License
23 *
24 * National Semiconductor Corporation licenses this software
25 * ("Software"):
26 *
27 * National Xfree frame buffer driver
28 *
29 * under one of the two following licenses, depending on how the
30 * Software is received by the Licensee.
31 *
32 * If this Software is received as part of the Linux Framebuffer or
33 * other GPL licensed software, then the GPL license designated
34 * NSC_LIC_GPL applies to this Software; in all other circumstances
35 * then the BSD-style license designated NSC_LIC_BSD shall apply.
36 *
37 * END_NSC_LIC_ALTERNATIVE_PREAMBLE */
38
39/* NSC_LIC_BSD
40 *
41 * National Semiconductor Corporation Open Source License for
42 *
43 * National Xfree frame buffer driver
44 *
45 * (BSD License with Export Notice)
46 *
47 * Copyright (c) 1999-2001
48 * National Semiconductor Corporation.
49 * All rights reserved.
50 *
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
53 * are met:
54 *
55 *   * Redistributions of source code must retain the above copyright
56 *     notice, this list of conditions and the following disclaimer.
57 *
58 *   * Redistributions in binary form must reproduce the above
59 *     copyright notice, this list of conditions and the following
60 *     disclaimer in the documentation and/or other materials provided
61 *     with the distribution.
62 *
63 *   * Neither the name of the National Semiconductor Corporation nor
64 *     the names of its contributors may be used to endorse or promote
65 *     products derived from this software without specific prior
66 *     written permission.
67 *
68 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
69 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
70 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
71 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
72 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
73 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
74 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
75 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
76 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
77 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
78 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
79 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
80 * OF SUCH DAMAGE.
81 *
82 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
83 * YOUR JURISDICTION. It is licensee's responsibility to comply with
84 * any export regulations applicable in licensee's jurisdiction. Under
85 * CURRENT (2001) U.S. export regulations this software
86 * is eligible for export from the U.S. and can be downloaded by or
87 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
88 * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
89 * Syria, Sudan, Afghanistan and any other country to which the U.S.
90 * has embargoed goods and services.
91 *
92 * END_NSC_LIC_BSD */
93
94/* NSC_LIC_GPL
95 *
96 * National Semiconductor Corporation Gnu General Public License for
97 *
98 * National Xfree frame buffer driver
99 *
100 * (GPL License with Export Notice)
101 *
102 * Copyright (c) 1999-2001
103 * National Semiconductor Corporation.
104 * All rights reserved.
105 *
106 * Redistribution and use in source and binary forms, with or without
107 * modification, are permitted under the terms of the GNU General
108 * Public License as published by the Free Software Foundation; either
109 * version 2 of the License, or (at your option) any later version
110 *
111 * In addition to the terms of the GNU General Public License, neither
112 * the name of the National Semiconductor Corporation nor the names of
113 * its contributors may be used to endorse or promote products derived
114 * from this software without specific prior written permission.
115 *
116 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
117 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
118 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
119 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
120 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
121 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
122 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
123 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
124 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
125 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
126 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
127 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
128 * OF SUCH DAMAGE. See the GNU General Public License for more details.
129 *
130 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
131 * YOUR JURISDICTION. It is licensee's responsibility to comply with
132 * any export regulations applicable in licensee's jurisdiction. Under
133 * CURRENT (2001) U.S. export regulations this software
134 * is eligible for export from the U.S. and can be downloaded by or
135 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
136 * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
137 * Syria, Sudan, Afghanistan and any other country to which the U.S.
138 * has embargoed goods and services.
139 *
140 * You should have received a copy of the GNU General Public License
141 * along with this file; if not, write to the Free Software Foundation,
142 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
143 *
144 * END_NSC_LIC_GPL */
145
146#ifdef HAVE_CONFIG_H
147#include "config.h"
148#endif
149
150#define DEBUG(x)
151#define NSC_TRACE 0
152#define HWVGA 1
153
154/* Includes that are used by all drivers */
155#include "xf86.h"
156#include "xf86_OSproc.h"
157#include "xf86Resources.h"
158
159/* We may want inb() and outb() */
160#include "compiler.h"
161
162/* We may want to access the PCI config space */
163#include "xf86PciInfo.h"
164#include "xf86Pci.h"
165
166/* Colormap handling stuff */
167#include "xf86cmap.h"
168
169#define RC_MAX_DEPTH 24
170
171/* Frame buffer stuff */
172#include "fb.h"
173
174#include "shadowfb.h"
175
176/* Machine independent stuff */
177#include "mipointer.h"
178#include "mibank.h"
179#include "micmap.h"
180/* All drivers implementing backing store need this */
181#include "mibstore.h"
182#include "vgaHW.h"
183#include "vbe.h"
184
185/* Check for some extensions */
186#ifdef XFreeXDGA
187#define _XF86_DGA_SERVER_
188#include <X11/extensions/xf86dgastr.h>
189#endif /* XFreeXDGA */
190
191#include "globals.h"
192#include "opaque.h"
193#define DPMS_SERVER
194#include <X11/extensions/dpms.h>
195
196#define EXTERN
197/* Our private include file (this also includes the durango headers) */
198#include "nsc.h"
199
200#if NSC_TRACE
201/* ANSI C does not allow var arg macros */
202#define GeodeDebug(args) DebugPort(DCount++);ErrorF args
203#else
204#define GeodeDebug(args)
205#endif
206
207/* A few things all drivers should have */
208#define NSC_NAME            "NSC"
209#define NSC_DRIVER_NAME     "nsc"
210
211/* This should match the durango code version.
212 * The patchlevel may be used to indicate changes in geode.c
213 */
214#define NSC_VERSION_NAME    "2.8.1"
215#define NSC_VERSION_MAJOR   2
216#define NSC_VERSION_MINOR   8
217#define NSC_PATCHLEVEL      1
218
219#define NSC_VERSION_CURRENT ((NSC_VERSION_MAJOR << 24) | \
220		(NSC_VERSION_MINOR << 16) | NSC_PATCHLEVEL)
221
222/* Forward definitions */
223static const OptionInfoRec *NscAvailableOptions(int chipid, int busid);
224static void NscIdentify(int);
225static Bool NscProbe(DriverPtr, int);
226static int CPUDetected;
227
228extern void GX1SetupChipsetFPtr(ScrnInfoPtr pScrn);
229extern void GX2SetupChipsetFPtr(ScrnInfoPtr pScrn);
230
231#if !defined(STB_X)
232extern unsigned char *XpressROMPtr;
233#endif /* STB_X */
234
235/* driver record contains the functions needed by the server after loading
236 * the driver module.
237 */
238_X_EXPORT DriverRec NSC = {
239   NSC_VERSION_CURRENT,
240   NSC_DRIVER_NAME,
241   NscIdentify,
242   NscProbe,
243   NscAvailableOptions,
244   NULL,
245   0
246};
247
248/* Existing Processor Models */
249#define GX1 0x1
250#define GX2 0x2
251#define GX2_CRT 0x6
252#define GX2_TFT 0xA
253
254#define PCI_VENDOR_ID_CYRIX  0x1078
255#define PCI_VENDOR_ID_NS     0x100B
256
257#define PCI_CHIP_5530     0x0104
258#define PCI_CHIP_SC1200   0x0504
259#define PCI_CHIP_SC1400   0x0104
260#define PCI_CHIP_REDCLOUD 0x0030
261
262/* National Chip Models */
263typedef struct _DEVICE_MODEL
264{
265   int DeviceId;
266   int Model;
267}
268DeviceModel;
269
270DeviceModel ChipModel[] = {
271   {PCI_CHIP_5530, GX1},
272   {PCI_CHIP_SC1200, GX1},
273   {PCI_CHIP_SC1400, GX1},
274   {PCI_CHIP_REDCLOUD, GX2},
275   {-1, 0}
276};
277
278/* Supported chipsets */
279SymTabRec GeodeChipsets[] = {
280   {PCI_CHIP_5530, "5530"},
281   {PCI_CHIP_SC1200, "SC1200"},
282   {PCI_CHIP_SC1400, "SC1400"},
283   {PCI_CHIP_REDCLOUD, "REDCLOUD"},
284   {-1, NULL}
285};
286
287PciChipsets GeodePCIchipsets[] = {
288   {PCI_CHIP_5530, PCI_CHIP_5530, RES_SHARED_VGA},
289   {PCI_CHIP_SC1200, PCI_CHIP_SC1200, RES_SHARED_VGA},
290   {PCI_CHIP_SC1400, PCI_CHIP_SC1400, RES_SHARED_VGA},
291   {PCI_CHIP_REDCLOUD, PCI_CHIP_REDCLOUD, RES_SHARED_VGA},
292   {-1, -1, RES_UNDEFINED},
293};
294
295OptionInfoRec GeodeOptions[] = {
296   {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
297   {OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE},
298   {OPTION_NOCOMPRESSION, "NoCompression", OPTV_BOOLEAN, {0}, FALSE},
299   {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
300   {OPTION_TV_SUPPORT, "TV", OPTV_ANYSTR, {0}, FALSE},
301   {OPTION_TV_OUTPUT, "TV_Output", OPTV_ANYSTR, {0}, FALSE},
302   {OPTION_TV_OVERSCAN, "TVOverscan", OPTV_ANYSTR, {0}, FALSE},
303   {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
304   {OPTION_ROTATE, "Rotate", OPTV_ANYSTR, {0}, FALSE},
305   {OPTION_FLATPANEL, "FlatPanel", OPTV_BOOLEAN, {0}, FALSE},
306   {OPTION_COLOR_KEY, "ColorKey", OPTV_INTEGER, {0}, FALSE},
307   {OPTION_OSM_IMG_BUFS, "OSMImageBuffers", OPTV_INTEGER, {0}, FALSE},
308   {-1, NULL, OPTV_NONE, {0}, FALSE}
309};
310
311/* List of symbols from other modules that this module references.The purpose
312* is that to avoid unresolved symbol warnings
313*/
314const char *nscVgahwSymbols[] = {
315   "vgaHWGetHWRec",
316   "vgaHWUnlock",
317   "vgaHWInit",
318   "vgaHWSave",
319   "vgaHWRestore",
320   "vgaHWProtect",
321   "vgaHWGetIOBase",
322   "vgaHWMapMem",
323   "vgaHWLock",
324   "vgaHWFreeHWRec",
325   "vgaHWSaveScreen",
326   NULL
327};
328
329const char *nscVbeSymbols[] = {
330   "VBEInit",
331   "vbeDoEDID",
332   "vbeFree",
333   NULL
334};
335
336const char *nscInt10Symbols[] = {
337   "xf86ExecX86int10",
338   "xf86InitInt10",
339   "xf86Int10AllocPages",
340   "xf86Int10Addr",
341   NULL
342};
343
344const char *nscFbSymbols[] = {
345   "fbScreenInit",
346   "fbPictureInit",
347   NULL
348};
349
350const char *nscXaaSymbols[] = {
351   "XAADestroyInfoRec",
352   "XAACreateInfoRec",
353   "XAAInit",
354   NULL
355};
356
357const char *nscRamdacSymbols[] = {
358   "xf86InitCursor",
359   "xf86CreateCursorInfoRec",
360   "xf86DestroyCursorInfoRec",
361   NULL
362};
363
364const char *nscShadowSymbols[] = {
365   "ShadowFBInit",
366   NULL
367};
368
369#ifdef XFree86LOADER
370
371/* Module loader interface */
372
373static MODULESETUPPROTO(NscSetup);
374
375static XF86ModuleVersionInfo NscVersionRec = {
376   "nsc",
377   MODULEVENDORSTRING,
378   MODINFOSTRING1,
379   MODINFOSTRING2,
380   XORG_VERSION_CURRENT,
381   NSC_VERSION_MAJOR, NSC_VERSION_MINOR, NSC_PATCHLEVEL,
382   ABI_CLASS_VIDEODRV,			/* This is a video driver */
383   ABI_VIDEODRV_VERSION,
384   MOD_CLASS_VIDEODRV,
385   {0, 0, 0, 0}
386};
387
388/*
389 * This data is accessed by the loader.  The name must be the module name
390 * followed by "ModuleInit".
391 */
392_X_EXPORT XF86ModuleData nscModuleData = { &NscVersionRec, NscSetup, NULL };
393
394/*-------------------------------------------------------------------------
395 * NscSetup.
396 *
397 * Description	:This function sets up the driver in X list and load the
398 *               module symbols through xf86loader routines..
399 *
400 * Parameters.
401 *    Module	:Pointer to the geode  module
402 *    options	:Driver module options.
403 *    ErrorMajor:Major no
404 *    ErrorMinor:Minor no.
405 *
406 * Returns		:NULL on success
407 *
408 * Comments     :Module setup is done by this function
409 *
410 *-------------------------------------------------------------------------
411*/
412static pointer
413NscSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
414{
415   static Bool Initialised = FALSE;
416
417   if (!Initialised) {
418      Initialised = TRUE;
419      xf86AddDriver(&NSC, Module, 0);
420      /* Tell the loader about symbols from other modules that this
421       * module might refer to.
422       */
423      LoaderRefSymLists(nscVgahwSymbols, nscVbeSymbols,
424			nscFbSymbols,
425			nscXaaSymbols,
426			nscInt10Symbols, nscRamdacSymbols, nscShadowSymbols,
427			NULL);
428      return (pointer) TRUE;
429   }
430   /*The return value must be non-NULL on success */
431   if (ErrorMajor)
432      *ErrorMajor = LDR_ONCEONLY;
433   return NULL;
434}
435#endif /*End of XFree86Loader */
436
437/*-------------------------------------------------------------------------
438 * NscIdentify.
439 *
440 * Description  :	This function identify an Nscfamily version.
441 *
442 *
443 * Parameters.
444 *    flags		:	flags may be used in PreInit*
445 *
446 * Returns		: 	none
447 *
448 * Comments     : 	none
449 *
450*------------------------------------------------------------------------
451*/
452static void
453NscIdentify(int flags)
454{
455   xf86PrintChipsets(NSC_NAME,
456		     "Nsc family driver (version " NSC_VERSION_NAME ") "
457		     "for chipsets", GeodeChipsets);
458}
459
460/*----------------------------------------------------------------------------
461 * NscAvailableOptions.
462 *
463 * Description	:This function returns the geodeoptions set geodeoption
464 *
465 * Parameters.
466 *    chipid	:This will identify the chipset.
467 *    busid     :This will identify the PCI busid
468 *
469 * Returns		:ptr to GeodeOptions.
470 *
471 * Comments     :none
472 *
473*----------------------------------------------------------------------------
474*/
475static const OptionInfoRec *
476NscAvailableOptions(int chipid, int busid)
477{
478   return GeodeOptions;
479}
480
481/*----------------------------------------------------------------------------
482 * NscProbe.
483 *
484 * Description	:This is to find that hardware is claimed by another
485 *		 driver if not claim the slot & allocate ScreenInfoRec.
486 *
487 * Parameters.
488 *     drv	:a pointer to the geode driver
489 *     flags    :flags may passed to check the config and probe detect
490 *
491 * Returns	:TRUE on success and FALSE on failure.
492 *
493 * Comments     :This should ne minimal probe and it should under no
494 *               circumstances change the state of the hardware.Don't do
495 *               any intiallizations other than the required
496 *               ScreenInforec.
497*----------------------------------------------------------------------------
498*/
499
500static Bool
501NscProbe(DriverPtr drv, int flags)
502{
503   Bool foundScreen = FALSE;
504   int numDevSections, numUsed;
505   GDevPtr *devSections = NULL;
506   int *usedChips = NULL;
507   int i;
508
509   GeodeDebug(("NscProbe: Probing for supported devices!\n"));
510   /*
511    * * Find the config file Device sections that match this
512    * * driver, and return if there are none.
513    */
514   if ((numDevSections = xf86MatchDevice(NSC_NAME, &devSections)) <= 0) {
515      GeodeDebug(("NscProbe: failed 1!\n"));
516      return FALSE;
517   }
518   GeodeDebug(("NscProbe: Before MatchPciInstances!\n"));
519   /* PCI BUS */
520   if (xf86GetPciVideoInfo()) {
521      numUsed = xf86MatchPciInstances(NSC_NAME, PCI_VENDOR_ID_NS,
522				      GeodeChipsets, GeodePCIchipsets,
523				      devSections, numDevSections,
524				      drv, &usedChips);
525      if (numUsed <= 0) {
526	 /* Check for old CYRIX vendor ID (5530) */
527	 numUsed = xf86MatchPciInstances(NSC_NAME,
528					 PCI_VENDOR_ID_CYRIX,
529					 GeodeChipsets, GeodePCIchipsets,
530					 devSections, numDevSections,
531					 drv, &usedChips);
532      }
533
534      GeodeDebug(("NscProbe: MatchPCI (%d)!\n", numUsed));
535
536      if (numUsed > 0) {
537	 if (flags & PROBE_DETECT)
538	    foundScreen = TRUE;
539	 else {
540	    /* Durango only supports one instance, */
541	    /* so take the first one */
542	    for (i = 0; i < numUsed; i++) {
543	       /* Allocate a ScrnInfoRec  */
544	       ScrnInfoPtr pScrn = xf86AllocateScreen(drv, 0);
545
546	       EntityInfoPtr pEnt = xf86GetEntityInfo(usedChips[i]);
547	       PciChipsets *p_id;
548
549	       for (p_id = GeodePCIchipsets; p_id->numChipset != -1; p_id++) {
550		  if (pEnt->chipset == p_id->numChipset) {
551		     CPUDetected = GX1;
552		     if (pEnt->chipset == PCI_CHIP_REDCLOUD)
553			CPUDetected = GX2;
554		     break;
555		  }
556	       }
557	       xfree(pEnt);
558	       GeodeDebug(("NscProbe: CPUDetected %d!\n", CPUDetected));
559
560	       pScrn->driverName = NSC_DRIVER_NAME;
561	       pScrn->name = NSC_NAME;
562	       pScrn->Probe = NscProbe;
563
564	       if (CPUDetected == GX1) {
565		  GX1SetupChipsetFPtr(pScrn);
566	       } else {			/* GX2 */
567		  GX2SetupChipsetFPtr(pScrn);
568	       }
569
570	       foundScreen = TRUE;
571	       xf86ConfigActivePciEntity(pScrn,
572					 usedChips[i],
573					 GeodePCIchipsets,
574					 NULL, NULL, NULL, NULL, NULL);
575	    }
576	 }
577      }
578   }
579
580   if (usedChips)
581      xfree(usedChips);
582   if (devSections)
583      xfree(devSections);
584   GeodeDebug(("NscProbe: result (%d)!\n", foundScreen));
585   return foundScreen;
586}
587