1
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/gfx/durango.c,v 1.1 2002/12/10 15:12:25 alanh Exp $ */
3
* $Workfile: durango.c $
5
* This is the main file used to add Durango graphics support to a software
6
* project. The main reason to have a single file include the other files
7
* is that it centralizes the location of the compiler options. This file
8
* should be tuned for a specific implementation, and then modified as needed
9
* for new Durango releases. The releases.txt file indicates any updates to
10
* this main file, such as a new definition for a new hardware platform.
12
* In other words, this file should be copied from the Durango source files
13
* once when a software project starts, and then maintained as necessary.
14
* It should not be recopied with new versions of Durango unless the
15
* developer is willing to tune the file again for the specific project.
17
* NSC_LIC_ALTERNATIVE_PREAMBLE
21
* National Semiconductor Alternative GPL-BSD License
23
* National Semiconductor Corporation licenses this software
28
* under one of the two following licenses, depending on how the
29
* Software is received by the Licensee.
31
* If this Software is received as part of the Linux Framebuffer or
32
* other GPL licensed software, then the GPL license designated
33
* NSC_LIC_GPL applies to this Software; in all other circumstances
34
* then the BSD-style license designated NSC_LIC_BSD shall apply.
36
* END_NSC_LIC_ALTERNATIVE_PREAMBLE */
40
* National Semiconductor Corporation Open Source License for Durango
42
* (BSD License with Export Notice)
44
* Copyright (c) 1999-2001
45
* National Semiconductor Corporation.
46
* All rights reserved.
48
* Redistribution and use in source and binary forms, with or without
49
* modification, are permitted provided that the following conditions
52
* * Redistributions of source code must retain the above copyright
53
* notice, this list of conditions and the following disclaimer.
55
* * Redistributions in binary form must reproduce the above
56
* copyright notice, this list of conditions and the following
57
* disclaimer in the documentation and/or other materials provided
58
* with the distribution.
60
* * Neither the name of the National Semiconductor Corporation nor
61
* the names of its contributors may be used to endorse or promote
62
* products derived from this software without specific prior
65
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
66
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
67
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
68
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
69
* NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
70
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
72
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
73
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
74
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
75
* INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
76
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
79
* EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
80
* YOUR JURISDICTION. It is licensee's responsibility to comply with
81
* any export regulations applicable in licensee's jurisdiction. Under
82
* CURRENT (2001) U.S. export regulations this software
83
* is eligible for export from the U.S. and can be downloaded by or
84
* otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
85
* destinations which include Cuba, Iraq, Libya, North Korea, Iran,
86
* Syria, Sudan, Afghanistan and any other country to which the U.S.
87
* has embargoed goods and services.
93
* National Semiconductor Corporation Gnu General Public License for Durango
95
* (GPL License with Export Notice)
97
* Copyright (c) 1999-2001
98
* National Semiconductor Corporation.
99
* All rights reserved.
101
* Redistribution and use in source and binary forms, with or without
102
* modification, are permitted under the terms of the GNU General
103
* Public License as published by the Free Software Foundation; either
104
* version 2 of the License, or (at your option) any later version
106
* In addition to the terms of the GNU General Public License, neither
107
* the name of the National Semiconductor Corporation nor the names of
108
* its contributors may be used to endorse or promote products derived
109
* from this software without specific prior written permission.
111
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
112
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
113
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
114
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
115
* NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
116
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
117
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
118
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
119
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
120
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
121
* INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
122
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
123
* OF SUCH DAMAGE. See the GNU General Public License for more details.
125
* EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
126
* YOUR JURISDICTION. It is licensee's responsibility to comply with
127
* any export regulations applicable in licensee's jurisdiction. Under
128
* CURRENT (2001) U.S. export regulations this software
129
* is eligible for export from the U.S. and can be downloaded by or
130
* otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
131
* destinations which include Cuba, Iraq, Libya, North Korea, Iran,
132
* Syria, Sudan, Afghanistan and any other country to which the U.S.
133
* has embargoed goods and services.
135
* You should have received a copy of the GNU General Public License
136
* along with this file; if not, write to the Free Software Foundation,
137
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
142
* These compiler options specify how the Durango routines are compiled
143
* for the different hardware platforms. For best performance, a driver
144
* would build for a specific platform. The "dynamic" switches are set
145
* by diagnostic applications such as Darwin that will run on a variety
146
* of platforms and use the appropriate code at runtime. Each component
147
* may be separately dynamic, so that a driver has the option of being
148
* tuned for a specific 2D accelerator, but will still run with a variety
152
#define GFX_DISPLAY_DYNAMIC 1 /* runtime selection */
153
#define GFX_DISPLAY_GU1 1 /* 1st generation display controller */
154
#define GFX_DISPLAY_GU2 1 /* 2nd generation display controller */
156
#define GFX_INIT_DYNAMIC 1 /* runtime selection */
157
#define GFX_INIT_GU1 1 /* Geode family */
158
#define GFX_INIT_GU2 1 /* Redcloud */
160
#define GFX_MSR_DYNAMIC 1 /* runtime selection */
161
#define GFX_MSR_REDCLOUD 1 /* Redcloud */
163
#define GFX_2DACCEL_DYNAMIC 1 /* runtime selection */
164
#define GFX_2DACCEL_GU1 1 /* 1st generation 2D accelerator */
165
#define GFX_2DACCEL_GU2 1 /* 2nd generation 2D accelerator */
167
#define GFX_VIDEO_DYNAMIC 1 /* runtime selection */
168
#define GFX_VIDEO_CS5530 1 /* support for CS5530 */
169
#define GFX_VIDEO_SC1200 1 /* support for SC1200 */
170
#define GFX_VIDEO_REDCLOUD 1 /* support for Redcloud */
172
#define GFX_VIP_DYNAMIC 1 /* runtime selection */
173
#define GFX_VIP_SC1200 1 /* support for SC1200 */
175
#define GFX_DECODER_DYNAMIC 1 /* runtime selection */
176
#define GFX_DECODER_SAA7114 1 /* Philips SAA7114 decoder */
178
#define GFX_TV_DYNAMIC 1 /* runtime selection */
179
#define GFX_TV_FS451 1 /* Focus Enhancements FS450 */
180
#define GFX_TV_SC1200 1 /* SC1200 integrated TV encoder */
182
#define GFX_I2C_DYNAMIC 1 /* runtime selection */
183
#define GFX_I2C_ACCESS 1 /* support for ACCESS.BUS */
184
#define GFX_I2C_GPIO 1 /* support for CS5530 GPIOs */
186
#define GFX_VGA_DYNAMIC 1 /* runtime selection */
187
#define GFX_VGA_GU1 1 /* 1st generation graphics unit */
189
#define FB4MB 1 /* Set to use 4Mb video ram for Pyramid */
191
#define GFX_NO_IO_IN_WAIT_MACROS 0 /* Set to remove I/O accesses in GP bit testing */
193
/* ROUTINES TO READ VALUES
194
* These are routines used by Darwin or other diagnostics to read the
195
* current state of the hardware. Display drivers or embedded applications can
196
* reduce the size of the Durango code by not including these routines.
198
#define GFX_READ_ROUTINES 1 /* add routines to read values */
200
/* VARIABLES USED FOR RUNTIME SELECTION
201
* If part of the graphics subsystem is declared as dynamic, then the
202
* following variables are used to specify which platform has been detected.
203
* The variables are set in the "gfx_detect_cpu" routine. The values should
204
* be bit flags to allow masks to be used to check for multiple platforms.
207
#if GFX_DISPLAY_DYNAMIC
208
int gfx_display_type = 0;
212
int gfx_init_type = 0;
216
int gfx_msr_type = 0;
219
#if GFX_2DACCEL_DYNAMIC
220
int gfx_2daccel_type = 0;
223
#if GFX_VIDEO_DYNAMIC
224
int gfx_video_type = 0;
228
int gfx_vip_type = 0;
231
#if GFX_DECODER_DYNAMIC
232
int gfx_decoder_type = 0;
240
int gfx_i2c_type = 0;
244
int gfx_vga_type = 0;
247
/* HEADER FILE FOR DURANGO ROUTINE DEFINITIONS
248
* Needed since some of the Durango routines call other Durango routines.
249
* Also defines the size of chipset array (GFX_CSPTR_SIZE).
251
#include "gfx_rtns.h" /* routine definitions */
253
/* DEFINE POINTERS TO MEMORY MAPPED REGIONS
254
* These pointers are used by the Durango routines to access the hardware.
255
* The variables must be set by the project's initialization code after
256
* mapping the regions in the appropriate manner.
259
/* DEFINE VIRTUAL ADDRESSES */
260
/* Note: These addresses define the starting base expected by all */
261
/* Durango offsets. Under an OS that requires these pointers */
262
/* to be mapped to linear addresses (i.e Windows), it may not */
263
/* be possible to keep these base offsets. In these cases, */
264
/* the addresses are modified to point to the beginning of the */
265
/* relevant memory region and the access macros are adjusted */
266
/* to subtract the offset from the default base. For example, */
267
/* the register pointer could be moved to be 0x40008000, while */
268
/* the WRITE_REG* macros are modified to subtract 0x8000 from */
271
unsigned char *gfx_virt_regptr = (unsigned char *)0x40000000;
272
unsigned char *gfx_virt_fbptr = (unsigned char *)0x40800000;
273
unsigned char *gfx_virt_vidptr = (unsigned char *)0x40010000;
274
unsigned char *gfx_virt_vipptr = (unsigned char *)0x40015000;
275
unsigned char *gfx_virt_spptr = (unsigned char *)0x40000000;
276
unsigned char *gfx_virt_gpptr = (unsigned char *)0x40000000;
278
/* DEFINE PHYSICAL ADDRESSES */
280
unsigned char *gfx_phys_regptr = (unsigned char *)0x40000000;
281
unsigned char *gfx_phys_fbptr = (unsigned char *)0x40800000;
282
unsigned char *gfx_phys_vidptr = (unsigned char *)0x40010000;
283
unsigned char *gfx_phys_vipptr = (unsigned char *)0x40015000;
285
/* HEADER FILE FOR GRAPHICS REGISTER DEFINITIONS
286
* This contains only constant definitions, so it should be able to be
287
* included in any software project as is.
289
#include "gfx_regs.h" /* graphics register definitions */
291
/* HEADER FILE FOR REGISTER ACCESS MACROS
292
* This file contains the definitions of the WRITE_REG32 and similar macros
293
* used by the Durango routines to access the hardware. The file assumes
294
* that the environment can handle 32-bit pointer access. If this is not
295
* the case, or if there are special requirements, then this header file
296
* should not be included and the project must define the macros itself.
297
* (A project may define WRITE_REG32 to call a routine, for example).
299
#include "gfx_defs.h" /* register access macros */
301
/* IO MACROS AND ROUTINES
302
* These macros must be defined before the initialization or I2C
303
* routines will work properly.
306
#if defined(OS_WIN32) /* For Windows */
311
gfx_msr_asm_read(unsigned short msrReg, unsigned long msrAddr,
312
unsigned long *ptrHigh, unsigned long *ptrLow)
314
unsigned long temp1, temp2;
324
;EDX:EAX will contain MSR contents.
334
gfx_msr_asm_write(unsigned short msrReg, unsigned long msrAddr,
335
unsigned long *ptrHigh, unsigned long *ptrLow)
337
unsigned long temp1 = *ptrHigh;
338
unsigned long temp2 = *ptrLow;
345
;ECX contains msrAddr | msrReg
357
;MSR is written at this point
363
gfx_inb(unsigned short port)
378
gfx_inw(unsigned short port)
393
gfx_ind(unsigned short port)
408
gfx_outb(unsigned short port, unsigned char data)
420
gfx_outw(unsigned short port, unsigned short data)
432
gfx_outd(unsigned short port, unsigned long data)
444
#elif defined(OS_VXWORKS) || defined (OS_LINUX) /* VxWorks and Linux */
446
#if defined(OS_LINUX)
451
gfx_msr_asm_read(unsigned short msrReg, unsigned long msrAddr,
452
unsigned long *ptrHigh, unsigned long *ptrLow)
454
unsigned long addr, val1, val2;
456
addr = msrAddr | (unsigned long)msrReg;
457
rdmsr(addr, val1, val2);
464
gfx_msr_asm_write(unsigned short msrReg, unsigned long msrAddr,
465
unsigned long *ptrHigh, unsigned long *ptrLow)
467
unsigned long addr, val1, val2;
472
addr = (msrAddr & 0xFFFF0000) | (unsigned long)msrReg;
473
wrmsr(addr, val1, val2);
477
gfx_inb(unsigned short port)
480
__asm__ volatile ("inb %1,%0":"=a" (value):"d"(port));
486
gfx_inw(unsigned short port)
488
unsigned short value;
489
__asm__ volatile ("in %1,%0":"=a" (value):"d"(port));
495
gfx_ind(unsigned short port)
498
__asm__ volatile ("inl %1,%0":"=a" (value):"d"(port));
504
gfx_outb(unsigned short port, unsigned char data)
506
__asm__ volatile ("outb %0,%1"::"a" (data), "d"(port));
510
gfx_outw(unsigned short port, unsigned short data)
512
__asm__ volatile ("out %0,%1"::"a" (data), "d"(port));
516
gfx_outd(unsigned short port, unsigned long data)
518
__asm__ volatile ("outl %0,%1"::"a" (data), "d"(port));
521
#else /* else nothing */
524
gfx_inb(unsigned short port)
526
/* ADD OS SPECIFIC IMPLEMENTATION */
531
gfx_inw(unsigned short port)
533
/* ADD OS SPECIFIC IMPLEMENTATION */
538
gfx_ind(unsigned short port)
540
/* ADD OS SPECIFIC IMPLEMENTATION */
545
gfx_outb(unsigned short port, unsigned char data)
547
/* ADD OS SPECIFIC IMPLEMENTATION */
551
gfx_outw(unsigned short port, unsigned short data)
553
/* ADD OS SPECIFIC IMPLEMENTATION */
557
gfx_outd(unsigned short port, unsigned long data)
559
/* ADD OS SPECIFIC IMPLEMENTATION */
563
#define INB(port) gfx_inb(port)
564
#define INW(port) gfx_inw(port)
565
#define IND(port) gfx_ind(port)
566
#define OUTB(port, data) gfx_outb(port, data)
567
#define OUTW(port, data) gfx_outw(port, data)
568
#define OUTD(port, data) gfx_outd(port, data)
570
/* INITIALIZATION ROUTINES
571
* These routines are used during the initialization of the driver to
572
* perform such tasks as detecting the type of CPU and video hardware.
573
* The routines require the use of IO, so the above IO routines need
574
* to be implemented before the initialization routines will work
578
#include "gfx_init.c"
580
/* INCLUDE MSR ACCESS ROUTINES */
584
/* INCLUDE GRAPHICS ENGINE ROUTINES
585
* These routines are used to program the 2D graphics accelerator. If
586
* the project does not use graphics acceleration (direct frame buffer
587
* access only), then this file does not need to be included.
589
#include "gfx_rndr.c" /* graphics engine routines */
591
/* INCLUDE DISPLAY CONTROLLER ROUTINES
592
* These routines are used if the display mode is set directly. If the
593
* project uses VGA registers to set a display mode, then these files
594
* do not need to be included.
596
#include "gfx_mode.h" /* display mode tables */
597
#include "gfx_disp.c" /* display controller routines */
599
/* INCLUDE VIDEO OVERLAY ROUTINES
600
* These routines control the video overlay hardware.
602
#include "gfx_vid.c" /* video overlay routines */
604
/* VIDEO PORT AND VIDEO DECODER ROUTINES
605
* These routines rely on the I2C routines.
607
#include "gfx_vip.c" /* video port routines */
608
#include "gfx_dcdr.c" /* video decoder routines */
610
/* I2C BUS ACCESS ROUTINES
611
* These routines are used by the video decoder and possibly an
612
* external TV encoer.
614
#include "gfx_i2c.c" /* I2C bus access routines */
616
/* TV ENCODER ROUTINES
617
* This file does not need to be included if the system does not
620
#include "gfx_tv.c" /* TV encoder routines */
623
* This file is used if setting display modes using VGA registers.
625
#include "gfx_vga.c" /* VGA routines */