mesa: simplify dependencies in mmakefiles
[AROS.git] / workbench / hidds / agp / sisbridgedeviceclass.c
blob13aff3c0b717b53707a4645a1955fe5d6d936ae6
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_SIS_GATT_BASE 0x90
18 #define AGP_SIS_APER_SIZE 0x94
19 #define AGP_SIS_GATT_CNTRL 0x97
20 #define AGP_SIS_GATT_FLUSH 0x98
22 /* NON-PUBLIC METHODS */
23 VOID METHOD(SiSBridgeDevice, Hidd_AGPBridgeDevice, FlushGattTable)
25 struct HIDDGenericBridgeDeviceData * gbddata =
26 OOP_INST_DATA(SD(cl)->genericBridgeDeviceClass, o);
28 OOP_Object * bridgedev = gbddata->bridge->PciDevice;
29 writeconfigbyte(bridgedev, AGP_SIS_GATT_FLUSH, 0x02);
32 /* PUBLIC METHODS */
33 OOP_Object * METHOD(SiSBridgeDevice, Root, New)
35 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
37 return o;
40 VOID SiSBridgeDevice__Root__Dispose(OOP_Class * cl, OOP_Object * o, OOP_Msg msg)
42 struct HIDDGenericBridgeDeviceData * gbddata =
43 OOP_INST_DATA(SD(cl)->genericBridgeDeviceClass, o);
45 if (gbddata->state != STATE_UNKNOWN)
47 OOP_Object * bridgedev = gbddata->bridge->PciDevice;
48 UBYTE temp = 0;
50 /* Disable GART */
51 temp = readconfigbyte(bridgedev, AGP_SIS_APER_SIZE);
52 writeconfigbyte(bridgedev, AGP_SIS_APER_SIZE, temp & ~3);
54 /* Disable GATT */
55 writeconfigbyte(bridgedev, AGP_SIS_GATT_CNTRL, 0x00);
58 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
61 BOOL METHOD(SiSBridgeDevice, Hidd_AGPBridgeDevice, Initialize)
63 struct HIDDGenericBridgeDeviceData * gbddata =
64 OOP_INST_DATA(SD(cl)->genericBridgeDeviceClass, o);
66 struct pHidd_AGPBridgeDevice_ScanAndDetectDevices saddmsg = {
67 mID: OOP_GetMethodID(IID_Hidd_AGPBridgeDevice, moHidd_AGPBridgeDevice_ScanAndDetectDevices)
70 ULONG major, minor = 0;
71 OOP_Object * bridgedev = NULL;
72 UBYTE bridgeagpcap = 0;
73 UBYTE aperture_size_value = 0;
74 UBYTE temp = 0;
77 /* Scan for bridge and agp devices */
78 if (!OOP_DoMethod(o, (OOP_Msg)&saddmsg))
79 return FALSE;
81 /* Check if bridge is a supported SiS bridge */
82 if (gbddata->bridge->VendorID != 0x1039)
83 return FALSE;
85 /* Check if version is at least 3.5 */
86 bridgedev = gbddata->bridge->PciDevice;
87 bridgeagpcap = gbddata->bridge->AgpCapability;
89 /* Getting version info */
90 major = (readconfigbyte(bridgedev, bridgeagpcap + AGP_VERSION_REG) >> 4) & 0xf;
91 minor = readconfigbyte(bridgedev, bridgeagpcap + AGP_VERSION_REG) & 0xf;
92 D(bug("[AGP] [SiS] Read config: AGP version %d.%d\n", major, minor));
94 /* In case of SiS only 3.5 bridges are guaranteed to be AGP3 compliant */
95 if (((major == 3) && (minor >= 5)))
96 return FALSE;
98 /* Getting mode */
99 gbddata->bridgemode = readconfiglong(bridgedev, bridgeagpcap + AGP_STATUS_REG);
100 D(bug("[AGP] [SiS] Reading mode: 0x%x\n", gbddata->bridgemode));
104 /* Initialize */
106 /* Getting GART size */
107 aperture_size_value = readconfigbyte(bridgedev, AGP_SIS_APER_SIZE);
108 D(bug("[AGP] [SIS] Reading aperture size value: %x\n", aperture_size_value));
110 switch(aperture_size_value & ~(0x07))
112 case( 3 & ~(0x07)): gbddata->bridgeapersize = 4; break;
113 case(19 & ~(0x07)): gbddata->bridgeapersize = 8; break;
114 case(35 & ~(0x07)): gbddata->bridgeapersize = 16; break;
115 case(51 & ~(0x07)): gbddata->bridgeapersize = 32; break;
116 case(67 & ~(0x07)): gbddata->bridgeapersize = 64; break;
117 case(83 & ~(0x07)): gbddata->bridgeapersize = 128; break;
118 case(99 & ~(0x07)): gbddata->bridgeapersize = 256; break;
119 default: gbddata->bridgeapersize = 0; break;
122 D(bug("[AGP] [SIS] Calculated aperture size: %d MB\n", (ULONG)gbddata->bridgeapersize));
124 /* Creation of GATT table */
125 struct pHidd_AGPBridgeDevice_CreateGattTable cgtmsg = {
126 mID: OOP_GetMethodID(IID_Hidd_AGPBridgeDevice, moHidd_AGPBridgeDevice_CreateGattTable)
128 if (!OOP_DoMethod(o, (OOP_Msg)&cgtmsg))
129 return FALSE;
131 /* Getting GART base */
132 gbddata->bridgeaperbase = (IPTR)readconfiglong(bridgedev, AGP_APER_BASE);
133 gbddata->bridgeaperbase &= (~0x0fUL) /* PCI_BASE_ADDRESS_MEM_MASK */;
134 D(bug("[AGP] [SiS] Reading aperture base: 0x%x\n", (ULONG)gbddata->bridgeaperbase));
136 /* Set GATT pointer */
137 writeconfiglong(bridgedev, AGP_SIS_GATT_BASE, (ULONG)(IPTR)gbddata->gatttable);
138 D(bug("[AGP] [SiS] Set GATT pointer to 0x%x\n", (ULONG)(IPTR)gbddata->gatttable));
140 /* Enable GART */
141 temp = readconfigbyte(bridgedev, AGP_SIS_APER_SIZE);
142 writeconfigbyte(bridgedev, AGP_SIS_APER_SIZE, temp | 3);
144 /* Enable GATT */
145 writeconfigbyte(bridgedev, AGP_SIS_GATT_CNTRL, 0x05);
147 gbddata->state = STATE_INITIALIZED;
149 return TRUE;