Added a test for MUIA_Listview_SelectChange.
[AROS.git] / workbench / hidds / agp / viabridgedeviceclass.c
blobb68e3f989290a8245ff6b5cdf8ab8d98c1ea2bdc
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_GART_CTRL 0x80
19 #define AGP_VIA_APER_SIZE 0x84
20 #define AGP_VIA_GATT_BASE 0x88
23 /* NON-PUBLIC METHODS */
24 VOID METHOD(VIABridgeDevice, Hidd_AGPBridgeDevice, FlushGattTable)
26 struct HIDDGenericBridgeDeviceData * gbddata =
27 OOP_INST_DATA(SD(cl)->genericBridgeDeviceClass, o);
29 OOP_Object * bridgedev = gbddata->bridge->PciDevice;
30 ULONG ctrlreg;
31 ctrlreg = readconfiglong(bridgedev, AGP_VIA_GART_CTRL);
32 ctrlreg |= (1<<7);
33 writeconfiglong(bridgedev, AGP_VIA_GART_CTRL, ctrlreg);
34 ctrlreg &= ~(1<<7);
35 writeconfiglong(bridgedev, AGP_VIA_GART_CTRL, ctrlreg);
39 /* PUBLIC METHODS */
40 OOP_Object * METHOD(VIABridgeDevice, Root, New)
42 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
44 return o;
47 VOID VIABridgeDevice__Root__Dispose(OOP_Class * cl, OOP_Object * o, OOP_Msg msg)
49 /* NO OP */
51 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
54 BOOL METHOD(VIABridgeDevice, Hidd_AGPBridgeDevice, Initialize)
56 struct HIDDGenericBridgeDeviceData * gbddata =
57 OOP_INST_DATA(SD(cl)->genericBridgeDeviceClass, o);
59 struct pHidd_AGPBridgeDevice_ScanAndDetectDevices saddmsg = {
60 mID: OOP_GetMethodID(IID_Hidd_AGPBridgeDevice, moHidd_AGPBridgeDevice_ScanAndDetectDevices)
63 ULONG major;
64 D(ULONG minor;)
65 OOP_Object * bridgedev = NULL;
66 UBYTE bridgeagpcap = 0;
67 UBYTE aperture_size_value = 0;
70 /* Scan for bridge and agp devices */
71 if (!OOP_DoMethod(o, (OOP_Msg)&saddmsg))
72 return FALSE;
74 /* Check if bridge is a supported VIA bridge */
75 if (gbddata->bridge->VendorID != 0x1106)
76 return FALSE;
78 bridgedev = gbddata->bridge->PciDevice;
79 bridgeagpcap = gbddata->bridge->AgpCapability;
81 /* Getting version info */
82 major = (readconfigbyte(bridgedev, bridgeagpcap + AGP_VERSION_REG) >> 4) & 0xf;
83 D(minor = readconfigbyte(bridgedev, bridgeagpcap + AGP_VERSION_REG) & 0xf);
85 D(bug("[AGP] [VIA] Read config: AGP version %d.%d\n", major, minor));
87 /* Getting mode */
88 gbddata->bridgemode = readconfiglong(bridgedev, bridgeagpcap + AGP_STATUS_REG);
90 D(bug("[AGP] [VIA] Reading mode: 0x%x\n", gbddata->bridgemode));
92 if (major >= 3)
94 /* VIA AGP3 chipsets emulate pre 3.0 if in legacy mode */
96 UBYTE reg = 0;
97 reg = readconfigbyte(bridgedev, AGP_VIA_SEL);
98 if ((reg & (1<<1)) == 0)
100 D(bug("[AGP] [VIA] 3.0 chipset working in 3.0 mode\n"));
101 return FALSE;
103 else
105 D(bug("[AGP] [VIA] 3.0 chipset working in 2.0 emulation mode\n"));
110 /* Initialize */
113 /* Getting GART size */
114 aperture_size_value = readconfigbyte(bridgedev, AGP_VIA_APER_SIZE);
115 D(bug("[AGP] [VIA] Reading aperture size value: %x\n", aperture_size_value));
117 switch(aperture_size_value)
119 case(255): gbddata->bridgeapersize = 1; break;
120 case(254): gbddata->bridgeapersize = 2; break;
121 case(252): gbddata->bridgeapersize = 4; break;
122 case(248): gbddata->bridgeapersize = 8; break;
123 case(240): gbddata->bridgeapersize = 16; break;
124 case(224): gbddata->bridgeapersize = 32; break;
125 case(192): gbddata->bridgeapersize = 64; break;
126 case(128): gbddata->bridgeapersize = 128; break;
127 case(0): gbddata->bridgeapersize = 256; break;
128 default: gbddata->bridgeapersize = 0; break;
131 D(bug("[AGP] [VIA] Calculated aperture size: %d MB\n", (ULONG)gbddata->bridgeapersize));
133 /* Creation of GATT table */
134 struct pHidd_AGPBridgeDevice_CreateGattTable cgtmsg = {
135 mID: OOP_GetMethodID(IID_Hidd_AGPBridgeDevice, moHidd_AGPBridgeDevice_CreateGattTable)
137 if (!OOP_DoMethod(o, (OOP_Msg)&cgtmsg))
138 return FALSE;
140 /* Getting GART base */
141 gbddata->bridgeaperbase = (IPTR)readconfiglong(bridgedev, AGP_APER_BASE);
142 gbddata->bridgeaperbase &= (~0x0fUL) /* PCI_BASE_ADDRESS_MEM_MASK */;
143 D(bug("[AGP] [VIA] Reading aperture base: 0x%x\n", (ULONG)gbddata->bridgeaperbase));
145 /* GART control register */
146 writeconfiglong(bridgedev, AGP_VIA_GART_CTRL, 0x0000000f);
148 /* Set GATT pointer */
149 writeconfiglong(bridgedev, AGP_VIA_GATT_BASE,
150 (((ULONG)(IPTR)gbddata->gatttable) & 0xfffff000) | 3);
151 D(bug("[AGP] [VIA] Set GATT pointer to 0x%x\n",
152 (((ULONG)(IPTR)gbddata->gatttable) & 0xfffff000) | 3));
154 gbddata->state = STATE_INITIALIZED;
156 return TRUE;