aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcin Koƛcielnicki <koriakin@0x04.net>2009-12-14 19:37:31 -0500
committerBen Skeggs <bskeggs@redhat.com>2009-12-16 02:05:02 -0500
commit37383650e4f47aef633055e3f62e87a44d83312d (patch)
treeb689fe8dd744b94755f0e991573046a228f5e4ff
parent657b6245ba23d32c7a4fd273549c8c0beebec770 (diff)
drm/nouveau: Kill global state in BIOS script interpreter
Signed-off-by: Marcin Koƛcielnicki <koriakin@0x04.net> Signed-off-by: Maarten Maathuis <madman2003@gmail.com> Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.c562
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.h1
2 files changed, 276 insertions, 287 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index 519faa955045..ba143972769f 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -256,10 +256,7 @@ static bool NVShadowVBIOS(struct drm_device *dev, uint8_t *data)
256struct init_tbl_entry { 256struct init_tbl_entry {
257 char *name; 257 char *name;
258 uint8_t id; 258 uint8_t id;
259 int length; 259 int (*handler)(struct nvbios *, uint16_t, struct init_exec *);
260 int length_offset;
261 int length_multiplier;
262 bool (*handler)(struct nvbios *, uint16_t, struct init_exec *);
263}; 260};
264 261
265struct bit_entry { 262struct bit_entry {
@@ -815,7 +812,7 @@ static uint32_t get_tmds_index_reg(struct drm_device *dev, uint8_t mlv)
815 } 812 }
816} 813}
817 814
818static bool 815static int
819init_io_restrict_prog(struct nvbios *bios, uint16_t offset, 816init_io_restrict_prog(struct nvbios *bios, uint16_t offset,
820 struct init_exec *iexec) 817 struct init_exec *iexec)
821{ 818{
@@ -847,9 +844,10 @@ init_io_restrict_prog(struct nvbios *bios, uint16_t offset,
847 uint32_t reg = ROM32(bios->data[offset + 7]); 844 uint32_t reg = ROM32(bios->data[offset + 7]);
848 uint8_t config; 845 uint8_t config;
849 uint32_t configval; 846 uint32_t configval;
847 int len = 11 + count * 4;
850 848
851 if (!iexec->execute) 849 if (!iexec->execute)
852 return true; 850 return len;
853 851
854 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, " 852 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
855 "Shift: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n", 853 "Shift: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n",
@@ -860,7 +858,7 @@ init_io_restrict_prog(struct nvbios *bios, uint16_t offset,
860 NV_ERROR(bios->dev, 858 NV_ERROR(bios->dev,
861 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", 859 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
862 offset, config, count); 860 offset, config, count);
863 return false; 861 return 0;
864 } 862 }
865 863
866 configval = ROM32(bios->data[offset + 11 + config * 4]); 864 configval = ROM32(bios->data[offset + 11 + config * 4]);
@@ -869,10 +867,10 @@ init_io_restrict_prog(struct nvbios *bios, uint16_t offset,
869 867
870 bios_wr32(bios, reg, configval); 868 bios_wr32(bios, reg, configval);
871 869
872 return true; 870 return len;
873} 871}
874 872
875static bool 873static int
876init_repeat(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 874init_repeat(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
877{ 875{
878 /* 876 /*
@@ -907,10 +905,10 @@ init_repeat(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
907 905
908 iexec->repeat = false; 906 iexec->repeat = false;
909 907
910 return true; 908 return 2;
911} 909}
912 910
913static bool 911static int
914init_io_restrict_pll(struct nvbios *bios, uint16_t offset, 912init_io_restrict_pll(struct nvbios *bios, uint16_t offset,
915 struct init_exec *iexec) 913 struct init_exec *iexec)
916{ 914{
@@ -946,9 +944,10 @@ init_io_restrict_pll(struct nvbios *bios, uint16_t offset,
946 uint32_t reg = ROM32(bios->data[offset + 8]); 944 uint32_t reg = ROM32(bios->data[offset + 8]);
947 uint8_t config; 945 uint8_t config;
948 uint16_t freq; 946 uint16_t freq;
947 int len = 12 + count * 2;
949 948
950 if (!iexec->execute) 949 if (!iexec->execute)
951 return true; 950 return len;
952 951
953 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, " 952 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
954 "Shift: 0x%02X, IO Flag Condition: 0x%02X, " 953 "Shift: 0x%02X, IO Flag Condition: 0x%02X, "
@@ -961,7 +960,7 @@ init_io_restrict_pll(struct nvbios *bios, uint16_t offset,
961 NV_ERROR(bios->dev, 960 NV_ERROR(bios->dev,
962 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", 961 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
963 offset, config, count); 962 offset, config, count);
964 return false; 963 return 0;
965 } 964 }
966 965
967 freq = ROM16(bios->data[offset + 12 + config * 2]); 966 freq = ROM16(bios->data[offset + 12 + config * 2]);
@@ -981,10 +980,10 @@ init_io_restrict_pll(struct nvbios *bios, uint16_t offset,
981 980
982 setPLL(bios, reg, freq * 10); 981 setPLL(bios, reg, freq * 10);
983 982
984 return true; 983 return len;
985} 984}
986 985
987static bool 986static int
988init_end_repeat(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 987init_end_repeat(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
989{ 988{
990 /* 989 /*
@@ -1002,12 +1001,12 @@ init_end_repeat(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1002 * we're not in repeat mode 1001 * we're not in repeat mode
1003 */ 1002 */
1004 if (iexec->repeat) 1003 if (iexec->repeat)
1005 return false; 1004 return 0;
1006 1005
1007 return true; 1006 return 1;
1008} 1007}
1009 1008
1010static bool 1009static int
1011init_copy(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1010init_copy(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1012{ 1011{
1013 /* 1012 /*
@@ -1036,7 +1035,7 @@ init_copy(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1036 uint8_t crtcdata; 1035 uint8_t crtcdata;
1037 1036
1038 if (!iexec->execute) 1037 if (!iexec->execute)
1039 return true; 1038 return 11;
1040 1039
1041 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Shift: 0x%02X, SrcMask: 0x%02X, " 1040 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Shift: 0x%02X, SrcMask: 0x%02X, "
1042 "Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X\n", 1041 "Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X\n",
@@ -1055,10 +1054,10 @@ init_copy(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1055 crtcdata |= (uint8_t)data; 1054 crtcdata |= (uint8_t)data;
1056 bios_idxprt_wr(bios, crtcport, crtcindex, crtcdata); 1055 bios_idxprt_wr(bios, crtcport, crtcindex, crtcdata);
1057 1056
1058 return true; 1057 return 11;
1059} 1058}
1060 1059
1061static bool 1060static int
1062init_not(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1061init_not(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1063{ 1062{
1064 /* 1063 /*
@@ -1074,10 +1073,10 @@ init_not(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1074 BIOSLOG(bios, "0x%04X: ------ Executing following commands ------\n", offset); 1073 BIOSLOG(bios, "0x%04X: ------ Executing following commands ------\n", offset);
1075 1074
1076 iexec->execute = !iexec->execute; 1075 iexec->execute = !iexec->execute;
1077 return true; 1076 return 1;
1078} 1077}
1079 1078
1080static bool 1079static int
1081init_io_flag_condition(struct nvbios *bios, uint16_t offset, 1080init_io_flag_condition(struct nvbios *bios, uint16_t offset,
1082 struct init_exec *iexec) 1081 struct init_exec *iexec)
1083{ 1082{
@@ -1095,7 +1094,7 @@ init_io_flag_condition(struct nvbios *bios, uint16_t offset,
1095 uint8_t cond = bios->data[offset + 1]; 1094 uint8_t cond = bios->data[offset + 1];
1096 1095
1097 if (!iexec->execute) 1096 if (!iexec->execute)
1098 return true; 1097 return 2;
1099 1098
1100 if (io_flag_condition_met(bios, offset, cond)) 1099 if (io_flag_condition_met(bios, offset, cond))
1101 BIOSLOG(bios, "0x%04X: Condition fulfilled -- continuing to execute\n", offset); 1100 BIOSLOG(bios, "0x%04X: Condition fulfilled -- continuing to execute\n", offset);
@@ -1104,10 +1103,10 @@ init_io_flag_condition(struct nvbios *bios, uint16_t offset,
1104 iexec->execute = false; 1103 iexec->execute = false;
1105 } 1104 }
1106 1105
1107 return true; 1106 return 2;
1108} 1107}
1109 1108
1110static bool 1109static int
1111init_idx_addr_latched(struct nvbios *bios, uint16_t offset, 1110init_idx_addr_latched(struct nvbios *bios, uint16_t offset,
1112 struct init_exec *iexec) 1111 struct init_exec *iexec)
1113{ 1112{
@@ -1135,11 +1134,12 @@ init_idx_addr_latched(struct nvbios *bios, uint16_t offset,
1135 uint32_t mask = ROM32(bios->data[offset + 9]); 1134 uint32_t mask = ROM32(bios->data[offset + 9]);
1136 uint32_t data = ROM32(bios->data[offset + 13]); 1135 uint32_t data = ROM32(bios->data[offset + 13]);
1137 uint8_t count = bios->data[offset + 17]; 1136 uint8_t count = bios->data[offset + 17];
1137 int len = 18 + count * 2;
1138 uint32_t value; 1138 uint32_t value;
1139 int i; 1139 int i;
1140 1140
1141 if (!iexec->execute) 1141 if (!iexec->execute)
1142 return true; 1142 return len;
1143 1143
1144 BIOSLOG(bios, "0x%04X: ControlReg: 0x%08X, DataReg: 0x%08X, " 1144 BIOSLOG(bios, "0x%04X: ControlReg: 0x%08X, DataReg: 0x%08X, "
1145 "Mask: 0x%08X, Data: 0x%08X, Count: 0x%02X\n", 1145 "Mask: 0x%08X, Data: 0x%08X, Count: 0x%02X\n",
@@ -1159,10 +1159,10 @@ init_idx_addr_latched(struct nvbios *bios, uint16_t offset,
1159 bios_wr32(bios, controlreg, value); 1159 bios_wr32(bios, controlreg, value);
1160 } 1160 }
1161 1161
1162 return true; 1162 return len;
1163} 1163}
1164 1164
1165static bool 1165static int
1166init_io_restrict_pll2(struct nvbios *bios, uint16_t offset, 1166init_io_restrict_pll2(struct nvbios *bios, uint16_t offset,
1167 struct init_exec *iexec) 1167 struct init_exec *iexec)
1168{ 1168{
@@ -1191,25 +1191,26 @@ init_io_restrict_pll2(struct nvbios *bios, uint16_t offset,
1191 uint8_t shift = bios->data[offset + 5]; 1191 uint8_t shift = bios->data[offset + 5];
1192 uint8_t count = bios->data[offset + 6]; 1192 uint8_t count = bios->data[offset + 6];
1193 uint32_t reg = ROM32(bios->data[offset + 7]); 1193 uint32_t reg = ROM32(bios->data[offset + 7]);
1194 int len = 11 + count * 4;
1194 uint8_t config; 1195 uint8_t config;
1195 uint32_t freq; 1196 uint32_t freq;
1196 1197
1197 if (!iexec->execute) 1198 if (!iexec->execute)
1198 return true; 1199 return len;
1199 1200
1200 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, " 1201 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
1201 "Shift: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n", 1202 "Shift: 0x%02X, Count: 0x%02X, Reg: 0x%08X\n",
1202 offset, crtcport, crtcindex, mask, shift, count, reg); 1203 offset, crtcport, crtcindex, mask, shift, count, reg);
1203 1204
1204 if (!reg) 1205 if (!reg)
1205 return true; 1206 return len;
1206 1207
1207 config = (bios_idxprt_rd(bios, crtcport, crtcindex) & mask) >> shift; 1208 config = (bios_idxprt_rd(bios, crtcport, crtcindex) & mask) >> shift;
1208 if (config > count) { 1209 if (config > count) {
1209 NV_ERROR(bios->dev, 1210 NV_ERROR(bios->dev,
1210 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", 1211 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
1211 offset, config, count); 1212 offset, config, count);
1212 return false; 1213 return 0;
1213 } 1214 }
1214 1215
1215 freq = ROM32(bios->data[offset + 11 + config * 4]); 1216 freq = ROM32(bios->data[offset + 11 + config * 4]);
@@ -1219,10 +1220,10 @@ init_io_restrict_pll2(struct nvbios *bios, uint16_t offset,
1219 1220
1220 setPLL(bios, reg, freq); 1221 setPLL(bios, reg, freq);
1221 1222
1222 return true; 1223 return len;
1223} 1224}
1224 1225
1225static bool 1226static int
1226init_pll2(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1227init_pll2(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1227{ 1228{
1228 /* 1229 /*
@@ -1239,16 +1240,16 @@ init_pll2(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1239 uint32_t freq = ROM32(bios->data[offset + 5]); 1240 uint32_t freq = ROM32(bios->data[offset + 5]);
1240 1241
1241 if (!iexec->execute) 1242 if (!iexec->execute)
1242 return true; 1243 return 9;
1243 1244
1244 BIOSLOG(bios, "0x%04X: Reg: 0x%04X, Freq: %dkHz\n", 1245 BIOSLOG(bios, "0x%04X: Reg: 0x%04X, Freq: %dkHz\n",
1245 offset, reg, freq); 1246 offset, reg, freq);
1246 1247
1247 setPLL(bios, reg, freq); 1248 setPLL(bios, reg, freq);
1248 return true; 1249 return 9;
1249} 1250}
1250 1251
1251static bool 1252static int
1252init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1253init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1253{ 1254{
1254 /* 1255 /*
@@ -1272,12 +1273,13 @@ init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1272 uint8_t i2c_index = bios->data[offset + 1]; 1273 uint8_t i2c_index = bios->data[offset + 1];
1273 uint8_t i2c_address = bios->data[offset + 2]; 1274 uint8_t i2c_address = bios->data[offset + 2];
1274 uint8_t count = bios->data[offset + 3]; 1275 uint8_t count = bios->data[offset + 3];
1276 int len = 4 + count * 3;
1275 struct nouveau_i2c_chan *chan; 1277 struct nouveau_i2c_chan *chan;
1276 struct i2c_msg msg; 1278 struct i2c_msg msg;
1277 int i; 1279 int i;
1278 1280
1279 if (!iexec->execute) 1281 if (!iexec->execute)
1280 return true; 1282 return len;
1281 1283
1282 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, " 1284 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, "
1283 "Count: 0x%02X\n", 1285 "Count: 0x%02X\n",
@@ -1285,7 +1287,7 @@ init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1285 1287
1286 chan = init_i2c_device_find(bios->dev, i2c_index); 1288 chan = init_i2c_device_find(bios->dev, i2c_index);
1287 if (!chan) 1289 if (!chan)
1288 return false; 1290 return 0;
1289 1291
1290 for (i = 0; i < count; i++) { 1292 for (i = 0; i < count; i++) {
1291 uint8_t i2c_reg = bios->data[offset + 4 + i * 3]; 1293 uint8_t i2c_reg = bios->data[offset + 4 + i * 3];
@@ -1298,7 +1300,7 @@ init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1298 msg.len = 1; 1300 msg.len = 1;
1299 msg.buf = &value; 1301 msg.buf = &value;
1300 if (i2c_transfer(&chan->adapter, &msg, 1) != 1) 1302 if (i2c_transfer(&chan->adapter, &msg, 1) != 1)
1301 return false; 1303 return 0;
1302 1304
1303 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: 0x%02X, " 1305 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: 0x%02X, "
1304 "Mask: 0x%02X, Data: 0x%02X\n", 1306 "Mask: 0x%02X, Data: 0x%02X\n",
@@ -1312,14 +1314,14 @@ init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1312 msg.len = 1; 1314 msg.len = 1;
1313 msg.buf = &value; 1315 msg.buf = &value;
1314 if (i2c_transfer(&chan->adapter, &msg, 1) != 1) 1316 if (i2c_transfer(&chan->adapter, &msg, 1) != 1)
1315 return false; 1317 return 0;
1316 } 1318 }
1317 } 1319 }
1318 1320
1319 return true; 1321 return len;
1320} 1322}
1321 1323
1322static bool 1324static int
1323init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1325init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1324{ 1326{
1325 /* 1327 /*
@@ -1341,12 +1343,13 @@ init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1341 uint8_t i2c_index = bios->data[offset + 1]; 1343 uint8_t i2c_index = bios->data[offset + 1];
1342 uint8_t i2c_address = bios->data[offset + 2]; 1344 uint8_t i2c_address = bios->data[offset + 2];
1343 uint8_t count = bios->data[offset + 3]; 1345 uint8_t count = bios->data[offset + 3];
1346 int len = 4 + count * 2;
1344 struct nouveau_i2c_chan *chan; 1347 struct nouveau_i2c_chan *chan;
1345 struct i2c_msg msg; 1348 struct i2c_msg msg;
1346 int i; 1349 int i;
1347 1350
1348 if (!iexec->execute) 1351 if (!iexec->execute)
1349 return true; 1352 return len;
1350 1353
1351 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, " 1354 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, "
1352 "Count: 0x%02X\n", 1355 "Count: 0x%02X\n",
@@ -1354,7 +1357,7 @@ init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1354 1357
1355 chan = init_i2c_device_find(bios->dev, i2c_index); 1358 chan = init_i2c_device_find(bios->dev, i2c_index);
1356 if (!chan) 1359 if (!chan)
1357 return false; 1360 return 0;
1358 1361
1359 for (i = 0; i < count; i++) { 1362 for (i = 0; i < count; i++) {
1360 uint8_t i2c_reg = bios->data[offset + 4 + i * 2]; 1363 uint8_t i2c_reg = bios->data[offset + 4 + i * 2];
@@ -1369,14 +1372,14 @@ init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1369 msg.len = 1; 1372 msg.len = 1;
1370 msg.buf = &data; 1373 msg.buf = &data;
1371 if (i2c_transfer(&chan->adapter, &msg, 1) != 1) 1374 if (i2c_transfer(&chan->adapter, &msg, 1) != 1)
1372 return false; 1375 return 0;
1373 } 1376 }
1374 } 1377 }
1375 1378
1376 return true; 1379 return len;
1377} 1380}
1378 1381
1379static bool 1382static int
1380init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1383init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1381{ 1384{
1382 /* 1385 /*
@@ -1396,13 +1399,14 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1396 uint8_t i2c_index = bios->data[offset + 1]; 1399 uint8_t i2c_index = bios->data[offset + 1];
1397 uint8_t i2c_address = bios->data[offset + 2]; 1400 uint8_t i2c_address = bios->data[offset + 2];
1398 uint8_t count = bios->data[offset + 3]; 1401 uint8_t count = bios->data[offset + 3];
1402 int len = 4 + count;
1399 struct nouveau_i2c_chan *chan; 1403 struct nouveau_i2c_chan *chan;
1400 struct i2c_msg msg; 1404 struct i2c_msg msg;
1401 uint8_t data[256]; 1405 uint8_t data[256];
1402 int i; 1406 int i;
1403 1407
1404 if (!iexec->execute) 1408 if (!iexec->execute)
1405 return true; 1409 return len;
1406 1410
1407 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, " 1411 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X, "
1408 "Count: 0x%02X\n", 1412 "Count: 0x%02X\n",
@@ -1410,7 +1414,7 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1410 1414
1411 chan = init_i2c_device_find(bios->dev, i2c_index); 1415 chan = init_i2c_device_find(bios->dev, i2c_index);
1412 if (!chan) 1416 if (!chan)
1413 return false; 1417 return 0;
1414 1418
1415 for (i = 0; i < count; i++) { 1419 for (i = 0; i < count; i++) {
1416 data[i] = bios->data[offset + 4 + i]; 1420 data[i] = bios->data[offset + 4 + i];
@@ -1424,13 +1428,13 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1424 msg.len = count; 1428 msg.len = count;
1425 msg.buf = data; 1429 msg.buf = data;
1426 if (i2c_transfer(&chan->adapter, &msg, 1) != 1) 1430 if (i2c_transfer(&chan->adapter, &msg, 1) != 1)
1427 return false; 1431 return 0;
1428 } 1432 }
1429 1433
1430 return true; 1434 return len;
1431} 1435}
1432 1436
1433static bool 1437static int
1434init_tmds(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1438init_tmds(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1435{ 1439{
1436 /* 1440 /*
@@ -1455,7 +1459,7 @@ init_tmds(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1455 uint32_t reg, value; 1459 uint32_t reg, value;
1456 1460
1457 if (!iexec->execute) 1461 if (!iexec->execute)
1458 return true; 1462 return 5;
1459 1463
1460 BIOSLOG(bios, "0x%04X: MagicLookupValue: 0x%02X, TMDSAddr: 0x%02X, " 1464 BIOSLOG(bios, "0x%04X: MagicLookupValue: 0x%02X, TMDSAddr: 0x%02X, "
1461 "Mask: 0x%02X, Data: 0x%02X\n", 1465 "Mask: 0x%02X, Data: 0x%02X\n",
@@ -1463,7 +1467,7 @@ init_tmds(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1463 1467
1464 reg = get_tmds_index_reg(bios->dev, mlv); 1468 reg = get_tmds_index_reg(bios->dev, mlv);
1465 if (!reg) 1469 if (!reg)
1466 return false; 1470 return 0;
1467 1471
1468 bios_wr32(bios, reg, 1472 bios_wr32(bios, reg,
1469 tmdsaddr | NV_PRAMDAC_FP_TMDS_CONTROL_WRITE_DISABLE); 1473 tmdsaddr | NV_PRAMDAC_FP_TMDS_CONTROL_WRITE_DISABLE);
@@ -1471,10 +1475,10 @@ init_tmds(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1471 bios_wr32(bios, reg + 4, value); 1475 bios_wr32(bios, reg + 4, value);
1472 bios_wr32(bios, reg, tmdsaddr); 1476 bios_wr32(bios, reg, tmdsaddr);
1473 1477
1474 return true; 1478 return 5;
1475} 1479}
1476 1480
1477static bool 1481static int
1478init_zm_tmds_group(struct nvbios *bios, uint16_t offset, 1482init_zm_tmds_group(struct nvbios *bios, uint16_t offset,
1479 struct init_exec *iexec) 1483 struct init_exec *iexec)
1480{ 1484{
@@ -1495,18 +1499,19 @@ init_zm_tmds_group(struct nvbios *bios, uint16_t offset,
1495 1499
1496 uint8_t mlv = bios->data[offset + 1]; 1500 uint8_t mlv = bios->data[offset + 1];
1497 uint8_t count = bios->data[offset + 2]; 1501 uint8_t count = bios->data[offset + 2];
1502 int len = 3 + count * 2;
1498 uint32_t reg; 1503 uint32_t reg;
1499 int i; 1504 int i;
1500 1505
1501 if (!iexec->execute) 1506 if (!iexec->execute)
1502 return true; 1507 return len;
1503 1508
1504 BIOSLOG(bios, "0x%04X: MagicLookupValue: 0x%02X, Count: 0x%02X\n", 1509 BIOSLOG(bios, "0x%04X: MagicLookupValue: 0x%02X, Count: 0x%02X\n",
1505 offset, mlv, count); 1510 offset, mlv, count);
1506 1511
1507 reg = get_tmds_index_reg(bios->dev, mlv); 1512 reg = get_tmds_index_reg(bios->dev, mlv);
1508 if (!reg) 1513 if (!reg)
1509 return false; 1514 return 0;
1510 1515
1511 for (i = 0; i < count; i++) { 1516 for (i = 0; i < count; i++) {
1512 uint8_t tmdsaddr = bios->data[offset + 3 + i * 2]; 1517 uint8_t tmdsaddr = bios->data[offset + 3 + i * 2];
@@ -1516,10 +1521,10 @@ init_zm_tmds_group(struct nvbios *bios, uint16_t offset,
1516 bios_wr32(bios, reg, tmdsaddr); 1521 bios_wr32(bios, reg, tmdsaddr);
1517 } 1522 }
1518 1523
1519 return true; 1524 return len;
1520} 1525}
1521 1526
1522static bool 1527static int
1523init_cr_idx_adr_latch(struct nvbios *bios, uint16_t offset, 1528init_cr_idx_adr_latch(struct nvbios *bios, uint16_t offset,
1524 struct init_exec *iexec) 1529 struct init_exec *iexec)
1525{ 1530{
@@ -1542,11 +1547,12 @@ init_cr_idx_adr_latch(struct nvbios *bios, uint16_t offset,
1542 uint8_t crtcindex2 = bios->data[offset + 2]; 1547 uint8_t crtcindex2 = bios->data[offset + 2];
1543 uint8_t baseaddr = bios->data[offset + 3]; 1548 uint8_t baseaddr = bios->data[offset + 3];
1544 uint8_t count = bios->data[offset + 4]; 1549 uint8_t count = bios->data[offset + 4];
1550 int len = 5 + count;
1545 uint8_t oldaddr, data; 1551 uint8_t oldaddr, data;
1546 int i; 1552 int i;
1547 1553
1548 if (!iexec->execute) 1554 if (!iexec->execute)
1549 return true; 1555 return len;
1550 1556
1551 BIOSLOG(bios, "0x%04X: Index1: 0x%02X, Index2: 0x%02X, " 1557 BIOSLOG(bios, "0x%04X: Index1: 0x%02X, Index2: 0x%02X, "
1552 "BaseAddr: 0x%02X, Count: 0x%02X\n", 1558 "BaseAddr: 0x%02X, Count: 0x%02X\n",
@@ -1563,10 +1569,10 @@ init_cr_idx_adr_latch(struct nvbios *bios, uint16_t offset,
1563 1569
1564 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex1, oldaddr); 1570 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex1, oldaddr);
1565 1571
1566 return true; 1572 return len;
1567} 1573}
1568 1574
1569static bool 1575static int
1570init_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1576init_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1571{ 1577{
1572 /* 1578 /*
@@ -1587,7 +1593,7 @@ init_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1587 uint8_t value; 1593 uint8_t value;
1588 1594
1589 if (!iexec->execute) 1595 if (!iexec->execute)
1590 return true; 1596 return 4;
1591 1597
1592 BIOSLOG(bios, "0x%04X: Index: 0x%02X, Mask: 0x%02X, Data: 0x%02X\n", 1598 BIOSLOG(bios, "0x%04X: Index: 0x%02X, Mask: 0x%02X, Data: 0x%02X\n",
1593 offset, crtcindex, mask, data); 1599 offset, crtcindex, mask, data);
@@ -1596,10 +1602,10 @@ init_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1596 value |= data; 1602 value |= data;
1597 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex, value); 1603 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex, value);
1598 1604
1599 return true; 1605 return 4;
1600} 1606}
1601 1607
1602static bool 1608static int
1603init_zm_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1609init_zm_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1604{ 1610{
1605 /* 1611 /*
@@ -1616,14 +1622,14 @@ init_zm_cr(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1616 uint8_t data = bios->data[offset + 2]; 1622 uint8_t data = bios->data[offset + 2];
1617 1623
1618 if (!iexec->execute) 1624 if (!iexec->execute)
1619 return true; 1625 return 3;
1620 1626
1621 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex, data); 1627 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, crtcindex, data);
1622 1628
1623 return true; 1629 return 3;
1624} 1630}
1625 1631
1626static bool 1632static int
1627init_zm_cr_group(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1633init_zm_cr_group(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1628{ 1634{
1629 /* 1635 /*
@@ -1640,18 +1646,19 @@ init_zm_cr_group(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1640 */ 1646 */
1641 1647
1642 uint8_t count = bios->data[offset + 1]; 1648 uint8_t count = bios->data[offset + 1];
1649 int len = 2 + count * 2;
1643 int i; 1650 int i;
1644 1651
1645 if (!iexec->execute) 1652 if (!iexec->execute)
1646 return true; 1653 return len;
1647 1654
1648 for (i = 0; i < count; i++) 1655 for (i = 0; i < count; i++)
1649 init_zm_cr(bios, offset + 2 + 2 * i - 1, iexec); 1656 init_zm_cr(bios, offset + 2 + 2 * i - 1, iexec);
1650 1657
1651 return true; 1658 return len;
1652} 1659}
1653 1660
1654static bool 1661static int
1655init_condition_time(struct nvbios *bios, uint16_t offset, 1662init_condition_time(struct nvbios *bios, uint16_t offset,
1656 struct init_exec *iexec) 1663 struct init_exec *iexec)
1657{ 1664{
@@ -1675,7 +1682,7 @@ init_condition_time(struct nvbios *bios, uint16_t offset,
1675 unsigned cnt; 1682 unsigned cnt;
1676 1683
1677 if (!iexec->execute) 1684 if (!iexec->execute)
1678 return true; 1685 return 3;
1679 1686
1680 if (retries > 100) 1687 if (retries > 100)
1681 retries = 100; 1688 retries = 100;
@@ -1706,10 +1713,10 @@ init_condition_time(struct nvbios *bios, uint16_t offset,
1706 iexec->execute = false; 1713 iexec->execute = false;
1707 } 1714 }
1708 1715
1709 return true; 1716 return 3;
1710} 1717}
1711 1718
1712static bool 1719static int
1713init_zm_reg_sequence(struct nvbios *bios, uint16_t offset, 1720init_zm_reg_sequence(struct nvbios *bios, uint16_t offset,
1714 struct init_exec *iexec) 1721 struct init_exec *iexec)
1715{ 1722{
@@ -1729,10 +1736,11 @@ init_zm_reg_sequence(struct nvbios *bios, uint16_t offset,
1729 1736
1730 uint32_t basereg = ROM32(bios->data[offset + 1]); 1737 uint32_t basereg = ROM32(bios->data[offset + 1]);
1731 uint32_t count = bios->data[offset + 5]; 1738 uint32_t count = bios->data[offset + 5];
1739 int len = 6 + count * 4;
1732 int i; 1740 int i;
1733 1741
1734 if (!iexec->execute) 1742 if (!iexec->execute)
1735 return true; 1743 return len;
1736 1744
1737 BIOSLOG(bios, "0x%04X: BaseReg: 0x%08X, Count: 0x%02X\n", 1745 BIOSLOG(bios, "0x%04X: BaseReg: 0x%08X, Count: 0x%02X\n",
1738 offset, basereg, count); 1746 offset, basereg, count);
@@ -1744,10 +1752,10 @@ init_zm_reg_sequence(struct nvbios *bios, uint16_t offset,
1744 bios_wr32(bios, reg, data); 1752 bios_wr32(bios, reg, data);
1745 } 1753 }
1746 1754
1747 return true; 1755 return len;
1748} 1756}
1749 1757
1750static bool 1758static int
1751init_sub_direct(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1759init_sub_direct(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1752{ 1760{
1753 /* 1761 /*
@@ -1763,7 +1771,7 @@ init_sub_direct(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1763 uint16_t sub_offset = ROM16(bios->data[offset + 1]); 1771 uint16_t sub_offset = ROM16(bios->data[offset + 1]);
1764 1772
1765 if (!iexec->execute) 1773 if (!iexec->execute)
1766 return true; 1774 return 3;
1767 1775
1768 BIOSLOG(bios, "0x%04X: Executing subroutine at 0x%04X\n", 1776 BIOSLOG(bios, "0x%04X: Executing subroutine at 0x%04X\n",
1769 offset, sub_offset); 1777 offset, sub_offset);
@@ -1772,10 +1780,10 @@ init_sub_direct(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1772 1780
1773 BIOSLOG(bios, "0x%04X: End of 0x%04X subroutine\n", offset, sub_offset); 1781 BIOSLOG(bios, "0x%04X: End of 0x%04X subroutine\n", offset, sub_offset);
1774 1782
1775 return true; 1783 return 3;
1776} 1784}
1777 1785
1778static bool 1786static int
1779init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1787init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1780{ 1788{
1781 /* 1789 /*
@@ -1803,7 +1811,7 @@ init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1803 uint32_t srcvalue, dstvalue; 1811 uint32_t srcvalue, dstvalue;
1804 1812
1805 if (!iexec->execute) 1813 if (!iexec->execute)
1806 return true; 1814 return 22;
1807 1815
1808 BIOSLOG(bios, "0x%04X: SrcReg: 0x%08X, Shift: 0x%02X, SrcMask: 0x%08X, " 1816 BIOSLOG(bios, "0x%04X: SrcReg: 0x%08X, Shift: 0x%02X, SrcMask: 0x%08X, "
1809 "Xor: 0x%08X, DstReg: 0x%08X, DstMask: 0x%08X\n", 1817 "Xor: 0x%08X, DstReg: 0x%08X, DstMask: 0x%08X\n",
@@ -1822,10 +1830,10 @@ init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1822 1830
1823 bios_wr32(bios, dstreg, dstvalue | srcvalue); 1831 bios_wr32(bios, dstreg, dstvalue | srcvalue);
1824 1832
1825 return true; 1833 return 22;
1826} 1834}
1827 1835
1828static bool 1836static int
1829init_zm_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1837init_zm_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1830{ 1838{
1831 /* 1839 /*
@@ -1843,14 +1851,14 @@ init_zm_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1843 uint8_t data = bios->data[offset + 4]; 1851 uint8_t data = bios->data[offset + 4];
1844 1852
1845 if (!iexec->execute) 1853 if (!iexec->execute)
1846 return true; 1854 return 5;
1847 1855
1848 bios_idxprt_wr(bios, crtcport, crtcindex, data); 1856 bios_idxprt_wr(bios, crtcport, crtcindex, data);
1849 1857
1850 return true; 1858 return 5;
1851} 1859}
1852 1860
1853static bool 1861static int
1854init_compute_mem(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1862init_compute_mem(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1855{ 1863{
1856 /* 1864 /*
@@ -1899,7 +1907,7 @@ init_compute_mem(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1899 struct drm_nouveau_private *dev_priv = bios->dev->dev_private; 1907 struct drm_nouveau_private *dev_priv = bios->dev->dev_private;
1900 1908
1901 if (dev_priv->card_type >= NV_50) 1909 if (dev_priv->card_type >= NV_50)
1902 return true; 1910 return 1;
1903 1911
1904 /* 1912 /*
1905 * On every card I've seen, this step gets done for us earlier in 1913 * On every card I've seen, this step gets done for us earlier in
@@ -1917,10 +1925,10 @@ init_compute_mem(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1917 /* write back the saved configuration value */ 1925 /* write back the saved configuration value */
1918 bios_wr32(bios, NV_PFB_CFG0, bios->state.saved_nv_pfb_cfg0); 1926 bios_wr32(bios, NV_PFB_CFG0, bios->state.saved_nv_pfb_cfg0);
1919 1927
1920 return true; 1928 return 1;
1921} 1929}
1922 1930
1923static bool 1931static int
1924init_reset(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 1932init_reset(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1925{ 1933{
1926 /* 1934 /*
@@ -1954,10 +1962,10 @@ init_reset(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1954 pci_nv_20 &= ~NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED; /* 0xfffffffe */ 1962 pci_nv_20 &= ~NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED; /* 0xfffffffe */
1955 bios_wr32(bios, NV_PBUS_PCI_NV_20, pci_nv_20); 1963 bios_wr32(bios, NV_PBUS_PCI_NV_20, pci_nv_20);
1956 1964
1957 return true; 1965 return 13;
1958} 1966}
1959 1967
1960static bool 1968static int
1961init_configure_mem(struct nvbios *bios, uint16_t offset, 1969init_configure_mem(struct nvbios *bios, uint16_t offset,
1962 struct init_exec *iexec) 1970 struct init_exec *iexec)
1963{ 1971{
@@ -1978,7 +1986,7 @@ init_configure_mem(struct nvbios *bios, uint16_t offset,
1978 uint32_t reg, data; 1986 uint32_t reg, data;
1979 1987
1980 if (bios->major_version > 2) 1988 if (bios->major_version > 2)
1981 return false; 1989 return 0;
1982 1990
1983 bios_idxprt_wr(bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX, bios_idxprt_rd( 1991 bios_idxprt_wr(bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX, bios_idxprt_rd(
1984 bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX) | 0x20); 1992 bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX) | 0x20);
@@ -2010,10 +2018,10 @@ init_configure_mem(struct nvbios *bios, uint16_t offset,
2010 bios_wr32(bios, reg, data); 2018 bios_wr32(bios, reg, data);
2011 } 2019 }
2012 2020
2013 return true; 2021 return 1;
2014} 2022}
2015 2023
2016static bool 2024static int
2017init_configure_clk(struct nvbios *bios, uint16_t offset, 2025init_configure_clk(struct nvbios *bios, uint16_t offset,
2018 struct init_exec *iexec) 2026 struct init_exec *iexec)
2019{ 2027{
@@ -2033,7 +2041,7 @@ init_configure_clk(struct nvbios *bios, uint16_t offset,
2033 int clock; 2041 int clock;
2034 2042
2035 if (bios->major_version > 2) 2043 if (bios->major_version > 2)
2036 return false; 2044 return 0;
2037 2045
2038 clock = ROM16(bios->data[meminitoffs + 4]) * 10; 2046 clock = ROM16(bios->data[meminitoffs + 4]) * 10;
2039 setPLL(bios, NV_PRAMDAC_NVPLL_COEFF, clock); 2047 setPLL(bios, NV_PRAMDAC_NVPLL_COEFF, clock);
@@ -2043,10 +2051,10 @@ init_configure_clk(struct nvbios *bios, uint16_t offset,
2043 clock *= 2; 2051 clock *= 2;
2044 setPLL(bios, NV_PRAMDAC_MPLL_COEFF, clock); 2052 setPLL(bios, NV_PRAMDAC_MPLL_COEFF, clock);
2045 2053
2046 return true; 2054 return 1;
2047} 2055}
2048 2056
2049static bool 2057static int
2050init_configure_preinit(struct nvbios *bios, uint16_t offset, 2058init_configure_preinit(struct nvbios *bios, uint16_t offset,
2051 struct init_exec *iexec) 2059 struct init_exec *iexec)
2052{ 2060{
@@ -2066,15 +2074,15 @@ init_configure_preinit(struct nvbios *bios, uint16_t offset,
2066 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & (1 << 6)); 2074 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & (1 << 6));
2067 2075
2068 if (bios->major_version > 2) 2076 if (bios->major_version > 2)
2069 return false; 2077 return 0;
2070 2078
2071 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, 2079 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR,
2072 NV_CIO_CRE_SCRATCH4__INDEX, cr3c); 2080 NV_CIO_CRE_SCRATCH4__INDEX, cr3c);
2073 2081
2074 return true; 2082 return 1;
2075} 2083}
2076 2084
2077static bool 2085static int
2078init_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2086init_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2079{ 2087{
2080 /* 2088 /*
@@ -2094,7 +2102,7 @@ init_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2094 uint8_t data = bios->data[offset + 4]; 2102 uint8_t data = bios->data[offset + 4];
2095 2103
2096 if (!iexec->execute) 2104 if (!iexec->execute)
2097 return true; 2105 return 5;
2098 2106
2099 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Mask: 0x%02X, Data: 0x%02X\n", 2107 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Mask: 0x%02X, Data: 0x%02X\n",
2100 offset, crtcport, mask, data); 2108 offset, crtcport, mask, data);
@@ -2153,15 +2161,15 @@ init_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2153 for (i = 0; i < 2; i++) 2161 for (i = 0; i < 2; i++)
2154 bios_wr32(bios, 0x614108 + (i*0x800), bios_rd32( 2162 bios_wr32(bios, 0x614108 + (i*0x800), bios_rd32(
2155 bios, 0x614108 + (i*0x800)) & 0x0fffffff); 2163 bios, 0x614108 + (i*0x800)) & 0x0fffffff);
2156 return true; 2164 return 5;
2157 } 2165 }
2158 2166
2159 bios_port_wr(bios, crtcport, (bios_port_rd(bios, crtcport) & mask) | 2167 bios_port_wr(bios, crtcport, (bios_port_rd(bios, crtcport) & mask) |
2160 data); 2168 data);
2161 return true; 2169 return 5;
2162} 2170}
2163 2171
2164static bool 2172static int
2165init_sub(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2173init_sub(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2166{ 2174{
2167 /* 2175 /*
@@ -2176,7 +2184,7 @@ init_sub(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2176 uint8_t sub = bios->data[offset + 1]; 2184 uint8_t sub = bios->data[offset + 1];
2177 2185
2178 if (!iexec->execute) 2186 if (!iexec->execute)
2179 return true; 2187 return 2;
2180 2188
2181 BIOSLOG(bios, "0x%04X: Calling script %d\n", offset, sub); 2189 BIOSLOG(bios, "0x%04X: Calling script %d\n", offset, sub);
2182 2190
@@ -2186,10 +2194,10 @@ init_sub(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2186 2194
2187 BIOSLOG(bios, "0x%04X: End of script %d\n", offset, sub); 2195 BIOSLOG(bios, "0x%04X: End of script %d\n", offset, sub);
2188 2196
2189 return true; 2197 return 2;
2190} 2198}
2191 2199
2192static bool 2200static int
2193init_ram_condition(struct nvbios *bios, uint16_t offset, 2201init_ram_condition(struct nvbios *bios, uint16_t offset,
2194 struct init_exec *iexec) 2202 struct init_exec *iexec)
2195{ 2203{
@@ -2210,7 +2218,7 @@ init_ram_condition(struct nvbios *bios, uint16_t offset,
2210 uint8_t data; 2218 uint8_t data;
2211 2219
2212 if (!iexec->execute) 2220 if (!iexec->execute)
2213 return true; 2221 return 3;
2214 2222
2215 data = bios_rd32(bios, NV_PFB_BOOT_0) & mask; 2223 data = bios_rd32(bios, NV_PFB_BOOT_0) & mask;
2216 2224
@@ -2224,10 +2232,10 @@ init_ram_condition(struct nvbios *bios, uint16_t offset,
2224 iexec->execute = false; 2232 iexec->execute = false;
2225 } 2233 }
2226 2234
2227 return true; 2235 return 3;
2228} 2236}
2229 2237
2230static bool 2238static int
2231init_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2239init_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2232{ 2240{
2233 /* 2241 /*
@@ -2246,17 +2254,17 @@ init_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2246 uint32_t data = ROM32(bios->data[offset + 9]); 2254 uint32_t data = ROM32(bios->data[offset + 9]);
2247 2255
2248 if (!iexec->execute) 2256 if (!iexec->execute)
2249 return true; 2257 return 13;
2250 2258
2251 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Mask: 0x%08X, Data: 0x%08X\n", 2259 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Mask: 0x%08X, Data: 0x%08X\n",
2252 offset, reg, mask, data); 2260 offset, reg, mask, data);
2253 2261
2254 bios_wr32(bios, reg, (bios_rd32(bios, reg) & mask) | data); 2262 bios_wr32(bios, reg, (bios_rd32(bios, reg) & mask) | data);
2255 2263
2256 return true; 2264 return 13;
2257} 2265}
2258 2266
2259static bool 2267static int
2260init_macro(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2268init_macro(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2261{ 2269{
2262 /* 2270 /*
@@ -2280,7 +2288,7 @@ init_macro(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2280 int i; 2288 int i;
2281 2289
2282 if (!iexec->execute) 2290 if (!iexec->execute)
2283 return true; 2291 return 2;
2284 2292
2285 BIOSLOG(bios, "0x%04X: Macro: 0x%02X, MacroTableIndex: 0x%02X, " 2293 BIOSLOG(bios, "0x%04X: Macro: 0x%02X, MacroTableIndex: 0x%02X, "
2286 "Count: 0x%02X\n", 2294 "Count: 0x%02X\n",
@@ -2295,10 +2303,10 @@ init_macro(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2295 bios_wr32(bios, reg, data); 2303 bios_wr32(bios, reg, data);
2296 } 2304 }
2297 2305
2298 return true; 2306 return 2;
2299} 2307}
2300 2308
2301static bool 2309static int
2302init_done(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2310init_done(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2303{ 2311{
2304 /* 2312 /*
@@ -2310,10 +2318,10 @@ init_done(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2310 */ 2318 */
2311 2319
2312 /* mild retval abuse to stop parsing this table */ 2320 /* mild retval abuse to stop parsing this table */
2313 return false; 2321 return 0;
2314} 2322}
2315 2323
2316static bool 2324static int
2317init_resume(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2325init_resume(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2318{ 2326{
2319 /* 2327 /*
@@ -2325,15 +2333,15 @@ init_resume(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2325 */ 2333 */
2326 2334
2327 if (iexec->execute) 2335 if (iexec->execute)
2328 return true; 2336 return 1;
2329 2337
2330 iexec->execute = true; 2338 iexec->execute = true;
2331 BIOSLOG(bios, "0x%04X: ---- Executing following commands ----\n", offset); 2339 BIOSLOG(bios, "0x%04X: ---- Executing following commands ----\n", offset);
2332 2340
2333 return true; 2341 return 1;
2334} 2342}
2335 2343
2336static bool 2344static int
2337init_time(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2345init_time(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2338{ 2346{
2339 /* 2347 /*
@@ -2348,7 +2356,7 @@ init_time(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2348 unsigned time = ROM16(bios->data[offset + 1]); 2356 unsigned time = ROM16(bios->data[offset + 1]);
2349 2357
2350 if (!iexec->execute) 2358 if (!iexec->execute)
2351 return true; 2359 return 3;
2352 2360
2353 BIOSLOG(bios, "0x%04X: Sleeping for 0x%04X microseconds\n", 2361 BIOSLOG(bios, "0x%04X: Sleeping for 0x%04X microseconds\n",
2354 offset, time); 2362 offset, time);
@@ -2358,10 +2366,10 @@ init_time(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2358 else 2366 else
2359 msleep((time + 900) / 1000); 2367 msleep((time + 900) / 1000);
2360 2368
2361 return true; 2369 return 3;
2362} 2370}
2363 2371
2364static bool 2372static int
2365init_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2373init_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2366{ 2374{
2367 /* 2375 /*
@@ -2378,7 +2386,7 @@ init_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2378 uint8_t cond = bios->data[offset + 1]; 2386 uint8_t cond = bios->data[offset + 1];
2379 2387
2380 if (!iexec->execute) 2388 if (!iexec->execute)
2381 return true; 2389 return 2;
2382 2390
2383 BIOSLOG(bios, "0x%04X: Condition: 0x%02X\n", offset, cond); 2391 BIOSLOG(bios, "0x%04X: Condition: 0x%02X\n", offset, cond);
2384 2392
@@ -2389,10 +2397,10 @@ init_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2389 iexec->execute = false; 2397 iexec->execute = false;
2390 } 2398 }
2391 2399
2392 return true; 2400 return 2;
2393} 2401}
2394 2402
2395static bool 2403static int
2396init_io_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2404init_io_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2397{ 2405{
2398 /* 2406 /*
@@ -2409,7 +2417,7 @@ init_io_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2409 uint8_t cond = bios->data[offset + 1]; 2417 uint8_t cond = bios->data[offset + 1];
2410 2418
2411 if (!iexec->execute) 2419 if (!iexec->execute)
2412 return true; 2420 return 2;
2413 2421
2414 BIOSLOG(bios, "0x%04X: IO condition: 0x%02X\n", offset, cond); 2422 BIOSLOG(bios, "0x%04X: IO condition: 0x%02X\n", offset, cond);
2415 2423
@@ -2420,10 +2428,10 @@ init_io_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2420 iexec->execute = false; 2428 iexec->execute = false;
2421 } 2429 }
2422 2430
2423 return true; 2431 return 2;
2424} 2432}
2425 2433
2426static bool 2434static int
2427init_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2435init_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2428{ 2436{
2429 /* 2437 /*
@@ -2446,7 +2454,7 @@ init_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2446 uint8_t value; 2454 uint8_t value;
2447 2455
2448 if (!iexec->execute) 2456 if (!iexec->execute)
2449 return true; 2457 return 6;
2450 2458
2451 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, " 2459 BIOSLOG(bios, "0x%04X: Port: 0x%04X, Index: 0x%02X, Mask: 0x%02X, "
2452 "Data: 0x%02X\n", 2460 "Data: 0x%02X\n",
@@ -2455,10 +2463,10 @@ init_index_io(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2455 value = (bios_idxprt_rd(bios, crtcport, crtcindex) & mask) | data; 2463 value = (bios_idxprt_rd(bios, crtcport, crtcindex) & mask) | data;
2456 bios_idxprt_wr(bios, crtcport, crtcindex, value); 2464 bios_idxprt_wr(bios, crtcport, crtcindex, value);
2457 2465
2458 return true; 2466 return 6;
2459} 2467}
2460 2468
2461static bool 2469static int
2462init_pll(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2470init_pll(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2463{ 2471{
2464 /* 2472 /*
@@ -2476,16 +2484,16 @@ init_pll(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2476 uint16_t freq = ROM16(bios->data[offset + 5]); 2484 uint16_t freq = ROM16(bios->data[offset + 5]);
2477 2485
2478 if (!iexec->execute) 2486 if (!iexec->execute)
2479 return true; 2487 return 7;
2480 2488
2481 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Freq: %d0kHz\n", offset, reg, freq); 2489 BIOSLOG(bios, "0x%04X: Reg: 0x%08X, Freq: %d0kHz\n", offset, reg, freq);
2482 2490
2483 setPLL(bios, reg, freq * 10); 2491 setPLL(bios, reg, freq * 10);
2484 2492
2485 return true; 2493 return 7;
2486} 2494}
2487 2495
2488static bool 2496static int
2489init_zm_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2497init_zm_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2490{ 2498{
2491 /* 2499 /*
@@ -2502,17 +2510,17 @@ init_zm_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2502 uint32_t value = ROM32(bios->data[offset + 5]); 2510 uint32_t value = ROM32(bios->data[offset + 5]);
2503 2511
2504 if (!iexec->execute) 2512 if (!iexec->execute)
2505 return true; 2513 return 9;
2506 2514
2507 if (reg == 0x000200) 2515 if (reg == 0x000200)
2508 value |= 1; 2516 value |= 1;
2509 2517
2510 bios_wr32(bios, reg, value); 2518 bios_wr32(bios, reg, value);
2511 2519
2512 return true; 2520 return 9;
2513} 2521}
2514 2522
2515static bool 2523static int
2516init_ram_restrict_pll(struct nvbios *bios, uint16_t offset, 2524init_ram_restrict_pll(struct nvbios *bios, uint16_t offset,
2517 struct init_exec *iexec) 2525 struct init_exec *iexec)
2518{ 2526{
@@ -2538,14 +2546,15 @@ init_ram_restrict_pll(struct nvbios *bios, uint16_t offset,
2538 uint8_t type = bios->data[offset + 1]; 2546 uint8_t type = bios->data[offset + 1];
2539 uint32_t freq = ROM32(bios->data[offset + 2 + (index * 4)]); 2547 uint32_t freq = ROM32(bios->data[offset + 2 + (index * 4)]);
2540 uint8_t *pll_limits = &bios->data[bios->pll_limit_tbl_ptr], *entry; 2548 uint8_t *pll_limits = &bios->data[bios->pll_limit_tbl_ptr], *entry;
2549 int len = 2 + bios->ram_restrict_group_count * 4;
2541 int i; 2550 int i;
2542 2551
2543 if (!iexec->execute) 2552 if (!iexec->execute)
2544 return true; 2553 return len;
2545 2554
2546 if (!bios->pll_limit_tbl_ptr || (pll_limits[0] & 0xf0) != 0x30) { 2555 if (!bios->pll_limit_tbl_ptr || (pll_limits[0] & 0xf0) != 0x30) {
2547 NV_ERROR(dev, "PLL limits table not version 3.x\n"); 2556 NV_ERROR(dev, "PLL limits table not version 3.x\n");
2548 return true; /* deliberate, allow default clocks to remain */ 2557 return len; /* deliberate, allow default clocks to remain */
2549 } 2558 }
2550 2559
2551 entry = pll_limits + pll_limits[1]; 2560 entry = pll_limits + pll_limits[1];
@@ -2558,15 +2567,15 @@ init_ram_restrict_pll(struct nvbios *bios, uint16_t offset,
2558 offset, type, reg, freq); 2567 offset, type, reg, freq);
2559 2568
2560 setPLL(bios, reg, freq); 2569 setPLL(bios, reg, freq);
2561 return true; 2570 return len;
2562 } 2571 }
2563 } 2572 }
2564 2573
2565 NV_ERROR(dev, "PLL type 0x%02x not found in PLL limits table", type); 2574 NV_ERROR(dev, "PLL type 0x%02x not found in PLL limits table", type);
2566 return true; 2575 return len;
2567} 2576}
2568 2577
2569static bool 2578static int
2570init_8c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2579init_8c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2571{ 2580{
2572 /* 2581 /*
@@ -2576,10 +2585,10 @@ init_8c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2576 * 2585 *
2577 */ 2586 */
2578 2587
2579 return true; 2588 return 1;
2580} 2589}
2581 2590
2582static bool 2591static int
2583init_8d(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2592init_8d(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2584{ 2593{
2585 /* 2594 /*
@@ -2589,10 +2598,10 @@ init_8d(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2589 * 2598 *
2590 */ 2599 */
2591 2600
2592 return true; 2601 return 1;
2593} 2602}
2594 2603
2595static bool 2604static int
2596init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2605init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2597{ 2606{
2598 /* 2607 /*
@@ -2610,14 +2619,17 @@ init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2610 const uint8_t *gpio_entry; 2619 const uint8_t *gpio_entry;
2611 int i; 2620 int i;
2612 2621
2622 if (!iexec->execute)
2623 return 1;
2624
2613 if (bios->bdcb.version != 0x40) { 2625 if (bios->bdcb.version != 0x40) {
2614 NV_ERROR(bios->dev, "DCB table not version 4.0\n"); 2626 NV_ERROR(bios->dev, "DCB table not version 4.0\n");
2615 return false; 2627 return 0;
2616 } 2628 }
2617 2629
2618 if (!bios->bdcb.gpio_table_ptr) { 2630 if (!bios->bdcb.gpio_table_ptr) {
2619 NV_WARN(bios->dev, "Invalid pointer to INIT_8E table\n"); 2631 NV_WARN(bios->dev, "Invalid pointer to INIT_8E table\n");
2620 return false; 2632 return 0;
2621 } 2633 }
2622 2634
2623 gpio_entry = gpio_table + gpio_table[1]; 2635 gpio_entry = gpio_table + gpio_table[1];
@@ -2655,13 +2667,10 @@ init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2655 bios_wr32(bios, r, v); 2667 bios_wr32(bios, r, v);
2656 } 2668 }
2657 2669
2658 return true; 2670 return 1;
2659} 2671}
2660 2672
2661/* hack to avoid moving the itbl_entry array before this function */ 2673static int
2662int init_ram_restrict_zm_reg_group_blocklen;
2663
2664static bool
2665init_ram_restrict_zm_reg_group(struct nvbios *bios, uint16_t offset, 2674init_ram_restrict_zm_reg_group(struct nvbios *bios, uint16_t offset,
2666 struct init_exec *iexec) 2675 struct init_exec *iexec)
2667{ 2676{
@@ -2687,21 +2696,21 @@ init_ram_restrict_zm_reg_group(struct nvbios *bios, uint16_t offset,
2687 uint8_t regincrement = bios->data[offset + 5]; 2696 uint8_t regincrement = bios->data[offset + 5];
2688 uint8_t count = bios->data[offset + 6]; 2697 uint8_t count = bios->data[offset + 6];
2689 uint32_t strap_ramcfg, data; 2698 uint32_t strap_ramcfg, data;
2690 uint16_t blocklen; 2699 /* previously set by 'M' BIT table */
2700 uint16_t blocklen = bios->ram_restrict_group_count * 4;
2701 int len = 7 + count * blocklen;
2691 uint8_t index; 2702 uint8_t index;
2692 int i; 2703 int i;
2693 2704
2694 /* previously set by 'M' BIT table */
2695 blocklen = init_ram_restrict_zm_reg_group_blocklen;
2696 2705
2697 if (!iexec->execute) 2706 if (!iexec->execute)
2698 return true; 2707 return len;
2699 2708
2700 if (!blocklen) { 2709 if (!blocklen) {
2701 NV_ERROR(bios->dev, 2710 NV_ERROR(bios->dev,
2702 "0x%04X: Zero block length - has the M table " 2711 "0x%04X: Zero block length - has the M table "
2703 "been parsed?\n", offset); 2712 "been parsed?\n", offset);
2704 return false; 2713 return 0;
2705 } 2714 }
2706 2715
2707 strap_ramcfg = (bios_rd32(bios, NV_PEXTDEV_BOOT_0) >> 2) & 0xf; 2716 strap_ramcfg = (bios_rd32(bios, NV_PEXTDEV_BOOT_0) >> 2) & 0xf;
@@ -2719,10 +2728,10 @@ init_ram_restrict_zm_reg_group(struct nvbios *bios, uint16_t offset,
2719 reg += regincrement; 2728 reg += regincrement;
2720 } 2729 }
2721 2730
2722 return true; 2731 return len;
2723} 2732}
2724 2733
2725static bool 2734static int
2726init_copy_zm_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2735init_copy_zm_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2727{ 2736{
2728 /* 2737 /*
@@ -2739,14 +2748,14 @@ init_copy_zm_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2739 uint32_t dstreg = ROM32(bios->data[offset + 5]); 2748 uint32_t dstreg = ROM32(bios->data[offset + 5]);
2740 2749
2741 if (!iexec->execute) 2750 if (!iexec->execute)
2742 return true; 2751 return 9;
2743 2752
2744 bios_wr32(bios, dstreg, bios_rd32(bios, srcreg)); 2753 bios_wr32(bios, dstreg, bios_rd32(bios, srcreg));
2745 2754
2746 return true; 2755 return 9;
2747} 2756}
2748 2757
2749static bool 2758static int
2750init_zm_reg_group_addr_latched(struct nvbios *bios, uint16_t offset, 2759init_zm_reg_group_addr_latched(struct nvbios *bios, uint16_t offset,
2751 struct init_exec *iexec) 2760 struct init_exec *iexec)
2752{ 2761{
@@ -2764,20 +2773,21 @@ init_zm_reg_group_addr_latched(struct nvbios *bios, uint16_t offset,
2764 2773
2765 uint32_t reg = ROM32(bios->data[offset + 1]); 2774 uint32_t reg = ROM32(bios->data[offset + 1]);
2766 uint8_t count = bios->data[offset + 5]; 2775 uint8_t count = bios->data[offset + 5];
2776 int len = 6 + count * 4;
2767 int i; 2777 int i;
2768 2778
2769 if (!iexec->execute) 2779 if (!iexec->execute)
2770 return true; 2780 return len;
2771 2781
2772 for (i = 0; i < count; i++) { 2782 for (i = 0; i < count; i++) {
2773 uint32_t data = ROM32(bios->data[offset + 6 + 4 * i]); 2783 uint32_t data = ROM32(bios->data[offset + 6 + 4 * i]);
2774 bios_wr32(bios, reg, data); 2784 bios_wr32(bios, reg, data);
2775 } 2785 }
2776 2786
2777 return true; 2787 return len;
2778} 2788}
2779 2789
2780static bool 2790static int
2781init_reserved(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2791init_reserved(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2782{ 2792{
2783 /* 2793 /*
@@ -2788,10 +2798,10 @@ init_reserved(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2788 * Seemingly does nothing 2798 * Seemingly does nothing
2789 */ 2799 */
2790 2800
2791 return true; 2801 return 1;
2792} 2802}
2793 2803
2794static bool 2804static int
2795init_96(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2805init_96(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2796{ 2806{
2797 /* 2807 /*
@@ -2824,13 +2834,13 @@ init_96(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2824 val <<= bios->data[offset + 16]; 2834 val <<= bios->data[offset + 16];
2825 2835
2826 if (!iexec->execute) 2836 if (!iexec->execute)
2827 return true; 2837 return 17;
2828 2838
2829 bios_wr32(bios, reg, (bios_rd32(bios, reg) & mask) | val); 2839 bios_wr32(bios, reg, (bios_rd32(bios, reg) & mask) | val);
2830 return true; 2840 return 17;
2831} 2841}
2832 2842
2833static bool 2843static int
2834init_97(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2844init_97(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2835{ 2845{
2836 /* 2846 /*
@@ -2854,13 +2864,13 @@ init_97(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2854 val = (val & mask) | ((val + add) & ~mask); 2864 val = (val & mask) | ((val + add) & ~mask);
2855 2865
2856 if (!iexec->execute) 2866 if (!iexec->execute)
2857 return true; 2867 return 13;
2858 2868
2859 bios_wr32(bios, reg, val); 2869 bios_wr32(bios, reg, val);
2860 return true; 2870 return 13;
2861} 2871}
2862 2872
2863static bool 2873static int
2864init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2874init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2865{ 2875{
2866 /* 2876 /*
@@ -2878,32 +2888,33 @@ init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2878 struct drm_device *dev = bios->dev; 2888 struct drm_device *dev = bios->dev;
2879 struct nouveau_i2c_chan *auxch; 2889 struct nouveau_i2c_chan *auxch;
2880 uint32_t addr = ROM32(bios->data[offset + 1]); 2890 uint32_t addr = ROM32(bios->data[offset + 1]);
2881 uint8_t len = bios->data[offset + 5]; 2891 uint8_t count = bios->data[offset + 5];
2892 int len = 6 + count * 2;
2882 int ret, i; 2893 int ret, i;
2883 2894
2884 if (!bios->display.output) { 2895 if (!bios->display.output) {
2885 NV_ERROR(dev, "INIT_AUXCH: no active output\n"); 2896 NV_ERROR(dev, "INIT_AUXCH: no active output\n");
2886 return false; 2897 return 0;
2887 } 2898 }
2888 2899
2889 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index); 2900 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index);
2890 if (!auxch) { 2901 if (!auxch) {
2891 NV_ERROR(dev, "INIT_AUXCH: couldn't get auxch %d\n", 2902 NV_ERROR(dev, "INIT_AUXCH: couldn't get auxch %d\n",
2892 bios->display.output->i2c_index); 2903 bios->display.output->i2c_index);
2893 return false; 2904 return 0;
2894 } 2905 }
2895 2906
2896 if (!iexec->execute) 2907 if (!iexec->execute)
2897 return true; 2908 return len;
2898 2909
2899 offset += 6; 2910 offset += 6;
2900 for (i = 0; i < len; i++, offset += 2) { 2911 for (i = 0; i < count; i++, offset += 2) {
2901 uint8_t data; 2912 uint8_t data;
2902 2913
2903 ret = nouveau_dp_auxch(auxch, 9, addr, &data, 1); 2914 ret = nouveau_dp_auxch(auxch, 9, addr, &data, 1);
2904 if (ret) { 2915 if (ret) {
2905 NV_ERROR(dev, "INIT_AUXCH: rd auxch fail %d\n", ret); 2916 NV_ERROR(dev, "INIT_AUXCH: rd auxch fail %d\n", ret);
2906 return false; 2917 return 0;
2907 } 2918 }
2908 2919
2909 data &= bios->data[offset + 0]; 2920 data &= bios->data[offset + 0];
@@ -2912,14 +2923,14 @@ init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2912 ret = nouveau_dp_auxch(auxch, 8, addr, &data, 1); 2923 ret = nouveau_dp_auxch(auxch, 8, addr, &data, 1);
2913 if (ret) { 2924 if (ret) {
2914 NV_ERROR(dev, "INIT_AUXCH: wr auxch fail %d\n", ret); 2925 NV_ERROR(dev, "INIT_AUXCH: wr auxch fail %d\n", ret);
2915 return false; 2926 return 0;
2916 } 2927 }
2917 } 2928 }
2918 2929
2919 return true; 2930 return len;
2920} 2931}
2921 2932
2922static bool 2933static int
2923init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2934init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2924{ 2935{
2925 /* 2936 /*
@@ -2936,106 +2947,99 @@ init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2936 struct drm_device *dev = bios->dev; 2947 struct drm_device *dev = bios->dev;
2937 struct nouveau_i2c_chan *auxch; 2948 struct nouveau_i2c_chan *auxch;
2938 uint32_t addr = ROM32(bios->data[offset + 1]); 2949 uint32_t addr = ROM32(bios->data[offset + 1]);
2939 uint8_t len = bios->data[offset + 5]; 2950 uint8_t count = bios->data[offset + 5];
2951 int len = 6 + count;
2940 int ret, i; 2952 int ret, i;
2941 2953
2942 if (!bios->display.output) { 2954 if (!bios->display.output) {
2943 NV_ERROR(dev, "INIT_ZM_AUXCH: no active output\n"); 2955 NV_ERROR(dev, "INIT_ZM_AUXCH: no active output\n");
2944 return false; 2956 return 0;
2945 } 2957 }
2946 2958
2947 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index); 2959 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index);
2948 if (!auxch) { 2960 if (!auxch) {
2949 NV_ERROR(dev, "INIT_ZM_AUXCH: couldn't get auxch %d\n", 2961 NV_ERROR(dev, "INIT_ZM_AUXCH: couldn't get auxch %d\n",
2950 bios->display.output->i2c_index); 2962 bios->display.output->i2c_index);
2951 return false; 2963 return 0;
2952 } 2964 }
2953 2965
2954 if (!iexec->execute) 2966 if (!iexec->execute)
2955 return true; 2967 return len;
2956 2968
2957 offset += 6; 2969 offset += 6;
2958 for (i = 0; i < len; i++, offset++) { 2970 for (i = 0; i < count; i++, offset++) {
2959 ret = nouveau_dp_auxch(auxch, 8, addr, &bios->data[offset], 1); 2971 ret = nouveau_dp_auxch(auxch, 8, addr, &bios->data[offset], 1);
2960 if (ret) { 2972 if (ret) {
2961 NV_ERROR(dev, "INIT_ZM_AUXCH: wr auxch fail %d\n", ret); 2973 NV_ERROR(dev, "INIT_ZM_AUXCH: wr auxch fail %d\n", ret);
2962 return false; 2974 return 0;
2963 } 2975 }
2964 } 2976 }
2965 2977
2966 return true; 2978 return len;
2967} 2979}
2968 2980
2969static struct init_tbl_entry itbl_entry[] = { 2981static struct init_tbl_entry itbl_entry[] = {
2970 /* command name , id , length , offset , mult , command handler */ 2982 /* command name , id , length , offset , mult , command handler */
2971 /* INIT_PROG (0x31, 15, 10, 4) removed due to no example of use */ 2983 /* INIT_PROG (0x31, 15, 10, 4) removed due to no example of use */
2972 { "INIT_IO_RESTRICT_PROG" , 0x32, 11 , 6 , 4 , init_io_restrict_prog }, 2984 { "INIT_IO_RESTRICT_PROG" , 0x32, init_io_restrict_prog },
2973 { "INIT_REPEAT" , 0x33, 2 , 0 , 0 , init_repeat }, 2985 { "INIT_REPEAT" , 0x33, init_repeat },
2974 { "INIT_IO_RESTRICT_PLL" , 0x34, 12 , 7 , 2 , init_io_restrict_pll }, 2986 { "INIT_IO_RESTRICT_PLL" , 0x34, init_io_restrict_pll },
2975 { "INIT_END_REPEAT" , 0x36, 1 , 0 , 0 , init_end_repeat }, 2987 { "INIT_END_REPEAT" , 0x36, init_end_repeat },
2976 { "INIT_COPY" , 0x37, 11 , 0 , 0 , init_copy }, 2988 { "INIT_COPY" , 0x37, init_copy },
2977 { "INIT_NOT" , 0x38, 1 , 0 , 0 , init_not }, 2989 { "INIT_NOT" , 0x38, init_not },
2978 { "INIT_IO_FLAG_CONDITION" , 0x39, 2 , 0 , 0 , init_io_flag_condition }, 2990 { "INIT_IO_FLAG_CONDITION" , 0x39, init_io_flag_condition },
2979 { "INIT_INDEX_ADDRESS_LATCHED" , 0x49, 18 , 17 , 2 , init_idx_addr_latched }, 2991 { "INIT_INDEX_ADDRESS_LATCHED" , 0x49, init_idx_addr_latched },
2980 { "INIT_IO_RESTRICT_PLL2" , 0x4A, 11 , 6 , 4 , init_io_restrict_pll2 }, 2992 { "INIT_IO_RESTRICT_PLL2" , 0x4A, init_io_restrict_pll2 },
2981 { "INIT_PLL2" , 0x4B, 9 , 0 , 0 , init_pll2 }, 2993 { "INIT_PLL2" , 0x4B, init_pll2 },
2982 { "INIT_I2C_BYTE" , 0x4C, 4 , 3 , 3 , init_i2c_byte }, 2994 { "INIT_I2C_BYTE" , 0x4C, init_i2c_byte },
2983 { "INIT_ZM_I2C_BYTE" , 0x4D, 4 , 3 , 2 , init_zm_i2c_byte }, 2995 { "INIT_ZM_I2C_BYTE" , 0x4D, init_zm_i2c_byte },
2984 { "INIT_ZM_I2C" , 0x4E, 4 , 3 , 1 , init_zm_i2c }, 2996 { "INIT_ZM_I2C" , 0x4E, init_zm_i2c },
2985 { "INIT_TMDS" , 0x4F, 5 , 0 , 0 , init_tmds }, 2997 { "INIT_TMDS" , 0x4F, init_tmds },
2986 { "INIT_ZM_TMDS_GROUP" , 0x50, 3 , 2 , 2 , init_zm_tmds_group }, 2998 { "INIT_ZM_TMDS_GROUP" , 0x50, init_zm_tmds_group },
2987 { "INIT_CR_INDEX_ADDRESS_LATCHED" , 0x51, 5 , 4 , 1 , init_cr_idx_adr_latch }, 2999 { "INIT_CR_INDEX_ADDRESS_LATCHED" , 0x51, init_cr_idx_adr_latch },
2988 { "INIT_CR" , 0x52, 4 , 0 , 0 , init_cr }, 3000 { "INIT_CR" , 0x52, init_cr },
2989 { "INIT_ZM_CR" , 0x53, 3 , 0 , 0 , init_zm_cr }, 3001 { "INIT_ZM_CR" , 0x53, init_zm_cr },
2990 { "INIT_ZM_CR_GROUP" , 0x54, 2 , 1 , 2 , init_zm_cr_group }, 3002 { "INIT_ZM_CR_GROUP" , 0x54, init_zm_cr_group },
2991 { "INIT_CONDITION_TIME" , 0x56, 3 , 0 , 0 , init_condition_time }, 3003 { "INIT_CONDITION_TIME" , 0x56, init_condition_time },
2992 { "INIT_ZM_REG_SEQUENCE" , 0x58, 6 , 5 , 4 , init_zm_reg_sequence }, 3004 { "INIT_ZM_REG_SEQUENCE" , 0x58, init_zm_reg_sequence },
2993 /* INIT_INDIRECT_REG (0x5A, 7, 0, 0) removed due to no example of use */ 3005 /* INIT_INDIRECT_REG (0x5A, 7, 0, 0) removed due to no example of use */
2994 { "INIT_SUB_DIRECT" , 0x5B, 3 , 0 , 0 , init_sub_direct }, 3006 { "INIT_SUB_DIRECT" , 0x5B, init_sub_direct },
2995 { "INIT_COPY_NV_REG" , 0x5F, 22 , 0 , 0 , init_copy_nv_reg }, 3007 { "INIT_COPY_NV_REG" , 0x5F, init_copy_nv_reg },
2996 { "INIT_ZM_INDEX_IO" , 0x62, 5 , 0 , 0 , init_zm_index_io }, 3008 { "INIT_ZM_INDEX_IO" , 0x62, init_zm_index_io },
2997 { "INIT_COMPUTE_MEM" , 0x63, 1 , 0 , 0 , init_compute_mem }, 3009 { "INIT_COMPUTE_MEM" , 0x63, init_compute_mem },
2998 { "INIT_RESET" , 0x65, 13 , 0 , 0 , init_reset }, 3010 { "INIT_RESET" , 0x65, init_reset },
2999 { "INIT_CONFIGURE_MEM" , 0x66, 1 , 0 , 0 , init_configure_mem }, 3011 { "INIT_CONFIGURE_MEM" , 0x66, init_configure_mem },
3000 { "INIT_CONFIGURE_CLK" , 0x67, 1 , 0 , 0 , init_configure_clk }, 3012 { "INIT_CONFIGURE_CLK" , 0x67, init_configure_clk },
3001 { "INIT_CONFIGURE_PREINIT" , 0x68, 1 , 0 , 0 , init_configure_preinit }, 3013 { "INIT_CONFIGURE_PREINIT" , 0x68, init_configure_preinit },
3002 { "INIT_IO" , 0x69, 5 , 0 , 0 , init_io }, 3014 { "INIT_IO" , 0x69, init_io },
3003 { "INIT_SUB" , 0x6B, 2 , 0 , 0 , init_sub }, 3015 { "INIT_SUB" , 0x6B, init_sub },
3004 { "INIT_RAM_CONDITION" , 0x6D, 3 , 0 , 0 , init_ram_condition }, 3016 { "INIT_RAM_CONDITION" , 0x6D, init_ram_condition },
3005 { "INIT_NV_REG" , 0x6E, 13 , 0 , 0 , init_nv_reg }, 3017 { "INIT_NV_REG" , 0x6E, init_nv_reg },
3006 { "INIT_MACRO" , 0x6F, 2 , 0 , 0 , init_macro }, 3018 { "INIT_MACRO" , 0x6F, init_macro },
3007 { "INIT_DONE" , 0x71, 1 , 0 , 0 , init_done }, 3019 { "INIT_DONE" , 0x71, init_done },
3008 { "INIT_RESUME" , 0x72, 1 , 0 , 0 , init_resume }, 3020 { "INIT_RESUME" , 0x72, init_resume },
3009 /* INIT_RAM_CONDITION2 (0x73, 9, 0, 0) removed due to no example of use */ 3021 /* INIT_RAM_CONDITION2 (0x73, 9, 0, 0) removed due to no example of use */
3010 { "INIT_TIME" , 0x74, 3 , 0 , 0 , init_time }, 3022 { "INIT_TIME" , 0x74, init_time },
3011 { "INIT_CONDITION" , 0x75, 2 , 0 , 0 , init_condition }, 3023 { "INIT_CONDITION" , 0x75, init_condition },
3012 { "INIT_IO_CONDITION" , 0x76, 2 , 0 , 0 , init_io_condition }, 3024 { "INIT_IO_CONDITION" , 0x76, init_io_condition },
3013 { "INIT_INDEX_IO" , 0x78, 6 , 0 , 0 , init_index_io }, 3025 { "INIT_INDEX_IO" , 0x78, init_index_io },
3014 { "INIT_PLL" , 0x79, 7 , 0 , 0 , init_pll }, 3026 { "INIT_PLL" , 0x79, init_pll },
3015 { "INIT_ZM_REG" , 0x7A, 9 , 0 , 0 , init_zm_reg }, 3027 { "INIT_ZM_REG" , 0x7A, init_zm_reg },
3016 /* INIT_RAM_RESTRICT_PLL's length is adjusted by the BIT M table */ 3028 { "INIT_RAM_RESTRICT_PLL" , 0x87, init_ram_restrict_pll },
3017 { "INIT_RAM_RESTRICT_PLL" , 0x87, 2 , 0 , 0 , init_ram_restrict_pll }, 3029 { "INIT_8C" , 0x8C, init_8c },
3018 { "INIT_8C" , 0x8C, 1 , 0 , 0 , init_8c }, 3030 { "INIT_8D" , 0x8D, init_8d },
3019 { "INIT_8D" , 0x8D, 1 , 0 , 0 , init_8d }, 3031 { "INIT_GPIO" , 0x8E, init_gpio },
3020 { "INIT_GPIO" , 0x8E, 1 , 0 , 0 , init_gpio }, 3032 { "INIT_RAM_RESTRICT_ZM_REG_GROUP" , 0x8F, init_ram_restrict_zm_reg_group },
3021 /* INIT_RAM_RESTRICT_ZM_REG_GROUP's mult is loaded by M table in BIT */ 3033 { "INIT_COPY_ZM_REG" , 0x90, init_copy_zm_reg },
3022 { "INIT_RAM_RESTRICT_ZM_REG_GROUP" , 0x8F, 7 , 6 , 0 , init_ram_restrict_zm_reg_group }, 3034 { "INIT_ZM_REG_GROUP_ADDRESS_LATCHED" , 0x91, init_zm_reg_group_addr_latched },
3023 { "INIT_COPY_ZM_REG" , 0x90, 9 , 0 , 0 , init_copy_zm_reg }, 3035 { "INIT_RESERVED" , 0x92, init_reserved },
3024 { "INIT_ZM_REG_GROUP_ADDRESS_LATCHED" , 0x91, 6 , 5 , 4 , init_zm_reg_group_addr_latched }, 3036 { "INIT_96" , 0x96, init_96 },
3025 { "INIT_RESERVED" , 0x92, 1 , 0 , 0 , init_reserved }, 3037 { "INIT_97" , 0x97, init_97 },
3026 { "INIT_96" , 0x96, 17 , 0 , 0 , init_96 }, 3038 { "INIT_AUXCH" , 0x98, init_auxch },
3027 { "INIT_97" , 0x97, 13 , 0 , 0 , init_97 }, 3039 { "INIT_ZM_AUXCH" , 0x99, init_zm_auxch },
3028 { "INIT_AUXCH" , 0x98, 6 , 5 , 2 , init_auxch }, 3040 { NULL , 0 , NULL }
3029 { "INIT_ZM_AUXCH" , 0x99, 6 , 5 , 1 , init_zm_auxch },
3030 { NULL , 0 , 0 , 0 , 0 , NULL }
3031}; 3041};
3032 3042
3033static unsigned int get_init_table_entry_length(struct nvbios *bios, unsigned int offset, int i)
3034{
3035 /* Calculates the length of a given init table entry. */
3036 return itbl_entry[i].length + bios->data[offset + itbl_entry[i].length_offset]*itbl_entry[i].length_multiplier;
3037}
3038
3039#define MAX_TABLE_OPS 1000 3043#define MAX_TABLE_OPS 1000
3040 3044
3041static int 3045static int
@@ -3051,7 +3055,7 @@ parse_init_table(struct nvbios *bios, unsigned int offset,
3051 * is changed back to EXECUTE. 3055 * is changed back to EXECUTE.
3052 */ 3056 */
3053 3057
3054 int count = 0, i; 3058 int count = 0, i, res;
3055 uint8_t id; 3059 uint8_t id;
3056 3060
3057 /* 3061 /*
@@ -3071,22 +3075,21 @@ parse_init_table(struct nvbios *bios, unsigned int offset,
3071 offset, itbl_entry[i].id, itbl_entry[i].name); 3075 offset, itbl_entry[i].id, itbl_entry[i].name);
3072 3076
3073 /* execute eventual command handler */ 3077 /* execute eventual command handler */
3074 if (itbl_entry[i].handler) 3078 res = (*itbl_entry[i].handler)(bios, offset, iexec);
3075 if (!(*itbl_entry[i].handler)(bios, offset, iexec)) 3079 if (!res)
3076 break; 3080 break;
3081 /*
3082 * Add the offset of the current command including all data
3083 * of that command. The offset will then be pointing on the
3084 * next op code.
3085 */
3086 offset += res;
3077 } else { 3087 } else {
3078 NV_ERROR(bios->dev, 3088 NV_ERROR(bios->dev,
3079 "0x%04X: Init table command not found: " 3089 "0x%04X: Init table command not found: "
3080 "0x%02X\n", offset, id); 3090 "0x%02X\n", offset, id);
3081 return -ENOENT; 3091 return -ENOENT;
3082 } 3092 }
3083
3084 /*
3085 * Add the offset of the current command including all data
3086 * of that command. The offset will then be pointing on the
3087 * next op code.
3088 */
3089 offset += get_init_table_entry_length(bios, offset, i);
3090 } 3093 }
3091 3094
3092 if (offset >= bios->length) 3095 if (offset >= bios->length)
@@ -4601,10 +4604,6 @@ parse_bit_M_tbl_entry(struct drm_device *dev, struct nvbios *bios,
4601 * stuff that we don't use - their use currently unknown 4604 * stuff that we don't use - their use currently unknown
4602 */ 4605 */
4603 4606
4604 uint16_t rr_strap_xlat;
4605 uint8_t rr_group_count;
4606 int i;
4607
4608 /* 4607 /*
4609 * Older bios versions don't have a sufficiently long table for 4608 * Older bios versions don't have a sufficiently long table for
4610 * what we want 4609 * what we want
@@ -4613,24 +4612,13 @@ parse_bit_M_tbl_entry(struct drm_device *dev, struct nvbios *bios,
4613 return 0; 4612 return 0;
4614 4613
4615 if (bitentry->id[1] < 2) { 4614 if (bitentry->id[1] < 2) {
4616 rr_group_count = bios->data[bitentry->offset + 2]; 4615 bios->ram_restrict_group_count = bios->data[bitentry->offset + 2];
4617 rr_strap_xlat = ROM16(bios->data[bitentry->offset + 3]); 4616 bios->ram_restrict_tbl_ptr = ROM16(bios->data[bitentry->offset + 3]);
4618 } else { 4617 } else {
4619 rr_group_count = bios->data[bitentry->offset + 0]; 4618 bios->ram_restrict_group_count = bios->data[bitentry->offset + 0];
4620 rr_strap_xlat = ROM16(bios->data[bitentry->offset + 1]); 4619 bios->ram_restrict_tbl_ptr = ROM16(bios->data[bitentry->offset + 1]);
4621 } 4620 }
4622 4621
4623 /* adjust length of INIT_87 */
4624 for (i = 0; itbl_entry[i].name && (itbl_entry[i].id != 0x87); i++);
4625 itbl_entry[i].length += rr_group_count * 4;
4626
4627 /* set up multiplier for INIT_RAM_RESTRICT_ZM_REG_GROUP */
4628 for (; itbl_entry[i].name && (itbl_entry[i].id != 0x8f); i++);
4629 itbl_entry[i].length_multiplier = rr_group_count * 4;
4630
4631 init_ram_restrict_zm_reg_group_blocklen = itbl_entry[i].length_multiplier;
4632 bios->ram_restrict_tbl_ptr = rr_strap_xlat;
4633
4634 return 0; 4622 return 0;
4635} 4623}
4636 4624
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.h b/drivers/gpu/drm/nouveau/nouveau_bios.h
index 1d5f10bd78ed..058e98c76d89 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.h
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.h
@@ -227,6 +227,7 @@ struct nvbios {
227 227
228 uint16_t pll_limit_tbl_ptr; 228 uint16_t pll_limit_tbl_ptr;
229 uint16_t ram_restrict_tbl_ptr; 229 uint16_t ram_restrict_tbl_ptr;
230 uint8_t ram_restrict_group_count;
230 231
231 uint16_t some_script_ptr; /* BIT I + 14 */ 232 uint16_t some_script_ptr; /* BIT I + 14 */
232 uint16_t init96_tbl_ptr; /* BIT I + 16 */ 233 uint16_t init96_tbl_ptr; /* BIT I + 16 */