Added a test for MUIA_Listview_SelectChange.
[AROS.git] / workbench / hidds / agp / viaagp3bridgedeviceclass.c
blobed0a7eb1d1a54ff8f3c2de8a56ff2f7efc2bfffa
1 /*
2 Copyright 2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <hidd/agp.h>
7 #include <proto/oop.h>
8 #include <proto/exec.h>
9 #define DEBUG 0
10 #include <aros/debug.h>
12 #include "agp_private.h"
14 #undef HiddAGPBridgeDeviceAttrBase
15 #define HiddAGPBridgeDeviceAttrBase (SD(cl)->hiddAGPBridgeDeviceAB)
17 #define AGP_VIA_SEL 0xfd
18 #define AGP_VIA_AGP3_GART_CTRL 0x90
19 #define AGP_VIA_AGP3_APER_SIZE 0x94
20 #define AGP_VIA_AGP3_GATT_BASE 0x98
22 /* NON-PUBLIC METHODS */
23 VOID METHOD(VIAAgp3BridgeDevice, Hidd_AGPBridgeDevice, FlushGattTable)
25 struct HIDDGenericBridgeDeviceData * gbddata =
26 OOP_INST_DATA(SD(cl)->genericBridgeDeviceClass, o);
28 OOP_Object * bridgedev = gbddata->bridge->PciDevice;
29 ULONG ctrlreg;
30 ctrlreg = readconfiglong(bridgedev, AGP_VIA_AGP3_GART_CTRL);
31 writeconfiglong(bridgedev, AGP_VIA_AGP3_GART_CTRL, ctrlreg & ~(1<<7));
32 writeconfiglong(bridgedev, AGP_VIA_AGP3_GART_CTRL, ctrlreg);
35 /* PUBLIC METHODS */
36 OOP_Object * METHOD(VIAAgp3BridgeDevice, Root, New)
38 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
40 return o;
43 VOID VIAAgp3BridgeDevice__Root__Dispose(OOP_Class * cl, OOP_Object * o, OOP_Msg msg)
45 /* NO OP */
47 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
50 BOOL METHOD(VIAAgp3BridgeDevice, Hidd_AGPBridgeDevice, Initialize)
52 struct HIDDGenericBridgeDeviceData * gbddata =
53 OOP_INST_DATA(SD(cl)->genericBridgeDeviceClass, o);
55 struct pHidd_AGPBridgeDevice_ScanAndDetectDevices saddmsg = {
56 mID: OOP_GetMethodID(IID_Hidd_AGPBridgeDevice, moHidd_AGPBridgeDevice_ScanAndDetectDevices)
59 ULONG major;
60 D(ULONG minor);
61 OOP_Object * bridgedev = NULL;
62 UBYTE bridgeagpcap = 0;
63 UWORD aperture_size_value = 0;
64 ULONG ctrlreg = 0;
66 /* Scan for bridge and agp devices */
67 if (!OOP_DoMethod(o, (OOP_Msg)&saddmsg))
68 return FALSE;
70 /* Check if bridge is a supported VIA bridge */
71 if (gbddata->bridge->VendorID != 0x1106)
72 return FALSE;
74 bridgedev = gbddata->bridge->PciDevice;
75 bridgeagpcap = gbddata->bridge->AgpCapability;
77 /* Getting version info */
78 major = (readconfigbyte(bridgedev, bridgeagpcap + AGP_VERSION_REG) >> 4) & 0xf;
79 D(minor = readconfigbyte(bridgedev, bridgeagpcap + AGP_VERSION_REG) & 0xf);
81 D(bug("[AGP] [VIA] Read config: AGP version %d.%d\n", major, minor));
83 /* Getting mode */
84 gbddata->bridgemode = readconfiglong(bridgedev, bridgeagpcap + AGP_STATUS_REG);
86 D(bug("[AGP] [VIA] Reading mode: 0x%x\n", gbddata->bridgemode));
88 if (major >= 3)
90 /* VIA AGP3 chipsets emulate pre 3.0 if in legacy mode */
92 UBYTE reg = 0;
93 reg = readconfigbyte(bridgedev, AGP_VIA_SEL);
94 if ((reg & (1<<1)) == 0)
96 D(bug("[AGP] [VIA] 3.0 chipset working in 3.0 mode\n"));
98 else
100 D(bug("[AGP] [VIA] 3.0 chipset working in 2.0 emulation mode\n"));
101 return FALSE;
104 else
106 return FALSE;
111 /* Initialize */
114 /* Getting GART size */
115 aperture_size_value = readconfigword(bridgedev, AGP_VIA_AGP3_APER_SIZE);
116 aperture_size_value &= 0xfff;
117 D(bug("[AGP] [VIA] Reading aperture size value: %x\n", aperture_size_value));
119 switch(aperture_size_value)
121 case(0xf3f): gbddata->bridgeapersize = 4; break;
122 case(0xf3e): gbddata->bridgeapersize = 8; break;
123 case(0xf3c): gbddata->bridgeapersize = 16; break;
124 case(0xf38): gbddata->bridgeapersize = 32; break;
125 case(0xf30): gbddata->bridgeapersize = 64; break;
126 case(0xf20): gbddata->bridgeapersize = 128; break;
127 case(0xf00): gbddata->bridgeapersize = 256; break;
128 case(0xe00): gbddata->bridgeapersize = 512; break;
129 case(0xc00): gbddata->bridgeapersize = 1024; break;
130 case(0x800): gbddata->bridgeapersize = 2048; break;
131 default: gbddata->bridgeapersize = 0; break;
134 D(bug("[AGP] [VIA] Calculated aperture size: %d MB\n", (ULONG)gbddata->bridgeapersize));
136 /* Creation of GATT table */
137 struct pHidd_AGPBridgeDevice_CreateGattTable cgtmsg = {
138 mID: OOP_GetMethodID(IID_Hidd_AGPBridgeDevice, moHidd_AGPBridgeDevice_CreateGattTable)
140 if (!OOP_DoMethod(o, (OOP_Msg)&cgtmsg))
141 return FALSE;
143 /* Getting GART base */
144 gbddata->bridgeaperbase = (IPTR)readconfiglong(bridgedev, AGP_APER_BASE);
145 gbddata->bridgeaperbase &= (~0x0fUL) /* PCI_BASE_ADDRESS_MEM_MASK */;
146 D(bug("[AGP] [VIA] Reading aperture base: 0x%x\n", (ULONG)gbddata->bridgeaperbase));
148 /* Set GATT pointer */
149 writeconfiglong(bridgedev, AGP_VIA_AGP3_GATT_BASE,
150 ((ULONG)(IPTR)gbddata->gatttable) & 0xfffff000);
151 D(bug("[AGP] [VIA] Set GATT pointer to 0x%x\n",
152 ((ULONG)(IPTR)gbddata->gatttable) & 0xfffff000));
154 /* Enabled GART and GATT */
155 /* 1. Enable GTLB in RX90<7>, all AGP aperture access needs to fetch
156 * translation table first.
157 * 2. Enable AGP aperture in RX91<0>. This bit controls the enabling of the
158 * graphics AGP aperture for the AGP3.0 port.
161 ctrlreg = readconfiglong(bridgedev, AGP_VIA_AGP3_GART_CTRL);
162 writeconfiglong(bridgedev, AGP_VIA_AGP3_GART_CTRL,
163 ctrlreg | (3<<7));
165 D(bug("[AGP] [VIA] Enabled GART and GATT\n"));
167 gbddata->state = STATE_INITIALIZED;
169 return TRUE;