summaryrefslogtreecommitdiff
path: root/src/rhd_mc.c
blob: 5405945922c6a1d029b78ab4ee92ecb1c8986464 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
/*
 * Copyright 2007, 2008  Luc Verhaegen <libv@exsuse.de>
 * Copyright 2007, 2008  Matthias Hopf <mhopf@novell.com>
 * Copyright 2007, 2008  Egbert Eich   <eich@novell.com>
 * Copyright 2007, 2008  Advanced Micro Devices, Inc.
 *
 * 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
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
 */

/*
 * MC idling:
 *
 * For SetupFBLocation and Restore, we require a fully idle MC as we might lock up
 * otherwise. Both calls now check whether the MC is Idle before attempting
 * to set up the MC, and complain loudly when this fails.
 *
 * Likely suspect registers for when the Idle fails:
 *   DxVGA_CONTROL & D1VGA_MODE_ENABLE (run RHDVGADisable beforehand)
 *   DxCRTC_CONTROL & 0x1 (run DxCRTCDisable beforehand)
 *   (... Add more here...)
 *
 *
 * MC addressing:
 *
 * On R600 and up the MC can use a larger than 32bit card internal address for
 * its framebuffer. This is why the Address used inside the MC code is a
 * CARD64.
 *
 * rhdPtr->FbIntAddress is kept as a CARD32 for the time being. This is still
 * valid, as this makes the R500 code simpler, and since we pick FbIntAddress
 * from a 32bit register anyway on R600. FbIntAddress will also correctly cast
 * to a CARD64 when passed to the likes of the SetupFBLocation callback.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#if HAVE_XF86_ANSIC_H
# include "xf86_ansic.h"
#else
# include <unistd.h>
#endif

#include "xf86.h"

#include "rhd.h"
#include "rhd_regs.h"
#include "rhd_crtc.h" /* for definition of Crtc->Id */

struct rhdMC {
    int scrnIndex;

    CARD32 FbLocation;
    CARD32 HdpFbAddress;
    CARD32 MiscLatencyTimer;

    Bool Stored;

    void (*Save)(struct rhdMC *MC);
    void (*Restore)(struct rhdMC *MC);
    Bool (*Idle)(struct rhdMC *MC);
    CARD64 (*GetFBLocation)(struct rhdMC *MC, CARD32 *size);
    void (*SetupFBLocation)(struct rhdMC *MC, CARD64 Address, CARD32 Size);
    void (*TuneAccessForDisplay)(struct rhdMC *MC, int crtc,
			   DisplayModePtr Mode, DisplayModePtr ScaledToMode);
};

/*
 * Some common FB location calculations.
 */
/*
 * Applicable for all R5xx and RS600, RS690, RS740
 */
static CARD64
R5xxMCGetFBLocation(CARD32 Value, CARD32 *Size)
{
    *Size = (Value & 0xFFFF0000) - ((Value & 0xFFFF) << 16);
    return  (Value & 0xFFFF) << 16;
}

#define R5XX_FB_LOCATION(address, size) \
    ((((address) + (size)) & 0xFFFF0000) | (((address) >> 16) & 0xFFFF))
#define R5XX_HDP_LOCATION(address) \
    (((address) >> 16) & 0xFFFF)

/*
 * Applicable for all R6xx and R7xx, and RS780/RS790
 */
static CARD64
R6xxMCGetFBLocation(CARD32 Value, CARD32 *Size)
{
    *Size = (((Value & 0xFFFF0000) - ((Value & 0xFFFF) << 16))) << 8;
    return (Value & 0xFFFF) << 24;
}

#define R6XX_FB_LOCATION(address, size) \
    (((((address) + (size)) >> 8) & 0xFFFF0000) | (((address) >> 24) & 0xFFFF))
#define R6XX_HDP_LOCATION(address) \
    ((((address) >> 8) & 0x00FF0000))

/*
 *
 */
static void
RV515MCSave(struct rhdMC *MC)
{
    MC->FbLocation = RHDReadMC(MC, MC_IND_ALL | RV515_MC_FB_LOCATION);
    MC->MiscLatencyTimer = RHDReadMC(MC, MC_IND_ALL | RV515_MC_MISC_LAT_TIMER);
    MC->HdpFbAddress = RHDRegRead(MC, HDP_FB_LOCATION);
}

/*
 *
 */
static void
RV515MCRestore(struct rhdMC *MC)
{
    RHDWriteMC(MC, MC_IND_ALL | RV515_MC_FB_LOCATION, MC->FbLocation);
    RHDWriteMC(MC, MC_IND_ALL | RV515_MC_MISC_LAT_TIMER, MC->MiscLatencyTimer);
    RHDRegWrite(MC, HDP_FB_LOCATION, MC->HdpFbAddress);
}

/*
 *
 */
static Bool
RV515MCWaitIdle(struct rhdMC *MC)
{
    if (RHDReadMC(MC, MC_IND_ALL | RV515_MC_STATUS) & RV515_MC_IDLE)
	return TRUE;
    return FALSE;
}

/*
 *
 */
static CARD64
RV515MCGetFBLocation(struct rhdMC *MC, CARD32 *Size)
{
    return R5xxMCGetFBLocation(RHDReadMC(MC, RV515_MC_FB_LOCATION | MC_IND_ALL), Size);
}

/*
 *
 */
static void
RV515MCSetupFBLocation(struct rhdMC *MC, CARD64 Address, CARD32 Size)
{
    RHDWriteMC(MC, RV515_MC_FB_LOCATION | MC_IND_ALL,
	       R5XX_FB_LOCATION(Address, Size));
    RHDRegWrite(MC, HDP_FB_LOCATION, R5XX_HDP_LOCATION(Address));
}

/*
 *
 */
static void
RV515MCTuneMCAccessForDisplay(struct rhdMC *MC, int Crtc,
		    DisplayModePtr Mode, DisplayModePtr ScaledToMode)
{
    CARD32 value, setting = 0x1;

    value = RHDReadMC(MC, RV515_MC_MISC_LAT_TIMER);

    if (Crtc == RHD_CRTC_1) {
	value &= ~(0x0F << MC_DISP0R_INIT_LAT_SHIFT);
	value |= setting << MC_DISP0R_INIT_LAT_SHIFT;
    } else { /* RHD_CRTC_2 */
	value &= ~(0x0F << MC_DISP1R_INIT_LAT_SHIFT);
	value |= setting << MC_DISP1R_INIT_LAT_SHIFT;
    }

    RHDWriteMC(MC, RV515_MC_MISC_LAT_TIMER, value);
}

/*
 *
 */
static void
R500MCSave(struct rhdMC *MC)
{
    MC->FbLocation = RHDReadMC(MC, MC_IND_ALL | R5XX_MC_FB_LOCATION);
    MC->HdpFbAddress = RHDRegRead(MC, HDP_FB_LOCATION);
}

/*
 *
 */
static void
R500MCRestore(struct rhdMC *MC)
{
    RHDWriteMC(MC, MC_IND_ALL | R5XX_MC_FB_LOCATION, MC->FbLocation);
    RHDRegWrite(MC, HDP_FB_LOCATION, MC->HdpFbAddress);
}

/*
 *
 */
static Bool
R500MCWaitIdle(struct rhdMC *MC)
{
    if (RHDReadMC(MC, MC_IND_ALL | R5XX_MC_STATUS) & R5XX_MC_IDLE)
	return TRUE;
    return FALSE;
}

/*
 *
 */
static CARD64
R500MCGetFBLocation(struct rhdMC *MC, CARD32 *Size)
{
    return R5xxMCGetFBLocation(RHDReadMC(MC, R5XX_MC_FB_LOCATION | MC_IND_ALL), Size);
}

/*
 *
 */
static void
R500MCSetupFBLocation(struct rhdMC *MC, CARD64 Address, CARD32 Size)
{
    RHDWriteMC(MC, R5XX_MC_FB_LOCATION | MC_IND_ALL,
	       R5XX_FB_LOCATION(Address, Size));
    RHDRegWrite(MC, HDP_FB_LOCATION, R5XX_HDP_LOCATION(Address));
}

/*
 *
 */
static void
RS600MCSave(struct rhdMC *MC)
{
    MC->FbLocation = RHDReadMC(MC, RS60_NB_FB_LOCATION);
    MC->HdpFbAddress = RHDRegRead(MC, HDP_FB_LOCATION);
}

/*
 *
 */
static void
RS600MCRestore(struct rhdMC *MC)
{
    RHDWriteMC(MC, RS60_NB_FB_LOCATION, MC->FbLocation);
    RHDRegWrite(MC, HDP_FB_LOCATION, MC->HdpFbAddress);
}

/*
 *
 */
static Bool
RS600MCWaitIdle(struct rhdMC *MC)
{
    if (RHDReadMC(MC, RS60_MC_SYSTEM_STATUS) & RS6X_MC_SEQUENCER_IDLE)
	return TRUE;
    return FALSE;
}

/*
 *
 */
static CARD64
RS600MCGetFBLocation(struct rhdMC *MC, CARD32 *Size)
{
    return R5xxMCGetFBLocation(RHDReadMC(MC, RS60_NB_FB_LOCATION), Size);
}

/*
 *
 */
static void
RS600MCSetupFBLocation(struct rhdMC *MC, CARD64 Address, CARD32 Size)
{
    RHDWriteMC(MC, RS60_NB_FB_LOCATION, R5XX_FB_LOCATION(Address, Size));
    RHDRegWrite(MC, HDP_FB_LOCATION, R5XX_HDP_LOCATION(Address));
}

/*
 *
 */
static void
RS690MCSave(struct rhdMC *MC)
{
    MC->FbLocation = RHDReadMC(MC, RS69_MCCFG_FB_LOCATION);
    MC->HdpFbAddress = RHDRegRead(MC, HDP_FB_LOCATION);
    MC->MiscLatencyTimer = RHDReadMC(MC, RS69_MC_INIT_MISC_LAT_TIMER);
}

/*
 *
 */
static void
RS690MCRestore(struct rhdMC *MC)
{
    RHDWriteMC(MC, RS69_MCCFG_FB_LOCATION, MC->FbLocation);
    RHDRegWrite(MC, HDP_FB_LOCATION, MC->HdpFbAddress);
    RHDWriteMC(MC, RS69_MC_INIT_MISC_LAT_TIMER, MC->MiscLatencyTimer);
}

/*
 *
 */
static Bool
RS690MCWaitIdle(struct rhdMC *MC)
{
    if (RHDReadMC(MC, RS69_MC_SYSTEM_STATUS) & RS6X_MC_SEQUENCER_IDLE)
	return TRUE;
    return FALSE;
}

/*
 *
 */
static CARD64
RS690MCGetFBLocation(struct rhdMC *MC, CARD32 *Size)
{
    return R5xxMCGetFBLocation(RHDReadMC(MC, RS69_MCCFG_FB_LOCATION), Size);
}

/*
 *
 */
static void
RS690MCSetupFBLocation(struct rhdMC *MC, CARD64 Address, CARD32 Size)
{
    RHDWriteMC(MC, RS69_MCCFG_FB_LOCATION, R5XX_FB_LOCATION(Address, Size));
    RHDRegWrite(MC, HDP_FB_LOCATION, R5XX_HDP_LOCATION(Address));
}

/*
 *
 */
static void
RS690MCTuneMCAccessForDisplay(struct rhdMC *MC, int Crtc,
		      DisplayModePtr Mode, DisplayModePtr ScaledToMode)
{
    CARD32 value, setting = 0x1;

    value = RHDReadMC(MC, RS69_MC_INIT_MISC_LAT_TIMER);

    if (Crtc == RHD_CRTC_1) {
	value &= ~(0x0F << MC_DISP0R_INIT_LAT_SHIFT);
	value |= setting << MC_DISP0R_INIT_LAT_SHIFT;
    } else { /* RHD_CRTC_2 */
	value &= ~(0x0F << MC_DISP1R_INIT_LAT_SHIFT);
	value |= setting << MC_DISP1R_INIT_LAT_SHIFT;
    }

    RHDWriteMC(MC, RS69_MC_INIT_MISC_LAT_TIMER, value);
}

/*
 *
 */
static void
R600MCSave(struct rhdMC *MC)
{
    MC->FbLocation = RHDRegRead(MC, R6XX_MC_VM_FB_LOCATION);
    MC->HdpFbAddress = RHDRegRead(MC, R6XX_HDP_NONSURFACE_BASE);
}

/*
 *
 */
static void
R600MCRestore(struct rhdMC *MC)
{
    RHDRegWrite(MC, R6XX_MC_VM_FB_LOCATION, MC->FbLocation);
    RHDRegWrite(MC, R6XX_HDP_NONSURFACE_BASE, MC->HdpFbAddress);
}

/*
 *
 */
static Bool
R600MCWaitIdle(struct rhdMC *MC)
{
    if (!(RHDRegRead(MC, SRBM_STATUS) & 0x3f00))
	return TRUE;
    return FALSE;
}

/*
 *
 */
static CARD64
R600MCGetFBLocation(struct rhdMC *MC, CARD32 *Size)
{
    return R6xxMCGetFBLocation(RHDRegRead(MC, R6XX_MC_VM_FB_LOCATION), Size);
}

/*
 *
 */
static void
R600MCSetupFBLocation(struct rhdMC *MC, CARD64 Address, CARD32 Size)
{
    RHDRegWrite(MC, R6XX_MC_VM_FB_LOCATION, R6XX_FB_LOCATION(Address, Size));
    RHDRegWrite(MC, R6XX_HDP_NONSURFACE_BASE, R6XX_HDP_LOCATION(Address));
}

/*
 *
 */
#ifdef NOTYET

/*
 *
 */
static void
RS780MCSave(struct rhdMC *MC)
{
    MC->FbLocation = RHDReadMC(MC, RS78_MC_FB_LOCATION);
    MC->HdpFbAddress = RHDRegRead(MC, R6XX_HDP_NONSURFACE_BASE);
}

/*
 *
 */
static void
RS780MCRestore(struct rhdMC *MC)
{
    RHDWriteMC(MC, RS78_MC_FB_LOCATION, MC->FbLocation);
    RHDRegWrite(MC, R6XX_HDP_NONSURFACE_BASE, MC->HdpFbAddress);
}

/*
 *
 */
static Bool
RS780MCWaitIdle(struct rhdMC *MC)
{
    if (RHDReadMC(MC, RS78_MC_SYSTEM_STATUS) & RS78_MC_SEQUENCER_IDLE)
	return TRUE;
    return FALSE;
}

/*
 *
 */
static CARD64
RS780MCGetFBLocation(struct rhdMC *MC, CARD32 *Size)
{
    /* is this correct? */
    return R5xxMCGetFBLocation(RHDReadMC(MC, RS78_MC_FB_LOCATION), Size);
}

/*
 *
 */
static void
RS780MCSetupFBLocation(struct rhdMC *MC, CARD64 Address, CARD32 Size)
{
    /* is this correct? */
    RHDWriteMC(MC, RS78_MC_FB_LOCATION, R5XX_FB_LOCATION(Address, Size));
    RHDRegWrite(MC, R6XX_HDP_NONSURFACE_BASE, R6XX_HDP_LOCATION(Address));
}
#endif /* NOTYET */

/*
 *
 */
static void
R700MCSave(struct rhdMC *MC)
{
    MC->FbLocation = RHDRegRead(MC, R7XX_MC_VM_FB_LOCATION);
    MC->HdpFbAddress = RHDRegRead(MC, R6XX_HDP_NONSURFACE_BASE);
}

/*
 *
 */
static void
R700MCRestore(struct rhdMC *MC)
{
    RHDFUNC(MC);

    RHDRegWrite(MC, R7XX_MC_VM_FB_LOCATION, MC->FbLocation);
    RHDRegWrite(MC, R6XX_HDP_NONSURFACE_BASE, MC->HdpFbAddress);
}

/*
 * Idle is the R600 one...
 */

/*
 *
 */
static CARD64
R700MCGetFBLocation(struct rhdMC *MC, CARD32 *Size)
{
    return R6xxMCGetFBLocation(RHDRegRead(MC, R7XX_MC_VM_FB_LOCATION), Size);
}

/*
 *
 */
static void
R700MCSetupFBLocation(struct rhdMC *MC, CARD64 Address, CARD32 Size)
{
    RHDRegWrite(MC, R7XX_MC_VM_FB_LOCATION, R6XX_FB_LOCATION(Address, Size));
    RHDRegWrite(MC, R6XX_HDP_NONSURFACE_BASE, R6XX_HDP_LOCATION(Address));
}


/*
 *
 */
void
RHDMCInit(RHDPtr rhdPtr)
{
    struct rhdMC *MC;

    RHDFUNC(rhdPtr);

    /* These devices have an internal address reference, which some other
     * address registers in there also use. This can be different from the
     * address in the BAR.
     *
     * We read out the address here from some known location. This address
     * is as good a guess as any, we just need to pick one, but then make
     * sure that it is made consistent in MCSetupFBLocation and the various MC
     * accessing subsystems.
     */

    RHDDebug(rhdPtr->scrnIndex, "MC FB Address: 0x%08X.\n",
	     rhdPtr->FbIntAddress);

    MC = xnfcalloc(1, sizeof(struct rhdMC));
    MC->scrnIndex = rhdPtr->scrnIndex;

    if (rhdPtr->ChipSet < RHD_RS600) {
	switch(rhdPtr->ChipSet) {
	case RHD_RV515:
	case RHD_RV505:
	case RHD_RV516:
	case RHD_RV550:
	case RHD_M52:
	case RHD_M54:
	case RHD_M62:
	case RHD_M64:
	case RHD_M71:
	    MC->Save = RV515MCSave;
	    MC->Restore = RV515MCRestore;
	    MC->SetupFBLocation = RV515MCSetupFBLocation;
	    MC->GetFBLocation = RV515MCGetFBLocation;
	    MC->Idle = RV515MCWaitIdle;
	    MC->TuneAccessForDisplay = RV515MCTuneMCAccessForDisplay;
	    break;
	default:
	    MC->Save = R500MCSave;
	    MC->Restore = R500MCRestore;
	    MC->SetupFBLocation = R500MCSetupFBLocation;
	    MC->GetFBLocation = R500MCGetFBLocation;
	    MC->Idle = R500MCWaitIdle;
	    break;
	}
    } else if (rhdPtr->ChipSet == RHD_RS600) {
	MC->Save = RS600MCSave;
	MC->Restore = RS600MCRestore;
	MC->SetupFBLocation = RS600MCSetupFBLocation;
	MC->Idle = RS600MCWaitIdle;
	MC->GetFBLocation = RS600MCGetFBLocation;
    } else if (rhdPtr->ChipSet < RHD_R600) {
	MC->Save = RS690MCSave;
	MC->Restore = RS690MCRestore;
	MC->SetupFBLocation = RS690MCSetupFBLocation;
	MC->Idle = RS690MCWaitIdle;
	MC->GetFBLocation = RS690MCGetFBLocation;
	MC->TuneAccessForDisplay = RS690MCTuneMCAccessForDisplay;
    } else if (rhdPtr->ChipSet <= RHD_RS880) {
	MC->Save = R600MCSave;
	MC->Restore = R600MCRestore;
	MC->SetupFBLocation = R600MCSetupFBLocation;
	MC->Idle = R600MCWaitIdle;
	MC->GetFBLocation = R600MCGetFBLocation;
    }
#ifdef NOTYET
    else if (rhdPtr->ChipSet == RHD_RS880) {
	MC->Save = RS780MCSave;
	MC->Restore = RS780MCRestore;
	MC->SetupFBLocation = RS780MCSetupFBLocation;
	MC->Idle = RS780MCWaitIdle;
	MC->GetFBLocation = RS780MCGetFBLocation;
    }
#endif /* NOTYET */
    else if (rhdPtr->ChipSet >= RHD_RV770) {
	MC->Save = R700MCSave;
	MC->Restore = R700MCRestore;
	MC->SetupFBLocation = R700MCSetupFBLocation;
	MC->Idle = R600MCWaitIdle;
	MC->GetFBLocation = R700MCGetFBLocation;
    } else {
	xf86DrvMsg(rhdPtr->scrnIndex, X_ERROR, "I don't know anything about MC on this chipset\n");
	xfree(MC);
	return;
    }
    if (rhdPtr->ChipSet < RHD_R600)
	rhdPtr->FbIntAddress = RHDRegRead(rhdPtr, HDP_FB_LOCATION) << 16;
    else
	rhdPtr->FbIntAddress = RHDRegRead(rhdPtr, R6XX_CONFIG_FB_BASE);
    MC->GetFBLocation(MC, &rhdPtr->FbIntSize);

    rhdPtr->MC = MC;

}

/*
 * Free structure.
 */
void
RHDMCDestroy(RHDPtr rhdPtr)
{
    RHDFUNC(rhdPtr);

    if (!rhdPtr->MC)
	return;

    xfree(rhdPtr->MC);
    rhdPtr->MC = NULL;
}

/*
 *
 */
void
RHDMCSave(RHDPtr rhdPtr)
{
    struct rhdMC *MC = rhdPtr->MC;

    ASSERT(MC);

    RHDFUNC(rhdPtr);

    MC->Save(MC);

    MC->Stored = TRUE;
}

/*
 * Make sure that nothing is accessing memory anymore before calling this.
 */
void
RHDMCRestore(RHDPtr rhdPtr)
{
    struct rhdMC *MC = rhdPtr->MC;

    ASSERT(MC);
    RHD_UNSETDEBUGFLAG(rhdPtr, MC_SETUP);

    RHDFUNC(rhdPtr);

    if (!MC->Stored) {
	xf86DrvMsg(rhdPtr->scrnIndex, X_ERROR,
		   "%s: trying to restore uninitialized values.\n",__func__);
	return;
    }

    if (MC->Idle(MC))
	MC->Restore(MC);
    else
	xf86DrvMsg(rhdPtr->scrnIndex, X_ERROR,
		   "%s: MC is still not idle!!!\n", __func__);
}

/*
 *
 */
Bool
RHDMCIdleWait(RHDPtr rhdPtr, CARD32 count)
{
    struct rhdMC *MC = rhdPtr->MC;

    RHDFUNC(rhdPtr);

    ASSERT(MC);

    do {
	if (MC->Idle(MC))
	    return TRUE;
	usleep(1000);
    } while (count--);

    RHDDebug(rhdPtr->scrnIndex, "%s: MC not idle\n",__func__);

    return FALSE;
}

/*
 * Get FB location and size.
 */
CARD64
RHDMCGetFBLocation(RHDPtr rhdPtr, CARD32 *size)
{
    struct rhdMC *MC = rhdPtr->MC;

    ASSERT(MC);
    ASSERT(size);

    RHDFUNC(rhdPtr);

    return MC->GetFBLocation(MC, size);
}

/*
 * Make sure that nothing is accessing memory anymore before calling this.
 */
Bool
RHDMCSetupFBLocation(RHDPtr rhdPtr, CARD64 Address, CARD32 Size)
{
    struct rhdMC *MC = rhdPtr->MC;
    CARD64 OldAddress;
    CARD32 OldSize;

    ASSERT(MC);
    RHD_SETDEBUGFLAG(rhdPtr, MC_SETUP);

    RHDFUNC(rhdPtr);

    if (!MC->Idle(MC)) {
	xf86DrvMsg(rhdPtr->scrnIndex, X_ERROR,
		   "%s: Cannot setup MC: not idle!!!\n", __func__);
	return FALSE;
    }

    OldAddress = MC->GetFBLocation(MC, &OldSize);
    if (OldAddress == Address && OldSize == Size)
	return TRUE;

    /* If this ever occurs, we might have issues */
    if (OldAddress >> 32)
	xf86DrvMsg(rhdPtr->scrnIndex, X_WARNING, "%s: Board claims to use a "
		   "higher than 32bit address for its FB\n", __func__);

    RHDDebug(rhdPtr->scrnIndex,
	     "Setting MC from 0x%08X to 0x%08X [Size 0x%08X]\n",
	     OldAddress, rhdPtr->FbIntAddress, Size);

    MC->SetupFBLocation(MC, Address, Size);

    return TRUE;
}

/*
 *
 */
void
RHDMCTuneAccessForDisplay(RHDPtr rhdPtr, int Crtc,
		    DisplayModePtr Mode, DisplayModePtr ScaledToMode)
{
    struct rhdMC *MC = rhdPtr->MC;

    ASSERT(MC);

    RHDFUNC(rhdPtr);

    if (MC->TuneAccessForDisplay)
	MC->TuneAccessForDisplay(MC, Crtc, Mode, ScaledToMode);
}

/*
 *
 */
Bool
RHD_MC_IGP_SideportMemoryPresent(RHDPtr rhdPtr)
{
    Bool Present = FALSE;

    RHDFUNC(rhdPtr);

    switch (rhdPtr->ChipSet) {
	case RHD_RS690:
	case RHD_RS740:
	    Present = (RHDReadMC(rhdPtr, RS69_MC_MISC_UMA_CNTL) & RS69_SIDE_PORT_PRESENT_R) != 0;
	    break;
	case RHD_RS780:
	    Present = (RHDReadMC(rhdPtr, RS78_MC_MISC_UMA_CNTL) & RS78_SIDE_PORT_PRESENT_R) != 0;
	    break;
	default:
	    break;
    }
    xf86DrvMsg(rhdPtr->scrnIndex, X_INFO, "IGP sideport memory %s present.\n", Present ? "" : "not");

    return Present;
}