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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
|
/* $Id: VMMDev.cpp 29590 2010-05-18 07:02:17Z vboxsync $ */
/** @file
* VMMDev - Guest <-> VMM/Host communication device.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/* #define LOG_ENABLED */
/* Enable dev_vmm Log3 statements to get IRQ-related logging. */
#define LOG_GROUP LOG_GROUP_DEV_VMM
#include <VBox/VMMDev.h>
#include <VBox/log.h>
#include <VBox/param.h>
#include <VBox/mm.h>
#include <VBox/pgm.h>
#include <VBox/err.h>
#include <VBox/vm.h> /* for VM_IS_EMT */
#include <iprt/asm.h>
#include <iprt/assert.h>
#include <iprt/buildconfig.h>
#include <iprt/string.h>
#include <iprt/time.h>
#ifndef IN_RC
# include <iprt/mem.h>
#endif
#ifdef IN_RING3
# include <iprt/uuid.h>
#endif
#include "VMMDevState.h"
#ifdef VBOX_WITH_HGCM
# include "VMMDevHGCM.h"
#endif
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define PCIDEV_2_VMMDEVSTATE(pPciDev) ( (VMMDevState *)(pPciDev) )
#define VMMDEVSTATE_2_DEVINS(pVMMDevState) ( (pVMMDevState)->pDevIns )
#define VBOX_GUEST_ADDITIONS_VERSION_1_03(s) \
( RT_HIWORD((s)->guestInfo.additionsVersion) == 1 \
&& RT_LOWORD((s)->guestInfo.additionsVersion) == 3 )
#define VBOX_GUEST_ADDITIONS_VERSION_OK(additionsVersion) \
( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
&& RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) )
#define VBOX_GUEST_ADDITIONS_VERSION_OLD(additionsVersion) \
( (RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) \
|| ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
&& RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) ) )
#define VBOX_GUEST_ADDITIONS_VERSION_TOO_OLD(additionsVersion) \
( RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) )
#define VBOX_GUEST_ADDITIONS_VERSION_NEW(additionsVersion) \
( RT_HIWORD(additionsVersion) > RT_HIWORD(VMMDEV_VERSION) \
|| ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
&& RT_LOWORD(additionsVersion) > RT_LOWORD(VMMDEV_VERSION) ) )
/** The saved state version. */
#define VMMDEV_SAVED_STATE_VERSION 13
/** The saved state version used by VirtualBox 3.0.
* This doesn't have the config part. */
#define VMMDEV_SAVED_STATE_VERSION_VBOX_30 11
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
/* Whenever host wants to inform guest about something
* an IRQ notification will be raised.
*
* VMMDev PDM interface will contain the guest notification method.
*
* There is a 32 bit event mask which will be read
* by guest on an interrupt. A non zero bit in the mask
* means that the specific event occurred and requires
* processing on guest side.
*
* After reading the event mask guest must issue a
* generic request AcknowlegdeEvents.
*
* IRQ line is set to 1 (request) if there are unprocessed
* events, that is the event mask is not zero.
*
* After receiving an interrupt and checking event mask,
* the guest must process events using the event specific
* mechanism.
*
* That is if mouse capabilities were changed,
* guest will use VMMDev_GetMouseStatus generic request.
*
* Event mask is only a set of flags indicating that guest
* must proceed with a procedure.
*
* Unsupported events are therefore ignored.
* The guest additions must inform host which events they
* want to receive, to avoid unnecessary IRQ processing.
* By default no events are signalled to guest.
*
* This seems to be fast method. It requires
* only one context switch for an event processing.
*
*/
static void vmmdevSetIRQ_Legacy_EMT (VMMDevState *pVMMDevState)
{
if (!pVMMDevState->fu32AdditionsOk)
{
Log(("vmmdevSetIRQ: IRQ is not generated, guest has not yet reported to us.\n"));
return;
}
uint32_t u32IRQLevel = 0;
/* Filter unsupported events */
uint32_t u32EventFlags =
pVMMDevState->u32HostEventFlags
& pVMMDevState->pVMMDevRAMR3->V.V1_03.u32GuestEventMask;
Log(("vmmdevSetIRQ: u32EventFlags = 0x%08X, "
"pVMMDevState->u32HostEventFlags = 0x%08X, "
"pVMMDevState->pVMMDevRAMR3->u32GuestEventMask = 0x%08X\n",
u32EventFlags,
pVMMDevState->u32HostEventFlags,
pVMMDevState->pVMMDevRAMR3->V.V1_03.u32GuestEventMask));
/* Move event flags to VMMDev RAM */
pVMMDevState->pVMMDevRAMR3->V.V1_03.u32HostEvents = u32EventFlags;
if (u32EventFlags)
{
/* Clear host flags which will be delivered to guest. */
pVMMDevState->u32HostEventFlags &= ~u32EventFlags;
Log(("vmmdevSetIRQ: pVMMDevState->u32HostEventFlags = 0x%08X\n",
pVMMDevState->u32HostEventFlags));
u32IRQLevel = 1;
}
/* Set IRQ level for pin 0 */
/** @todo make IRQ pin configurable, at least a symbolic constant */
PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
PDMDevHlpPCISetIrqNoWait(pDevIns, 0, u32IRQLevel);
Log(("vmmdevSetIRQ: IRQ set %d\n", u32IRQLevel));
}
static void vmmdevMaybeSetIRQ_EMT (VMMDevState *pVMMDevState)
{
PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS (pVMMDevState);
Log3(("vmmdevMaybeSetIRQ_EMT: u32HostEventFlags = 0x%08X, u32GuestFilterMask = 0x%08X.\n",
pVMMDevState->u32HostEventFlags, pVMMDevState->u32GuestFilterMask));
if (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask)
{
pVMMDevState->pVMMDevRAMR3->V.V1_04.fHaveEvents = true;
PDMDevHlpPCISetIrqNoWait (pDevIns, 0, 1);
Log3(("vmmdevMaybeSetIRQ_EMT: IRQ set.\n"));
}
}
static void vmmdevNotifyGuest_EMT (VMMDevState *pVMMDevState, uint32_t u32EventMask)
{
Log3(("VMMDevNotifyGuest_EMT: u32EventMask = 0x%08X.\n", u32EventMask));
if (VBOX_GUEST_ADDITIONS_VERSION_1_03 (pVMMDevState))
{
Log3(("VMMDevNotifyGuest_EMT: Old additions detected.\n"));
pVMMDevState->u32HostEventFlags |= u32EventMask;
vmmdevSetIRQ_Legacy_EMT (pVMMDevState);
}
else
{
Log3(("VMMDevNotifyGuest_EMT: New additions detected.\n"));
if (!pVMMDevState->fu32AdditionsOk)
{
pVMMDevState->u32HostEventFlags |= u32EventMask;
Log(("vmmdevNotifyGuest_EMT: IRQ is not generated, guest has not yet reported to us.\n"));
return;
}
const bool fHadEvents =
(pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask) != 0;
Log3(("VMMDevNotifyGuest_EMT: fHadEvents = %d, u32HostEventFlags = 0x%08X, u32GuestFilterMask = 0x%08X.\n",
fHadEvents, pVMMDevState->u32HostEventFlags, pVMMDevState->u32GuestFilterMask));
pVMMDevState->u32HostEventFlags |= u32EventMask;
if (!fHadEvents)
vmmdevMaybeSetIRQ_EMT (pVMMDevState);
}
}
void VMMDevCtlSetGuestFilterMask (VMMDevState *pVMMDevState,
uint32_t u32OrMask,
uint32_t u32NotMask)
{
PDMCritSectEnter(&pVMMDevState->CritSect, VERR_SEM_BUSY);
const bool fHadEvents =
(pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask) != 0;
Log(("VMMDevCtlSetGuestFilterMask: u32OrMask = 0x%08X, u32NotMask = 0x%08X, fHadEvents = %d.\n", u32OrMask, u32NotMask, fHadEvents));
if (fHadEvents)
{
if (!pVMMDevState->fNewGuestFilterMask)
pVMMDevState->u32NewGuestFilterMask = pVMMDevState->u32GuestFilterMask;
pVMMDevState->u32NewGuestFilterMask |= u32OrMask;
pVMMDevState->u32NewGuestFilterMask &= ~u32NotMask;
pVMMDevState->fNewGuestFilterMask = true;
}
else
{
pVMMDevState->u32GuestFilterMask |= u32OrMask;
pVMMDevState->u32GuestFilterMask &= ~u32NotMask;
vmmdevMaybeSetIRQ_EMT (pVMMDevState);
}
PDMCritSectLeave(&pVMMDevState->CritSect);
}
void VMMDevNotifyGuest (VMMDevState *pVMMDevState, uint32_t u32EventMask)
{
PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
Log3(("VMMDevNotifyGuest: u32EventMask = 0x%08X.\n", u32EventMask));
/*
* Drop notifications if the VM is not running yet/anymore.
*/
VMSTATE enmVMState = PDMDevHlpVMState(pDevIns);
if ( enmVMState != VMSTATE_RUNNING
&& enmVMState != VMSTATE_RUNNING_LS)
return;
PDMCritSectEnter(&pVMMDevState->CritSect, VERR_SEM_BUSY);
/* No need to wait for the completion of this request. It is a notification
* about something, which has already happened.
*/
vmmdevNotifyGuest_EMT(pVMMDevState, u32EventMask);
PDMCritSectLeave(&pVMMDevState->CritSect);
}
/**
* Port I/O Handler for OUT operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument - ignored.
* @param uPort Port number used for the IN operation.
* @param u32 The value to output.
* @param cb The value size in bytes.
*/
static DECLCALLBACK(int) vmmdevBackdoorLog(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
{
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
if (!pThis->fBackdoorLogDisabled && cb == 1 && Port == RTLOG_DEBUG_PORT)
{
/* The raw version. */
switch (u32)
{
case '\r': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <return>\n")); break;
case '\n': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <newline>\n")); break;
case '\t': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <tab>\n")); break;
default: LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: %c (%02x)\n", u32, u32)); break;
}
/* The readable, buffered version. */
if (u32 == '\n' || u32 == '\r')
{
pThis->szMsg[pThis->iMsg] = '\0';
if (pThis->iMsg)
LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("Guest Log: %s\n", pThis->szMsg));
pThis->iMsg = 0;
}
else
{
if (pThis->iMsg >= sizeof(pThis->szMsg)-1)
{
pThis->szMsg[pThis->iMsg] = '\0';
LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("Guest Log: %s\n", pThis->szMsg));
pThis->iMsg = 0;
}
pThis->szMsg[pThis->iMsg] = (char )u32;
pThis->szMsg[++pThis->iMsg] = '\0';
}
}
return VINF_SUCCESS;
}
#ifdef TIMESYNC_BACKDOOR
/**
* Port I/O Handler for OUT operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument - ignored.
* @param uPort Port number used for the IN operation.
* @param u32 The value to output.
* @param cb The value size in bytes.
*/
static DECLCALLBACK(int) vmmdevTimesyncBackdoorWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
{
NOREF(pvUser);
if (cb == 4)
{
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
switch (u32)
{
case 0:
pThis->fTimesyncBackdoorLo = false;
break;
case 1:
pThis->fTimesyncBackdoorLo = true;
}
return VINF_SUCCESS;
}
return VINF_SUCCESS;
}
/**
* Port I/O Handler for backdoor timesync IN operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument - ignored.
* @param uPort Port number used for the IN operation.
* @param pu32 Where to store the result.
* @param cb Number of bytes read.
*/
static DECLCALLBACK(int) vmmdevTimesyncBackdoorRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
{
int rc;
NOREF(pvUser);
if (cb == 4)
{
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
RTTIMESPEC now;
if (pThis->fTimesyncBackdoorLo)
*pu32 = (uint32_t)pThis->hostTime;
else
{
pThis->hostTime = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &now));
*pu32 = (uint32_t)(pThis->hostTime >> 32);
}
rc = VINF_SUCCESS;
}
else
rc = VERR_IOM_IOPORT_UNUSED;
return rc;
}
#endif /* TIMESYNC_BACKDOOR */
/**
* Port I/O Handler for the generic request interface
* @see FNIOMIOPORTOUT for details.
*
* @todo Too long, suggest doing the request copying here and moving the
* switch into a different function (or better case -> functions), and
* looing the gotos.
*/
static DECLCALLBACK(int) vmmdevRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
{
VMMDevState *pThis = (VMMDevState*)pvUser;
int rcRet = VINF_SUCCESS;
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
/*
* The caller has passed the guest context physical address
* of the request structure. Copy the request packet.
*/
VMMDevRequestHeader *pRequestHeader = NULL;
VMMDevRequestHeader requestHeader;
RT_ZERO(requestHeader);
PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
/* the structure size must be greater or equal to the header size */
if (requestHeader.size < sizeof(VMMDevRequestHeader))
{
Log(("VMMDev request header size too small! size = %d\n", requestHeader.size));
rcRet = VINF_SUCCESS;
goto end; /** @todo shouldn't (/ no need to) write back.*/
}
/* check the version of the header structure */
if (requestHeader.version != VMMDEV_REQUEST_HEADER_VERSION)
{
Log(("VMMDev: guest header version (0x%08X) differs from ours (0x%08X)\n", requestHeader.version, VMMDEV_REQUEST_HEADER_VERSION));
rcRet = VINF_SUCCESS;
goto end; /** @todo shouldn't (/ no need to) write back.*/
}
Log2(("VMMDev request issued: %d\n", requestHeader.requestType));
if ( requestHeader.requestType != VMMDevReq_ReportGuestInfo
&& !pThis->fu32AdditionsOk)
{
Log(("VMMDev: guest has not yet reported to us. Refusing operation.\n"));
requestHeader.rc = VERR_NOT_SUPPORTED;
rcRet = VINF_SUCCESS;
goto end;
}
/* Check upper limit */
if (requestHeader.size > VMMDEV_MAX_VMMDEVREQ_SIZE)
{
LogRel(("VMMDev: request packet too big (%x). Refusing operation.\n", requestHeader.size));
requestHeader.rc = VERR_NOT_SUPPORTED;
rcRet = VINF_SUCCESS;
goto end;
}
/* Read the entire request packet */
pRequestHeader = (VMMDevRequestHeader *)RTMemAlloc(requestHeader.size);
if (!pRequestHeader)
{
Log(("VMMDev: RTMemAlloc failed!\n"));
rcRet = VINF_SUCCESS;
requestHeader.rc = VERR_NO_MEMORY;
goto end;
}
PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, pRequestHeader, requestHeader.size);
/* which request was sent? */
switch (pRequestHeader->requestType)
{
/*
* Guest wants to give up a timeslice
*/
case VMMDevReq_Idle:
{
/* just return to EMT telling it that we want to halt */
rcRet = VINF_EM_HALT;
break;
}
/*
* Guest is reporting its information
*/
case VMMDevReq_ReportGuestInfo:
{
if (pRequestHeader->size < sizeof(VMMDevReportGuestInfo))
{
AssertMsgFailed(("VMMDev guest information structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReportGuestInfo *guestInfo = (VMMDevReportGuestInfo*)pRequestHeader;
if (memcmp (&pThis->guestInfo, &guestInfo->guestInfo, sizeof (guestInfo->guestInfo)) != 0)
{
/* make a copy of supplied information */
pThis->guestInfo = guestInfo->guestInfo;
/* Check additions version */
pThis->fu32AdditionsOk = VBOX_GUEST_ADDITIONS_VERSION_OK(pThis->guestInfo.additionsVersion);
LogRel(("Guest Additions information report: additionsVersion = 0x%08X osType = 0x%08X\n",
pThis->guestInfo.additionsVersion,
pThis->guestInfo.osType));
pThis->pDrv->pfnUpdateGuestVersion(pThis->pDrv, &pThis->guestInfo);
}
if (pThis->fu32AdditionsOk)
{
pRequestHeader->rc = VINF_SUCCESS;
}
else
{
pRequestHeader->rc = VERR_VERSION_MISMATCH;
}
}
break;
}
/* Report guest capabilities */
case VMMDevReq_ReportGuestCapabilities:
{
if (pRequestHeader->size != sizeof(VMMDevReqGuestCapabilities))
{
AssertMsgFailed(("VMMDev guest caps structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqGuestCapabilities *guestCaps = (VMMDevReqGuestCapabilities*)pRequestHeader;
/* Enable this automatically for guests using the old
request to report their capabilities. */
/** @todo change this when we next bump the interface version */
guestCaps->caps |= VMMDEV_GUEST_SUPPORTS_GRAPHICS;
if (pThis->guestCaps != guestCaps->caps)
{
/* make a copy of supplied information */
pThis->guestCaps = guestCaps->caps;
LogRel(("Guest Additions capability report: (0x%x) "
"seamless: %s, "
"hostWindowMapping: %s, "
"graphics: %s\n",
guestCaps->caps,
guestCaps->caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
guestCaps->caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no",
guestCaps->caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? "yes" : "no"));
pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, guestCaps->caps);
}
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/* Change guest capabilities */
case VMMDevReq_SetGuestCapabilities:
{
if (pRequestHeader->size != sizeof(VMMDevReqGuestCapabilities2))
{
AssertMsgFailed(("VMMDev guest caps structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqGuestCapabilities2 *guestCaps = (VMMDevReqGuestCapabilities2*)pRequestHeader;
pThis->guestCaps |= guestCaps->u32OrMask;
pThis->guestCaps &= ~guestCaps->u32NotMask;
LogRel(("Guest Additions capability report: (0x%x) "
"seamless: %s, "
"hostWindowMapping: %s, "
"graphics: %s\n",
pThis->guestCaps,
pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no",
pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? "yes" : "no"));
pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/*
* Retrieve mouse information
*/
case VMMDevReq_GetMouseStatus:
{
if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
{
AssertMsgFailed(("VMMDev mouse status structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)pRequestHeader;
mouseStatus->mouseFeatures = pThis->mouseCapabilities
& VMMDEV_MOUSE_MASK;
mouseStatus->pointerXPos = pThis->mouseXAbs;
mouseStatus->pointerYPos = pThis->mouseYAbs;
LogRel2(("%s: VMMDevReq_GetMouseStatus: features = 0x%x, absX = %d, absY = %d\n",
__PRETTY_FUNCTION__,
mouseStatus->mouseFeatures,
mouseStatus->pointerXPos,
mouseStatus->pointerYPos));
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/*
* Set mouse information
*/
case VMMDevReq_SetMouseStatus:
{
if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
{
AssertMsgFailed(("VMMDev mouse status structure has invalid size %d (%#x) version=%d!\n",
pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
bool fNotify = false;
uint32_t fFeatures =
((VMMDevReqMouseStatus*)pRequestHeader)->mouseFeatures;
LogRelFlowFunc(("VMMDevReqMouseStatus: mouseFeatures = 0x%x\n",
fFeatures));
if ( (fFeatures & VMMDEV_MOUSE_NOTIFY_HOST_MASK)
!= ( pThis->mouseCapabilities
& VMMDEV_MOUSE_NOTIFY_HOST_MASK))
fNotify = true;
pThis->mouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
pThis->mouseCapabilities |=
(fFeatures & VMMDEV_MOUSE_GUEST_MASK);
LogRelFlowFunc(("VMMDevReq_SetMouseStatus: new host capabilities: 0x%x\n",
pThis->mouseCapabilities));
/*
* Notify connector if something has changed
*/
if (fNotify)
{
LogRelFlowFunc(("VMMDevReq_SetMouseStatus: notifying connector\n"));
pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
}
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/*
* Set a new mouse pointer shape
*/
case VMMDevReq_SetPointerShape:
{
if (pRequestHeader->size < sizeof(VMMDevReqMousePointer))
{
AssertMsg(pRequestHeader->size == 0x10028 && pRequestHeader->version == 10000, /* don't bitch about legacy!!! */
("VMMDev mouse shape structure has invalid size %d (%#x) version=%d!\n",
pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqMousePointer *pointerShape = (VMMDevReqMousePointer*)pRequestHeader;
bool fVisible = (pointerShape->fFlags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
bool fAlpha = (pointerShape->fFlags & VBOX_MOUSE_POINTER_ALPHA) != 0;
bool fShape = (pointerShape->fFlags & VBOX_MOUSE_POINTER_SHAPE) != 0;
Log(("VMMDevReq_SetPointerShape: visible: %d, alpha: %d, shape = %d, width: %d, height: %d\n",
fVisible, fAlpha, fShape, pointerShape->width, pointerShape->height));
if (pRequestHeader->size == sizeof(VMMDevReqMousePointer))
{
/* The guest did not provide the shape actually. */
fShape = false;
}
/* forward call to driver */
if (fShape)
{
pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
fVisible,
fAlpha,
pointerShape->xHot, pointerShape->yHot,
pointerShape->width, pointerShape->height,
pointerShape->pointerData);
}
else
{
pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
fVisible,
0,
0, 0,
0, 0,
NULL);
}
pThis->fHostCursorRequested = fVisible;
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/*
* Query the system time from the host
*/
case VMMDevReq_GetHostTime:
{
if (pRequestHeader->size != sizeof(VMMDevReqHostTime))
{
AssertMsgFailed(("VMMDev host time structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (RT_UNLIKELY(pThis->fGetHostTimeDisabled))
pRequestHeader->rc = VERR_NOT_SUPPORTED;
else
{
VMMDevReqHostTime *hostTimeReq = (VMMDevReqHostTime*)pRequestHeader;
RTTIMESPEC now;
hostTimeReq->time = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &now));
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/*
* Query information about the hypervisor
*/
case VMMDevReq_GetHypervisorInfo:
{
if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
{
AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
PVM pVM = PDMDevHlpGetVM(pDevIns);
pRequestHeader->rc = PGMR3MappingsSize(pVM, &hypervisorInfo->hypervisorSize);
}
break;
}
/*
* Set hypervisor information
*/
case VMMDevReq_SetHypervisorInfo:
{
if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
{
AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
PVM pVM = PDMDevHlpGetVM(pDevIns);
if (hypervisorInfo->hypervisorStart == 0)
pRequestHeader->rc = PGMR3MappingsUnfix(pVM);
else
{
/* only if the client has queried the size before! */
uint32_t mappingsSize;
pRequestHeader->rc = PGMR3MappingsSize(pVM, &mappingsSize);
if (RT_SUCCESS(pRequestHeader->rc) && hypervisorInfo->hypervisorSize == mappingsSize)
{
/* new reservation */
pRequestHeader->rc = PGMR3MappingsFix(pVM, hypervisorInfo->hypervisorStart,
hypervisorInfo->hypervisorSize);
LogRel(("Guest reported fixed hypervisor window at 0x%p (size = 0x%x, rc = %Rrc)\n",
(uintptr_t)hypervisorInfo->hypervisorStart,
hypervisorInfo->hypervisorSize,
pRequestHeader->rc));
}
}
}
break;
}
case VMMDevReq_RegisterPatchMemory:
{
if (pRequestHeader->size != sizeof(VMMDevReqPatchMemory))
{
AssertMsgFailed(("VMMDevReq_RegisterPatchMemory structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqPatchMemory *pPatchRequest = (VMMDevReqPatchMemory*)pRequestHeader;
pRequestHeader->rc = VMMR3RegisterPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
}
break;
}
case VMMDevReq_DeregisterPatchMemory:
{
if (pRequestHeader->size != sizeof(VMMDevReqPatchMemory))
{
AssertMsgFailed(("VMMDevReq_DeregisterPatchMemory structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqPatchMemory *pPatchRequest = (VMMDevReqPatchMemory*)pRequestHeader;
pRequestHeader->rc = VMMR3DeregisterPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
}
break;
}
/*
* Set the system power status
*/
case VMMDevReq_SetPowerStatus:
{
if (pRequestHeader->size != sizeof(VMMDevPowerStateRequest))
{
AssertMsgFailed(("VMMDev power state request structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevPowerStateRequest *powerStateRequest = (VMMDevPowerStateRequest*)pRequestHeader;
switch(powerStateRequest->powerState)
{
case VMMDevPowerState_Pause:
{
LogRel(("Guest requests the VM to be suspended (paused)\n"));
pRequestHeader->rc = rcRet = PDMDevHlpVMSuspend(pDevIns);
break;
}
case VMMDevPowerState_PowerOff:
{
LogRel(("Guest requests the VM to be turned off\n"));
pRequestHeader->rc = rcRet = PDMDevHlpVMPowerOff(pDevIns);
break;
}
case VMMDevPowerState_SaveState:
{
/** @todo no API for that yet */
pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
break;
}
default:
AssertMsgFailed(("VMMDev invalid power state request: %d\n", powerStateRequest->powerState));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
break;
}
}
break;
}
/*
* Get display change request
*/
case VMMDevReq_GetDisplayChangeRequest:
{
if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest))
{
/* Assert only if the size also not equal to a previous version size to prevent
* assertion with old additions.
*/
AssertMsg(pRequestHeader->size == sizeof(VMMDevDisplayChangeRequest) - sizeof (uint32_t),
("VMMDev display change request structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevDisplayChangeRequest *displayChangeRequest = (VMMDevDisplayChangeRequest*)pRequestHeader;
DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[0];
if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
{
/* Current request has been read at least once. */
pRequest->fPending = false;
/* Check if there are more pending requests. */
for (unsigned i = 1; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
{
if (pThis->displayChangeData.aRequests[i].fPending)
{
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
break;
}
}
/* Remember which resolution the client has queried, subsequent reads
* will return the same values. */
pRequest->lastReadDisplayChangeRequest = pRequest->displayChangeRequest;
pThis->displayChangeData.fGuestSentChangeEventAck = true;
}
if (pThis->displayChangeData.fGuestSentChangeEventAck)
{
displayChangeRequest->xres = pRequest->lastReadDisplayChangeRequest.xres;
displayChangeRequest->yres = pRequest->lastReadDisplayChangeRequest.yres;
displayChangeRequest->bpp = pRequest->lastReadDisplayChangeRequest.bpp;
}
else
{
/* This is not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
* read the last valid video mode hint. This happens when the guest X server
* determines the initial mode. */
displayChangeRequest->xres = pRequest->displayChangeRequest.xres;
displayChangeRequest->yres = pRequest->displayChangeRequest.yres;
displayChangeRequest->bpp = pRequest->displayChangeRequest.bpp;
}
Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d\n",
displayChangeRequest->xres, displayChangeRequest->yres, displayChangeRequest->bpp));
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
case VMMDevReq_GetDisplayChangeRequest2:
{
if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest2))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevDisplayChangeRequest2 *displayChangeRequest = (VMMDevDisplayChangeRequest2*)pRequestHeader;
DISPLAYCHANGEREQUEST *pRequest = NULL;
if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
{
/* Select a pending request to report. */
unsigned i;
for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
{
if (pThis->displayChangeData.aRequests[i].fPending)
{
pRequest = &pThis->displayChangeData.aRequests[i];
/* Remember which request should be reported. */
pThis->displayChangeData.iCurrentMonitor = i;
Log3(("VMMDev: will report pending request for %d\n",
i));
break;
}
}
/* Check if there are more pending requests. */
i++;
for (; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
{
if (pThis->displayChangeData.aRequests[i].fPending)
{
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
Log3(("VMMDev: another pending at %d\n",
i));
break;
}
}
if (pRequest)
{
/* Current request has been read at least once. */
pRequest->fPending = false;
/* Remember which resolution the client has queried, subsequent reads
* will return the same values. */
pRequest->lastReadDisplayChangeRequest = pRequest->displayChangeRequest;
pThis->displayChangeData.fGuestSentChangeEventAck = true;
}
else
{
Log3(("VMMDev: no pending request!!!\n"));
}
}
if (!pRequest)
{
Log3(("VMMDev: default to %d\n",
pThis->displayChangeData.iCurrentMonitor));
pRequest = &pThis->displayChangeData.aRequests[pThis->displayChangeData.iCurrentMonitor];
}
if (pThis->displayChangeData.fGuestSentChangeEventAck)
{
displayChangeRequest->xres = pRequest->lastReadDisplayChangeRequest.xres;
displayChangeRequest->yres = pRequest->lastReadDisplayChangeRequest.yres;
displayChangeRequest->bpp = pRequest->lastReadDisplayChangeRequest.bpp;
displayChangeRequest->display = pRequest->lastReadDisplayChangeRequest.display;
}
else
{
/* This is not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
* read the last valid video mode hint. This happens when the guest X server
* determines the initial video mode. */
displayChangeRequest->xres = pRequest->displayChangeRequest.xres;
displayChangeRequest->yres = pRequest->displayChangeRequest.yres;
displayChangeRequest->bpp = pRequest->displayChangeRequest.bpp;
displayChangeRequest->display = pRequest->displayChangeRequest.display;
}
Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d at %d\n",
displayChangeRequest->xres, displayChangeRequest->yres, displayChangeRequest->bpp, displayChangeRequest->display));
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/*
* Query whether the given video mode is supported
*/
case VMMDevReq_VideoModeSupported:
{
if (pRequestHeader->size != sizeof(VMMDevVideoModeSupportedRequest))
{
AssertMsgFailed(("VMMDev video mode supported request structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevVideoModeSupportedRequest *videoModeSupportedRequest = (VMMDevVideoModeSupportedRequest*)pRequestHeader;
/* forward the call */
pRequestHeader->rc = pThis->pDrv->pfnVideoModeSupported(pThis->pDrv,
0, /* primary screen. */
videoModeSupportedRequest->width,
videoModeSupportedRequest->height,
videoModeSupportedRequest->bpp,
&videoModeSupportedRequest->fSupported);
}
break;
}
/*
* Query whether the given video mode is supported for a specific display
*/
case VMMDevReq_VideoModeSupported2:
{
if (pRequestHeader->size != sizeof(VMMDevVideoModeSupportedRequest2))
{
AssertMsgFailed(("VMMDev video mode supported request 2 structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevVideoModeSupportedRequest2 *videoModeSupportedRequest2 = (VMMDevVideoModeSupportedRequest2*)pRequestHeader;
/* forward the call */
pRequestHeader->rc = pThis->pDrv->pfnVideoModeSupported(pThis->pDrv,
videoModeSupportedRequest2->display,
videoModeSupportedRequest2->width,
videoModeSupportedRequest2->height,
videoModeSupportedRequest2->bpp,
&videoModeSupportedRequest2->fSupported);
}
break;
}
/*
* Query the height reduction in pixels
*/
case VMMDevReq_GetHeightReduction:
{
if (pRequestHeader->size != sizeof(VMMDevGetHeightReductionRequest))
{
AssertMsgFailed(("VMMDev height reduction request structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevGetHeightReductionRequest *heightReductionRequest = (VMMDevGetHeightReductionRequest*)pRequestHeader;
/* forward the call */
pRequestHeader->rc = pThis->pDrv->pfnGetHeightReduction(pThis->pDrv,
&heightReductionRequest->heightReduction);
}
break;
}
/*
* Acknowledge VMMDev events
*/
case VMMDevReq_AcknowledgeEvents:
{
if (pRequestHeader->size != sizeof(VMMDevEvents))
{
AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
if (VBOX_GUEST_ADDITIONS_VERSION_1_03 (pThis))
{
vmmdevSetIRQ_Legacy_EMT (pThis);
}
else
{
VMMDevEvents *pAckRequest;
if (pThis->fNewGuestFilterMask)
{
pThis->fNewGuestFilterMask = false;
pThis->u32GuestFilterMask = pThis->u32NewGuestFilterMask;
}
pAckRequest = (VMMDevEvents *)pRequestHeader;
pAckRequest->events =
pThis->u32HostEventFlags & pThis->u32GuestFilterMask;
pThis->u32HostEventFlags &= ~pThis->u32GuestFilterMask;
pThis->pVMMDevRAMR3->V.V1_04.fHaveEvents = false;
PDMDevHlpPCISetIrqNoWait (pThis->pDevIns, 0, 0);
}
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/*
* Change guest filter mask
*/
case VMMDevReq_CtlGuestFilterMask:
{
if (pRequestHeader->size != sizeof(VMMDevCtlGuestFilterMask))
{
AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevCtlGuestFilterMask *pCtlMaskRequest;
pCtlMaskRequest = (VMMDevCtlGuestFilterMask *)pRequestHeader;
LogRelFlowFunc(("VMMDevCtlGuestFilterMask: or mask: 0x%x, not mask: 0x%x\n",
pCtlMaskRequest->u32OrMask,
pCtlMaskRequest->u32NotMask));
/* HGCM event notification is enabled by the VMMDev device
* automatically when any HGCM command is issued. The guest
* cannot disable these notifications.
*/
VMMDevCtlSetGuestFilterMask (pThis,
pCtlMaskRequest->u32OrMask,
pCtlMaskRequest->u32NotMask & ~VMMDEV_EVENT_HGCM);
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
#ifdef VBOX_WITH_HGCM
/*
* Process HGCM request
*/
case VMMDevReq_HGCMConnect:
{
if (pRequestHeader->size < sizeof(VMMDevHGCMConnect))
{
AssertMsgFailed(("VMMDevReq_HGCMConnect structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (!pThis->pHGCMDrv)
{
Log(("VMMDevReq_HGCMConnect HGCM Connector is NULL!\n"));
pRequestHeader->rc = VERR_NOT_SUPPORTED;
}
else
{
VMMDevHGCMConnect *pHGCMConnect = (VMMDevHGCMConnect *)pRequestHeader;
Log(("VMMDevReq_HGCMConnect\n"));
pRequestHeader->rc = vmmdevHGCMConnect (pThis, pHGCMConnect, (RTGCPHYS)u32);
}
break;
}
case VMMDevReq_HGCMDisconnect:
{
if (pRequestHeader->size < sizeof(VMMDevHGCMDisconnect))
{
AssertMsgFailed(("VMMDevReq_HGCMDisconnect structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (!pThis->pHGCMDrv)
{
Log(("VMMDevReq_HGCMDisconnect HGCM Connector is NULL!\n"));
pRequestHeader->rc = VERR_NOT_SUPPORTED;
}
else
{
VMMDevHGCMDisconnect *pHGCMDisconnect = (VMMDevHGCMDisconnect *)pRequestHeader;
Log(("VMMDevReq_VMMDevHGCMDisconnect\n"));
pRequestHeader->rc = vmmdevHGCMDisconnect (pThis, pHGCMDisconnect, (RTGCPHYS)u32);
}
break;
}
#ifdef VBOX_WITH_64_BITS_GUESTS
case VMMDevReq_HGCMCall32:
case VMMDevReq_HGCMCall64:
#else
case VMMDevReq_HGCMCall:
#endif /* VBOX_WITH_64_BITS_GUESTS */
{
if (pRequestHeader->size < sizeof(VMMDevHGCMCall))
{
AssertMsgFailed(("VMMDevReq_HGCMCall structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (!pThis->pHGCMDrv)
{
Log(("VMMDevReq_HGCMCall HGCM Connector is NULL!\n"));
pRequestHeader->rc = VERR_NOT_SUPPORTED;
}
else
{
VMMDevHGCMCall *pHGCMCall = (VMMDevHGCMCall *)pRequestHeader;
Log2(("VMMDevReq_HGCMCall: sizeof (VMMDevHGCMRequest) = %04X\n", sizeof (VMMDevHGCMCall)));
Log2(("%.*Rhxd\n", pRequestHeader->size, pRequestHeader));
#ifdef VBOX_WITH_64_BITS_GUESTS
bool f64Bits = (pRequestHeader->requestType == VMMDevReq_HGCMCall64);
#else
bool f64Bits = false;
#endif /* VBOX_WITH_64_BITS_GUESTS */
pRequestHeader->rc = vmmdevHGCMCall (pThis, pHGCMCall, requestHeader.size, (RTGCPHYS)u32, f64Bits);
}
break;
}
#endif /* VBOX_WITH_HGCM */
case VMMDevReq_HGCMCancel:
{
if (pRequestHeader->size < sizeof(VMMDevHGCMCancel))
{
AssertMsgFailed(("VMMDevReq_HGCMCancel structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (!pThis->pHGCMDrv)
{
Log(("VMMDevReq_HGCMCancel HGCM Connector is NULL!\n"));
pRequestHeader->rc = VERR_NOT_SUPPORTED;
}
else
{
VMMDevHGCMCancel *pHGCMCancel = (VMMDevHGCMCancel *)pRequestHeader;
Log(("VMMDevReq_VMMDevHGCMCancel\n"));
pRequestHeader->rc = vmmdevHGCMCancel (pThis, pHGCMCancel, (RTGCPHYS)u32);
}
break;
}
case VMMDevReq_HGCMCancel2:
{
if (pRequestHeader->size != sizeof(VMMDevHGCMCancel2))
{
AssertMsgFailed(("VMMDevReq_HGCMCancel structure has invalid size!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (!pThis->pHGCMDrv)
{
Log(("VMMDevReq_HGCMCancel HGCM Connector is NULL!\n"));
pRequestHeader->rc = VERR_NOT_SUPPORTED;
}
else
{
VMMDevHGCMCancel2 *pHGCMCancel2 = (VMMDevHGCMCancel2 *)pRequestHeader;
Log(("VMMDevReq_VMMDevHGCMCancel\n"));
pRequestHeader->rc = vmmdevHGCMCancel2 (pThis, pHGCMCancel2->physReqToCancel);
}
break;
}
case VMMDevReq_VideoAccelEnable:
{
if (pRequestHeader->size < sizeof(VMMDevVideoAccelEnable))
{
Log(("VMMDevReq_VideoAccelEnable request size too small!!!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (!pThis->pDrv)
{
Log(("VMMDevReq_VideoAccelEnable Connector is NULL!!!\n"));
pRequestHeader->rc = VERR_NOT_SUPPORTED;
}
else
{
VMMDevVideoAccelEnable *ptr = (VMMDevVideoAccelEnable *)pRequestHeader;
if (ptr->cbRingBuffer != VBVA_RING_BUFFER_SIZE)
{
/* The guest driver seems compiled with another headers. */
Log(("VMMDevReq_VideoAccelEnable guest ring buffer size %d, should be %d!!!\n", ptr->cbRingBuffer, VBVA_RING_BUFFER_SIZE));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
/* The request is correct. */
ptr->fu32Status |= VBVA_F_STATUS_ACCEPTED;
LogFlow(("VMMDevReq_VideoAccelEnable ptr->u32Enable = %d\n", ptr->u32Enable));
pRequestHeader->rc = ptr->u32Enable?
pThis->pDrv->pfnVideoAccelEnable (pThis->pDrv, true, &pThis->pVMMDevRAMR3->vbvaMemory):
pThis->pDrv->pfnVideoAccelEnable (pThis->pDrv, false, NULL);
if ( ptr->u32Enable
&& RT_SUCCESS (pRequestHeader->rc))
{
ptr->fu32Status |= VBVA_F_STATUS_ENABLED;
/* Remember that guest successfully enabled acceleration.
* We need to reestablish it on restoring the VM from saved state.
*/
pThis->u32VideoAccelEnabled = 1;
}
else
{
/* The acceleration was not enabled. Remember that. */
pThis->u32VideoAccelEnabled = 0;
}
}
}
break;
}
case VMMDevReq_VideoAccelFlush:
{
if (pRequestHeader->size < sizeof(VMMDevVideoAccelFlush))
{
AssertMsgFailed(("VMMDevReq_VideoAccelFlush request size too small.\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (!pThis->pDrv)
{
Log(("VMMDevReq_VideoAccelFlush Connector is NULL!\n"));
pRequestHeader->rc = VERR_NOT_SUPPORTED;
}
else
{
pThis->pDrv->pfnVideoAccelFlush (pThis->pDrv);
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
case VMMDevReq_VideoSetVisibleRegion:
{
if (pRequestHeader->size < sizeof(VMMDevVideoSetVisibleRegion))
{
Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else if (!pThis->pDrv)
{
Log(("VMMDevReq_VideoSetVisibleRegion Connector is NULL!!!\n"));
pRequestHeader->rc = VERR_NOT_SUPPORTED;
}
else
{
VMMDevVideoSetVisibleRegion *ptr = (VMMDevVideoSetVisibleRegion *)pRequestHeader;
if (!ptr->cRect)
{
Log(("VMMDevReq_VideoSetVisibleRegion no rectangles!!!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
if (pRequestHeader->size != sizeof(VMMDevVideoSetVisibleRegion) + (ptr->cRect-1)*sizeof(RTRECT))
{
Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", ptr->cRect));
/* forward the call */
pRequestHeader->rc = pThis->pDrv->pfnSetVisibleRegion(pThis->pDrv, ptr->cRect, &ptr->Rect);
}
}
break;
}
case VMMDevReq_GetSeamlessChangeRequest:
{
if (pRequestHeader->size != sizeof(VMMDevSeamlessChangeRequest))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevSeamlessChangeRequest *seamlessChangeRequest = (VMMDevSeamlessChangeRequest*)pRequestHeader;
/* just pass on the information */
Log(("VMMDev: returning seamless change request mode=%d\n", pThis->fSeamlessEnabled));
if (pThis->fSeamlessEnabled)
seamlessChangeRequest->mode = VMMDev_Seamless_Visible_Region;
else
seamlessChangeRequest->mode = VMMDev_Seamless_Disabled;
if (seamlessChangeRequest->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
{
/* Remember which mode the client has queried. */
pThis->fLastSeamlessEnabled = pThis->fSeamlessEnabled;
}
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
case VMMDevReq_GetVRDPChangeRequest:
{
if (pRequestHeader->size != sizeof(VMMDevVRDPChangeRequest))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevVRDPChangeRequest *vrdpChangeRequest = (VMMDevVRDPChangeRequest*)pRequestHeader;
/* just pass on the information */
Log(("VMMDev: returning VRDP status %d level %d\n", pThis->fVRDPEnabled, pThis->u32VRDPExperienceLevel));
vrdpChangeRequest->u8VRDPActive = pThis->fVRDPEnabled;
vrdpChangeRequest->u32VRDPExperienceLevel = pThis->u32VRDPExperienceLevel;
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
case VMMDevReq_GetMemBalloonChangeRequest:
{
Log(("VMMDevReq_GetMemBalloonChangeRequest\n"));
if (pRequestHeader->size != sizeof(VMMDevGetMemBalloonChangeRequest))
{
AssertFailed();
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevGetMemBalloonChangeRequest *memBalloonChangeRequest = (VMMDevGetMemBalloonChangeRequest*)pRequestHeader;
/* just pass on the information */
Log(("VMMDev: returning memory balloon size =%d\n", pThis->u32MemoryBalloonSize));
memBalloonChangeRequest->cBalloonChunks = pThis->u32MemoryBalloonSize;
memBalloonChangeRequest->cPhysMemChunks = pThis->cbGuestRAM / (uint64_t)_1M;
if (memBalloonChangeRequest->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
{
/* Remember which mode the client has queried. */
pThis->u32LastMemoryBalloonSize = pThis->u32MemoryBalloonSize;
}
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
case VMMDevReq_ChangeMemBalloon:
{
VMMDevChangeMemBalloon *memBalloonChange = (VMMDevChangeMemBalloon*)pRequestHeader;
Log(("VMMDevReq_ChangeMemBalloon\n"));
if ( pRequestHeader->size < sizeof(VMMDevChangeMemBalloon)
|| memBalloonChange->cPages != VMMDEV_MEMORY_BALLOON_CHUNK_PAGES
|| pRequestHeader->size != (uint32_t)RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[memBalloonChange->cPages]))
{
AssertFailed();
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
pRequestHeader->rc = PGMR3PhysChangeMemBalloon(PDMDevHlpGetVM(pDevIns), !!memBalloonChange->fInflate, memBalloonChange->cPages, memBalloonChange->aPhysPage);
if (memBalloonChange->fInflate)
STAM_REL_U32_INC(&pThis->StatMemBalloonChunks);
else
STAM_REL_U32_DEC(&pThis->StatMemBalloonChunks);
}
break;
}
case VMMDevReq_GetStatisticsChangeRequest:
{
Log(("VMMDevReq_GetStatisticsChangeRequest\n"));
if (pRequestHeader->size != sizeof(VMMDevGetStatisticsChangeRequest))
{
AssertFailed();
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevGetStatisticsChangeRequest *statIntervalChangeRequest = (VMMDevGetStatisticsChangeRequest*)pRequestHeader;
/* just pass on the information */
Log(("VMMDev: returning statistics interval %d seconds\n", pThis->u32StatIntervalSize));
statIntervalChangeRequest->u32StatInterval = pThis->u32StatIntervalSize;
if (statIntervalChangeRequest->eventAck == VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
{
/* Remember which mode the client has queried. */
pThis->u32LastStatIntervalSize= pThis->u32StatIntervalSize;
}
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
case VMMDevReq_ReportGuestStats:
{
Log(("VMMDevReq_ReportGuestStats\n"));
if (pRequestHeader->size != sizeof(VMMDevReportGuestStats))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReportGuestStats *stats = (VMMDevReportGuestStats*)pRequestHeader;
#ifdef DEBUG
VBoxGuestStatistics *pGuestStats = &stats->guestStats;
Log(("Current statistics:\n"));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
Log(("CPU%d: CPU Load Idle %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Idle));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
Log(("CPU%d: CPU Load Kernel %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Kernel));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
Log(("CPU%d: CPU Load User %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_User));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
Log(("CPU%d: Thread %d\n", pGuestStats->u32CpuId, pGuestStats->u32Threads));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
Log(("CPU%d: Processes %d\n", pGuestStats->u32CpuId, pGuestStats->u32Processes));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
Log(("CPU%d: Handles %d\n", pGuestStats->u32CpuId, pGuestStats->u32Handles));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
Log(("CPU%d: Memory Load %d%%\n", pGuestStats->u32CpuId, pGuestStats->u32MemoryLoad));
/* Note that reported values are in pages; upper layers expect them in megabytes */
Log(("CPU%d: Page size %-4d bytes\n", pGuestStats->u32CpuId, pGuestStats->u32PageSize));
Assert(pGuestStats->u32PageSize == 4096);
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
Log(("CPU%d: Total physical memory %-4d MB\n", pGuestStats->u32CpuId, (pGuestStats->u32PhysMemTotal + (_1M/_4K)-1) / (_1M/_4K)));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
Log(("CPU%d: Free physical memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemAvail / (_1M/_4K)));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
Log(("CPU%d: Memory balloon size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemBalloon / (_1M/_4K)));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
Log(("CPU%d: Committed memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemCommitTotal / (_1M/_4K)));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
Log(("CPU%d: Total kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelTotal / (_1M/_4K)));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
Log(("CPU%d: Paged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelPaged / (_1M/_4K)));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
Log(("CPU%d: Nonpaged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelNonPaged / (_1M/_4K)));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
Log(("CPU%d: System cache size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemSystemCache / (_1M/_4K)));
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
Log(("CPU%d: Page file size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PageFileSize / (_1M/_4K)));
Log(("Statistics end *******************\n"));
#endif
/* forward the call */
pRequestHeader->rc = pThis->pDrv->pfnReportStatistics(pThis->pDrv, &stats->guestStats);
}
break;
}
case VMMDevReq_QueryCredentials:
{
if (pRequestHeader->size != sizeof(VMMDevCredentials))
{
AssertMsgFailed(("VMMDevReq_QueryCredentials request size too small.\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
/* let's start by nulling out the data */
memset(credentials->szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(credentials->szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(credentials->szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
/* should we return whether we got credentials for a logon? */
if (credentials->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
{
if ( pThis->credentialsLogon.szUserName[0]
|| pThis->credentialsLogon.szPassword[0]
|| pThis->credentialsLogon.szDomain[0])
{
credentials->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
}
else
{
credentials->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
}
}
/* does the guest want to read logon credentials? */
if (credentials->u32Flags & VMMDEV_CREDENTIALS_READ)
{
if (pThis->credentialsLogon.szUserName[0])
strcpy(credentials->szUserName, pThis->credentialsLogon.szUserName);
if (pThis->credentialsLogon.szPassword[0])
strcpy(credentials->szPassword, pThis->credentialsLogon.szPassword);
if (pThis->credentialsLogon.szDomain[0])
strcpy(credentials->szDomain, pThis->credentialsLogon.szDomain);
if (!pThis->credentialsLogon.fAllowInteractiveLogon)
credentials->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
else
credentials->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
}
if (!pThis->fKeepCredentials)
{
/* does the caller want us to destroy the logon credentials? */
if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
{
memset(pThis->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(pThis->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(pThis->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
}
}
/* does the guest want to read credentials for verification? */
if (credentials->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
{
if (pThis->credentialsJudge.szUserName[0])
strcpy(credentials->szUserName, pThis->credentialsJudge.szUserName);
if (pThis->credentialsJudge.szPassword[0])
strcpy(credentials->szPassword, pThis->credentialsJudge.szPassword);
if (pThis->credentialsJudge.szDomain[0])
strcpy(credentials->szDomain, pThis->credentialsJudge.szDomain);
}
/* does the caller want us to destroy the judgement credentials? */
if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
{
memset(pThis->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(pThis->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(pThis->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
}
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
case VMMDevReq_ReportCredentialsJudgement:
{
if (pRequestHeader->size != sizeof(VMMDevCredentials))
{
AssertMsgFailed(("VMMDevReq_ReportCredentialsJudgement request size too small.\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
/* what does the guest think about the credentials? (note: the order is important here!) */
if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
{
pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
}
else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
{
pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
}
else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
{
pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
}
else
Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", credentials->u32Flags));
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
/*
* Implemented in 3.1.0.
*
* Note! The ring-0 VBoxGuestLib uses this to check whether
* VMMDevHGCMParmType_PageList is supported.
*/
case VMMDevReq_GetHostVersion:
{
AssertMsgBreakStmt(pRequestHeader->size == sizeof(VMMDevReqHostVersion),
("%#x < %#x\n", pRequestHeader->size, sizeof(VMMDevReqLogString)),
pRequestHeader->rc = VERR_INVALID_PARAMETER);
VMMDevReqHostVersion *pReqHostVer = (VMMDevReqHostVersion*)pRequestHeader;
pReqHostVer->major = RTBldCfgVersionMajor();
pReqHostVer->minor = RTBldCfgVersionMinor();
pReqHostVer->build = RTBldCfgVersionBuild();
pReqHostVer->revision = RTBldCfgRevision();
pReqHostVer->features = VMMDEV_HVF_HGCM_PHYS_PAGE_LIST;
pReqHostVer->header.rc = VINF_SUCCESS;
break;
}
case VMMDevReq_GetCpuHotPlugRequest:
{
VMMDevGetCpuHotPlugRequest *pReqCpuHotPlug = (VMMDevGetCpuHotPlugRequest *)pRequestHeader;
if (pRequestHeader->size != sizeof(VMMDevGetCpuHotPlugRequest))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
pReqCpuHotPlug->enmEventType = pThis->enmCpuHotPlugEvent;
pReqCpuHotPlug->idCpuCore = pThis->idCpuCore;
pReqCpuHotPlug->idCpuPackage = pThis->idCpuPackage;
pReqCpuHotPlug->header.rc = VINF_SUCCESS;
/* Clear the event */
pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_None;
pThis->idCpuCore = UINT32_MAX;
pThis->idCpuPackage = UINT32_MAX;
}
break;
}
case VMMDevReq_SetCpuHotPlugStatus:
{
VMMDevCpuHotPlugStatusRequest *pReqCpuHotPlugStatus = (VMMDevCpuHotPlugStatusRequest *)pRequestHeader;
if (pRequestHeader->size != sizeof(VMMDevCpuHotPlugStatusRequest))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
pRequestHeader->rc = VINF_SUCCESS;
if (pReqCpuHotPlugStatus->enmStatusType == VMMDevCpuStatusType_Disable)
pThis->fCpuHotPlugEventsEnabled = false;
else if (pReqCpuHotPlugStatus->enmStatusType == VMMDevCpuStatusType_Enable)
pThis->fCpuHotPlugEventsEnabled = true;
else
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
break;
}
#ifdef VBOX_WITH_PAGE_SHARING
case VMMDevReq_RegisterSharedModule:
{
VMMDevSharedModuleRegistrationRequest *pReqModule = (VMMDevSharedModuleRegistrationRequest *)pRequestHeader;
if ( pRequestHeader->size < sizeof(VMMDevSharedModuleRegistrationRequest)
|| pRequestHeader->size != RT_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[pReqModule->cRegions]))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
pRequestHeader->rc = PGMR3SharedModuleRegister(PDMDevHlpGetVM(pDevIns), pReqModule->enmGuestOS, pReqModule->szName, pReqModule->szVersion,
pReqModule->GCBaseAddr, pReqModule->cbModule,
pReqModule->cRegions, pReqModule->aRegions);
}
break;
}
case VMMDevReq_UnregisterSharedModule:
{
VMMDevSharedModuleUnregistrationRequest *pReqModule = (VMMDevSharedModuleUnregistrationRequest *)pRequestHeader;
if (pRequestHeader->size != sizeof(VMMDevSharedModuleUnregistrationRequest))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
pRequestHeader->rc = PGMR3SharedModuleUnregister(PDMDevHlpGetVM(pDevIns), pReqModule->szName, pReqModule->szVersion,
pReqModule->GCBaseAddr, pReqModule->cbModule);
}
break;
}
case VMMDevReq_CheckSharedModules:
{
VMMDevSharedModuleCheckRequest *pReqModule = (VMMDevSharedModuleCheckRequest *)pRequestHeader;
if (pRequestHeader->size != sizeof(VMMDevSharedModuleCheckRequest))
pRequestHeader->rc = VERR_INVALID_PARAMETER;
else
pRequestHeader->rc = PGMR3SharedModuleCheckAll(PDMDevHlpGetVM(pDevIns));
break;
}
case VMMDevReq_GetPageSharingStatus:
{
VMMDevPageSharingStatusRequest *pReqStatus = (VMMDevPageSharingStatusRequest *)pRequestHeader;
if (pRequestHeader->size != sizeof(VMMDevPageSharingStatusRequest))
{
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
pReqStatus->fEnabled = false;
pThis->pDrv->pfnIsPageFusionEnabled(pThis->pDrv, &pReqStatus->fEnabled);
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
#endif
#ifdef DEBUG
case VMMDevReq_LogString:
{
if (pRequestHeader->size < sizeof(VMMDevReqLogString))
{
AssertMsgFailed(("VMMDevReq_LogString request size too small.\n"));
pRequestHeader->rc = VERR_INVALID_PARAMETER;
}
else
{
VMMDevReqLogString *pReqLogString = (VMMDevReqLogString *)pRequestHeader;
LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR,
("DEBUG LOG: %s", pReqLogString->szString));
pRequestHeader->rc = VINF_SUCCESS;
}
break;
}
#endif
default:
{
pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
Log(("VMMDev unknown request type %d\n", pRequestHeader->requestType));
break;
}
}
end:
/* Write the result back to guest memory */
if (pRequestHeader)
{
PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, pRequestHeader, pRequestHeader->size);
RTMemFree(pRequestHeader);
}
else
{
/* early error case; write back header only */
PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
}
PDMCritSectLeave(&pThis->CritSect);
return rcRet;
}
/**
* Callback function for mapping an PCI I/O region.
*
* @return VBox status code.
* @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
* @param iRegion The region number.
* @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
* I/O port, else it's a physical address.
* This address is *NOT* relative to pci_mem_base like earlier!
* @param enmType One of the PCI_ADDRESS_SPACE_* values.
*/
static DECLCALLBACK(int) vmmdevIORAMRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
{
LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%RGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
VMMDevState *pThis = PCIDEV_2_VMMDEVSTATE(pPciDev);
int rc;
if (iRegion == 1)
{
AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM, VERR_INTERNAL_ERROR);
Assert(pThis->pVMMDevRAMR3 != NULL);
if (GCPhysAddress != NIL_RTGCPHYS)
{
/*
* Map the MMIO2 memory.
*/
pThis->GCPhysVMMDevRAM = GCPhysAddress;
Assert(pThis->GCPhysVMMDevRAM == GCPhysAddress);
rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
}
else
{
/*
* It is about to be unmapped, just clean up.
*/
pThis->GCPhysVMMDevRAM = NIL_RTGCPHYS32;
rc = VINF_SUCCESS;
}
}
else if (iRegion == 2)
{
AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM_PREFETCH, VERR_INTERNAL_ERROR);
Assert(pThis->pVMMDevHeapR3 != NULL);
if (GCPhysAddress != NIL_RTGCPHYS)
{
/*
* Map the MMIO2 memory.
*/
pThis->GCPhysVMMDevHeap = GCPhysAddress;
Assert(pThis->GCPhysVMMDevHeap == GCPhysAddress);
rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
if (RT_SUCCESS(rc))
rc = PDMDevHlpRegisterVMMDevHeap(pPciDev->pDevIns, GCPhysAddress, pThis->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
}
else
{
/*
* It is about to be unmapped, just clean up.
*/
PDMDevHlpUnregisterVMMDevHeap(pPciDev->pDevIns, pThis->GCPhysVMMDevHeap);
pThis->GCPhysVMMDevHeap = NIL_RTGCPHYS32;
rc = VINF_SUCCESS;
}
}
else
{
AssertMsgFailed(("%d\n", iRegion));
rc = VERR_INVALID_PARAMETER;
}
return rc;
}
/**
* Callback function for mapping a PCI I/O region.
*
* @return VBox status code.
* @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
* @param iRegion The region number.
* @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
* I/O port, else it's a physical address.
* This address is *NOT* relative to pci_mem_base like earlier!
* @param enmType One of the PCI_ADDRESS_SPACE_* values.
*/
static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
{
VMMDevState *pThis = PCIDEV_2_VMMDEVSTATE(pPciDev);
int rc = VINF_SUCCESS;
Assert(enmType == PCI_ADDRESS_SPACE_IO);
Assert(iRegion == 0);
AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
/*
* Save the base port address to simplify Port offset calculations.
*/
pThis->PortBase = (RTIOPORT)GCPhysAddress;
/*
* Register our port IO handlers.
*/
rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns,
(RTIOPORT)GCPhysAddress + VMMDEV_PORT_OFF_REQUEST, 1,
(void*)pThis, vmmdevRequestHandler,
NULL, NULL, NULL, "VMMDev Request Handler");
AssertRC(rc);
return rc;
}
/**
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
*/
static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, const char *pszIID)
{
VMMDevState *pThis = RT_FROM_MEMBER(pInterface, VMMDevState, IBase);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVPORT, &pThis->IPort);
#ifdef VBOX_WITH_HGCM
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMPORT, &pThis->IHGCMPort);
#endif
/* Currently only for shared folders. */
PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThis->SharedFolders.ILeds);
return NULL;
}
/**
* Gets the pointer to the status LED of a unit.
*
* @returns VBox status code.
* @param pInterface Pointer to the interface structure containing the called function pointer.
* @param iLUN The unit which status LED we desire.
* @param ppLed Where to store the LED pointer.
*/
static DECLCALLBACK(int) vmmdevQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
{
VMMDevState *pThis = (VMMDevState *)( (uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, SharedFolders.ILeds) );
if (iLUN == 0) /* LUN 0 is shared folders */
{
*ppLed = &pThis->SharedFolders.Led;
return VINF_SUCCESS;
}
return VERR_PDM_LUN_NOT_FOUND;
}
/* -=-=-=-=-=- IVMMDevPort -=-=-=-=-=- */
/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
#define IVMMDEVPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, IPort)) )
/**
* Return the current absolute mouse position in pixels
*
* @returns VBox status code
* @param pAbsX Pointer of result value, can be NULL
* @param pAbsY Pointer of result value, can be NULL
*/
static DECLCALLBACK(int) vmmdevQueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t *pAbsX, uint32_t *pAbsY)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
AssertCompile(sizeof(pThis->mouseXAbs) == sizeof(*pAbsX));
AssertCompile(sizeof(pThis->mouseYAbs) == sizeof(*pAbsY));
if (pAbsX)
ASMAtomicReadSize(&pThis->mouseXAbs, pAbsX);
if (pAbsY)
ASMAtomicReadSize(&pThis->mouseYAbs, pAbsY);
return VINF_SUCCESS;
}
/**
* Set the new absolute mouse position in pixels
*
* @returns VBox status code
* @param absX New absolute X position
* @param absY New absolute Y position
*/
static DECLCALLBACK(int) vmmdevSetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t absX, uint32_t absY)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
if ((pThis->mouseXAbs == absX) && (pThis->mouseYAbs == absY))
{
PDMCritSectLeave(&pThis->CritSect);
return VINF_SUCCESS;
}
Log2(("vmmdevSetAbsoluteMouse: settings absolute position to x = %d, y = %d\n", absX, absY));
pThis->mouseXAbs = absX;
pThis->mouseYAbs = absY;
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
PDMCritSectLeave(&pThis->CritSect);
return VINF_SUCCESS;
}
/**
* Return the current mouse capability flags
*
* @returns VBox status code
* @param pCapabilities Pointer of result value
*/
static DECLCALLBACK(int) vmmdevQueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pCapabilities)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
if (!pCapabilities)
return VERR_INVALID_PARAMETER;
*pCapabilities = pThis->mouseCapabilities;
return VINF_SUCCESS;
}
/**
* Set the current mouse capability flag (host side)
*
* @returns VBox status code
* @param capabilities Capability mask
*/
static DECLCALLBACK(int) vmmdevSetMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t capabilities)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
bool bNotify = ( (capabilities & VMMDEV_MOUSE_NOTIFY_GUEST_MASK)
!= (pThis->mouseCapabilities & VMMDEV_MOUSE_NOTIFY_GUEST_MASK));
Log(("vmmdevSetMouseCapabilities: bNotify %d\n", bNotify));
pThis->mouseCapabilities &= ~VMMDEV_MOUSE_HOST_MASK;
pThis->mouseCapabilities |= (capabilities & VMMDEV_MOUSE_HOST_MASK);
if (bNotify)
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
PDMCritSectLeave(&pThis->CritSect);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) vmmdevRequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t xres, uint32_t yres, uint32_t bpp, uint32_t display)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
if (display >= RT_ELEMENTS(pThis->displayChangeData.aRequests))
{
return VERR_INVALID_PARAMETER;
}
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[display];
/* Verify that the new resolution is different and that guest does not yet know about it. */
bool fSameResolution = (!xres || (pRequest->lastReadDisplayChangeRequest.xres == xres)) &&
(!yres || (pRequest->lastReadDisplayChangeRequest.yres == yres)) &&
(!bpp || (pRequest->lastReadDisplayChangeRequest.bpp == bpp)) &&
pRequest->lastReadDisplayChangeRequest.display == display;
if (!xres && !yres && !bpp)
{
/* Special case of reset video mode. */
fSameResolution = false;
}
Log3(("vmmdevRequestDisplayChange: same=%d. new: xres=%d, yres=%d, bpp=%d, display=%d. old: xres=%d, yres=%d, bpp=%d, display=%d.\n",
fSameResolution, xres, yres, bpp, display, pRequest->lastReadDisplayChangeRequest.xres, pRequest->lastReadDisplayChangeRequest.yres, pRequest->lastReadDisplayChangeRequest.bpp, pRequest->lastReadDisplayChangeRequest.display));
if (!fSameResolution)
{
LogRel(("VMMDev::SetVideoModeHint: got a video mode hint (%dx%dx%d) at %d\n",
xres, yres, bpp, display));
/* we could validate the information here but hey, the guest can do that as well! */
pRequest->displayChangeRequest.xres = xres;
pRequest->displayChangeRequest.yres = yres;
pRequest->displayChangeRequest.bpp = bpp;
pRequest->displayChangeRequest.display = display;
pRequest->fPending = true;
/* IRQ so the guest knows what's going on */
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
}
PDMCritSectLeave(&pThis->CritSect);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) vmmdevRequestSeamlessChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
/* Verify that the new resolution is different and that guest does not yet know about it. */
bool fSameMode = (pThis->fLastSeamlessEnabled == fEnabled);
Log(("vmmdevRequestSeamlessChange: same=%d. new=%d\n", fSameMode, fEnabled));
if (!fSameMode)
{
/* we could validate the information here but hey, the guest can do that as well! */
pThis->fSeamlessEnabled = fEnabled;
/* IRQ so the guest knows what's going on */
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
}
PDMCritSectLeave(&pThis->CritSect);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) vmmdevSetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t ulBalloonSize)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
/* Verify that the new resolution is different and that guest does not yet know about it. */
bool fSame = (pThis->u32LastMemoryBalloonSize == ulBalloonSize);
Log(("vmmdevSetMemoryBalloon: old=%d. new=%d\n", pThis->u32LastMemoryBalloonSize, ulBalloonSize));
if (!fSame)
{
/* we could validate the information here but hey, the guest can do that as well! */
pThis->u32MemoryBalloonSize = ulBalloonSize;
/* IRQ so the guest knows what's going on */
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
}
PDMCritSectLeave(&pThis->CritSect);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) vmmdevVRDPChange(PPDMIVMMDEVPORT pInterface, bool fVRDPEnabled, uint32_t u32VRDPExperienceLevel)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
bool fSame = (pThis->fVRDPEnabled == fVRDPEnabled);
Log(("vmmdevVRDPChange: old=%d. new=%d\n", pThis->fVRDPEnabled, fVRDPEnabled));
if (!fSame)
{
pThis->fVRDPEnabled = fVRDPEnabled;
pThis->u32VRDPExperienceLevel = u32VRDPExperienceLevel;
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_VRDP);
}
PDMCritSectLeave(&pThis->CritSect);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) vmmdevSetStatisticsInterval(PPDMIVMMDEVPORT pInterface, uint32_t ulStatInterval)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
/* Verify that the new resolution is different and that guest does not yet know about it. */
bool fSame = (pThis->u32LastStatIntervalSize == ulStatInterval);
Log(("vmmdevSetStatisticsInterval: old=%d. new=%d\n", pThis->u32LastStatIntervalSize, ulStatInterval));
if (!fSame)
{
/* we could validate the information here but hey, the guest can do that as well! */
pThis->u32StatIntervalSize = ulStatInterval;
/* IRQ so the guest knows what's going on */
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
}
PDMCritSectLeave(&pThis->CritSect);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) vmmdevSetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
const char *pszPassword, const char *pszDomain,
uint32_t u32Flags)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
int rc = VINF_SUCCESS;
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
/* logon mode? */
if (u32Flags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
{
/* memorize the data */
strcpy(pThis->credentialsLogon.szUserName, pszUsername);
strcpy(pThis->credentialsLogon.szPassword, pszPassword);
strcpy(pThis->credentialsLogon.szDomain, pszDomain);
pThis->credentialsLogon.fAllowInteractiveLogon = !(u32Flags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
}
/* credentials verification mode? */
else if (u32Flags & VMMDEV_SETCREDENTIALS_JUDGE)
{
/* memorize the data */
strcpy(pThis->credentialsJudge.szUserName, pszUsername);
strcpy(pThis->credentialsJudge.szPassword, pszPassword);
strcpy(pThis->credentialsJudge.szDomain, pszDomain);
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_JUDGE_CREDENTIALS);
}
else
rc = VERR_INVALID_PARAMETER;
PDMCritSectLeave(&pThis->CritSect);
return rc;
}
/**
* Notification from the Display. Especially useful when
* acceleration is disabled after a video mode change.
*
* @param fEnable Current acceleration status.
*/
static DECLCALLBACK(void) vmmdevVBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
{
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
Log(("vmmdevVBVAChange: fEnabled = %d\n", fEnabled));
if (pThis)
{
pThis->u32VideoAccelEnabled = fEnabled;
}
return;
}
/**
* Notification that a CPU is about to be unplugged from the VM.
* The guest has to eject the CPU.
*
* @returns VBox status code.
* @param idCpu The id of the CPU.
* @param idCpuCore The core id of the CPU to remove.
* @param idCpuPackage The package id of the CPU to remove.
*/
static DECLCALLBACK(int) vmmdevCpuHotUnplug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
{
int rc = VINF_SUCCESS;
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
Log(("vmmdevCpuHotUnplug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
if (pThis->fCpuHotPlugEventsEnabled)
{
pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Unplug;
pThis->idCpuCore = idCpuCore;
pThis->idCpuPackage = idCpuPackage;
VMMDevNotifyGuest (pThis, VMMDEV_EVENT_CPU_HOTPLUG);
}
else
rc = VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
PDMCritSectLeave(&pThis->CritSect);
return rc;
}
/**
* Notification that a CPU was attached to the VM
* The guest may use it now.
*
* @returns VBox status code.
* @param idCpuCore The core id of the CPU to add.
* @param idCpuPackage The package id of the CPU to add.
*/
static DECLCALLBACK(int) vmmdevCpuHotPlug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
{
int rc = VINF_SUCCESS;
VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
Log(("vmmdevCpuPlug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
if (pThis->fCpuHotPlugEventsEnabled)
{
pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Plug;
pThis->idCpuCore = idCpuCore;
pThis->idCpuPackage = idCpuPackage;
VMMDevNotifyGuest(pThis, VMMDEV_EVENT_CPU_HOTPLUG);
}
else
rc = VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
PDMCritSectLeave(&pThis->CritSect);
return rc;
}
/* -=-=-=-=-=- Saved State -=-=-=-=-=- */
/**
* @copydoc FNSSMDEVLIVEEXEC
*/
static DECLCALLBACK(int) vmmdevLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
{
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
SSMR3PutBool(pSSM, pThis->fGetHostTimeDisabled);
SSMR3PutBool(pSSM, pThis->fBackdoorLogDisabled);
SSMR3PutBool(pSSM, pThis->fKeepCredentials);
SSMR3PutBool(pSSM, pThis->fHeapEnabled);
return VINF_SSM_DONT_CALL_AGAIN;
}
/**
* @copydoc FNSSMDEVSAVEEXEC
*
*/
static DECLCALLBACK(int) vmmdevSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
{
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
vmmdevLiveExec(pDevIns, pSSM, SSM_PASS_FINAL);
SSMR3PutU32(pSSM, pThis->hypervisorSize);
SSMR3PutU32(pSSM, pThis->mouseCapabilities);
SSMR3PutU32(pSSM, pThis->mouseXAbs);
SSMR3PutU32(pSSM, pThis->mouseYAbs);
SSMR3PutBool(pSSM, pThis->fNewGuestFilterMask);
SSMR3PutU32(pSSM, pThis->u32NewGuestFilterMask);
SSMR3PutU32(pSSM, pThis->u32GuestFilterMask);
SSMR3PutU32(pSSM, pThis->u32HostEventFlags);
/* The following is not strictly necessary as PGM restors MMIO2, keeping it for historical reasons. */
SSMR3PutMem(pSSM, &pThis->pVMMDevRAMR3->V, sizeof(pThis->pVMMDevRAMR3->V));
SSMR3PutMem(pSSM, &pThis->guestInfo, sizeof (pThis->guestInfo));
SSMR3PutU32(pSSM, pThis->fu32AdditionsOk);
SSMR3PutU32(pSSM, pThis->u32VideoAccelEnabled);
SSMR3PutBool(pSSM, pThis->displayChangeData.fGuestSentChangeEventAck);
SSMR3PutU32(pSSM, pThis->guestCaps);
#ifdef VBOX_WITH_HGCM
vmmdevHGCMSaveState(pThis, pSSM);
#endif /* VBOX_WITH_HGCM */
SSMR3PutU32(pSSM, pThis->fHostCursorRequested);
return VINF_SUCCESS;
}
/**
* @copydoc FNSSMDEVLOADEXEC
*/
static DECLCALLBACK(int) vmmdevLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
{
/** @todo The code load code is assuming we're always loaded into a freshly
* constructed VM. */
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
int rc;
if ( uVersion > VMMDEV_SAVED_STATE_VERSION
|| uVersion < 6)
return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
/* config */
if (uVersion > VMMDEV_SAVED_STATE_VERSION_VBOX_30)
{
bool f;
rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
if (pThis->fGetHostTimeDisabled != f)
LogRel(("VMMDev: Config mismatch - fGetHostTimeDisabled: config=%RTbool saved=%RTbool\n", pThis->fGetHostTimeDisabled, f));
rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
if (pThis->fBackdoorLogDisabled != f)
LogRel(("VMMDev: Config mismatch - fBackdoorLogDisabled: config=%RTbool saved=%RTbool\n", pThis->fBackdoorLogDisabled, f));
rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
if (pThis->fKeepCredentials != f)
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fKeepCredentials: config=%RTbool saved=%RTbool"),
pThis->fKeepCredentials, f);
rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
if (pThis->fHeapEnabled != f)
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fHeapEnabled: config=%RTbool saved=%RTbool"),
pThis->fHeapEnabled, f);
}
if (uPass != SSM_PASS_FINAL)
return VINF_SUCCESS;
/* state */
SSMR3GetU32(pSSM, &pThis->hypervisorSize);
SSMR3GetU32(pSSM, &pThis->mouseCapabilities);
SSMR3GetU32(pSSM, &pThis->mouseXAbs);
SSMR3GetU32(pSSM, &pThis->mouseYAbs);
SSMR3GetBool(pSSM, &pThis->fNewGuestFilterMask);
SSMR3GetU32(pSSM, &pThis->u32NewGuestFilterMask);
SSMR3GetU32(pSSM, &pThis->u32GuestFilterMask);
SSMR3GetU32(pSSM, &pThis->u32HostEventFlags);
// SSMR3GetBool(pSSM, &pThis->pVMMDevRAMR3->fHaveEvents);
// here be dragons (probably)
SSMR3GetMem(pSSM, &pThis->pVMMDevRAMR3->V, sizeof (pThis->pVMMDevRAMR3->V));
SSMR3GetMem(pSSM, &pThis->guestInfo, sizeof (pThis->guestInfo));
SSMR3GetU32(pSSM, &pThis->fu32AdditionsOk);
SSMR3GetU32(pSSM, &pThis->u32VideoAccelEnabled);
if (uVersion > 10)
SSMR3GetBool(pSSM, &pThis->displayChangeData.fGuestSentChangeEventAck);
rc = SSMR3GetU32(pSSM, &pThis->guestCaps);
/* Attributes which were temporarily introduced in r30072 */
if (uVersion == 7)
{
uint32_t temp;
SSMR3GetU32(pSSM, &temp);
rc = SSMR3GetU32(pSSM, &temp);
}
AssertRCReturn(rc, rc);
#ifdef VBOX_WITH_HGCM
rc = vmmdevHGCMLoadState(pThis, pSSM, uVersion);
AssertRCReturn(rc, rc);
#endif /* VBOX_WITH_HGCM */
if (uVersion >= 10)
rc = SSMR3GetU32(pSSM, &pThis->fHostCursorRequested);
AssertRCReturn(rc, rc);
/*
* On a resume, we send the capabilities changed message so
* that listeners can sync their state again
*/
Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pThis->mouseCapabilities));
if (pThis->pDrv)
{
pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
if (uVersion >= 10)
pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
/*fVisible=*/!!pThis->fHostCursorRequested,
/*fAlpha=*/false,
/*xHot=*/0, /*yHot=*/0,
/*cx=*/0, /*cy=*/0,
/*pvShape=*/NULL);
}
/* Reestablish the acceleration status. */
if ( pThis->u32VideoAccelEnabled
&& pThis->pDrv)
{
pThis->pDrv->pfnVideoAccelEnable (pThis->pDrv, !!pThis->u32VideoAccelEnabled, &pThis->pVMMDevRAMR3->vbvaMemory);
}
if (pThis->fu32AdditionsOk)
{
LogRel(("Guest Additions information report: additionsVersion = 0x%08X, osType = 0x%08X\n",
pThis->guestInfo.additionsVersion,
pThis->guestInfo.osType));
if (pThis->pDrv)
pThis->pDrv->pfnUpdateGuestVersion(pThis->pDrv, &pThis->guestInfo);
}
if (pThis->pDrv)
pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
return VINF_SUCCESS;
}
/**
* Load state done callback. Notify guest of restore event.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSM The handle to the saved state.
*/
static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
{
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
#ifdef VBOX_WITH_HGCM
int rc = vmmdevHGCMLoadStateDone(pThis, pSSM);
AssertLogRelRCReturn(rc, rc);
#endif /* VBOX_WITH_HGCM */
VMMDevNotifyGuest(pThis, VMMDEV_EVENT_RESTORED);
return VINF_SUCCESS;
}
/* -=-=-=-=- PDMDEVREG -=-=-=-=- */
/**
* (Re-)initializes the MMIO2 data.
*
* @param pThis Pointer to the VMMDev instance data.
*/
static void vmmdevInitRam(VMMDevState *pThis)
{
memset(pThis->pVMMDevRAMR3, 0, sizeof(VMMDevMemory));
pThis->pVMMDevRAMR3->u32Size = sizeof(VMMDevMemory);
pThis->pVMMDevRAMR3->u32Version = VMMDEV_MEMORY_VERSION;
}
/**
* Reset notification.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
*/
static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
{
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
/*
* Reset the mouse integration feature bits
*/
if (pThis->mouseCapabilities & VMMDEV_MOUSE_GUEST_MASK)
{
pThis->mouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
/* notify the connector */
Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pThis->mouseCapabilities));
pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
}
pThis->fHostCursorRequested = false;
pThis->hypervisorSize = 0;
pThis->u32HostEventFlags = 0;
/* re-initialize the VMMDev memory */
if (pThis->pVMMDevRAMR3)
vmmdevInitRam(pThis);
/* credentials have to go away (by default) */
if (!pThis->fKeepCredentials)
{
memset(pThis->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(pThis->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(pThis->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
}
memset(pThis->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(pThis->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
memset(pThis->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
/* Reset means that additions will report again. */
const bool fVersionChanged = pThis->fu32AdditionsOk
|| pThis->guestInfo.additionsVersion
|| pThis->guestInfo.osType != VBOXOSTYPE_Unknown;
if (fVersionChanged)
Log(("vmmdevReset: fu32AdditionsOk=%d additionsVersion=%x osType=%#x\n",
pThis->fu32AdditionsOk, pThis->guestInfo.additionsVersion, pThis->guestInfo.osType));
pThis->fu32AdditionsOk = false;
memset (&pThis->guestInfo, 0, sizeof (pThis->guestInfo));
/* clear pending display change request. */
for (unsigned i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
{
DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
memset (&pRequest->lastReadDisplayChangeRequest, 0, sizeof (pRequest->lastReadDisplayChangeRequest));
}
pThis->displayChangeData.iCurrentMonitor = 0;
pThis->displayChangeData.fGuestSentChangeEventAck = false;
/* disable seamless mode */
pThis->fLastSeamlessEnabled = false;
/* disabled memory ballooning */
pThis->u32LastMemoryBalloonSize = 0;
/* disabled statistics updating */
pThis->u32LastStatIntervalSize = 0;
/* Clear the "HGCM event enabled" flag so the event can be automatically reenabled. */
pThis->u32HGCMEnabled = 0;
/*
* Clear the event variables.
*
* Note: The pThis->u32HostEventFlags is not cleared.
* It is designed that way so host events do not
* depend on guest resets.
*/
pThis->u32GuestFilterMask = 0;
pThis->u32NewGuestFilterMask = 0;
pThis->fNewGuestFilterMask = 0;
/* This is the default, as Windows and OS/2 guests take this for granted. (Actually, neither does...) */
/** @todo change this when we next bump the interface version */
const bool fCapsChanged = pThis->guestCaps != VMMDEV_GUEST_SUPPORTS_GRAPHICS;
if (fCapsChanged)
Log(("vmmdevReset: fCapsChanged=%#x -> %#x\n", pThis->guestCaps, VMMDEV_GUEST_SUPPORTS_GRAPHICS));
pThis->guestCaps = VMMDEV_GUEST_SUPPORTS_GRAPHICS; /** @todo r=bird: why? I cannot see this being done at construction?*/
/*
* Call the update functions as required.
*/
if (fVersionChanged)
pThis->pDrv->pfnUpdateGuestVersion(pThis->pDrv, &pThis->guestInfo);
if (fCapsChanged)
pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
}
/**
* @interface_method_impl{PDMDEVREG,pfnConstruct}
*/
static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
{
int rc;
VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
Assert(iInstance == 0);
PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
/*
* Validate and read the configuration.
*/
if (!CFGMR3AreValuesValid(pCfg,
"GetHostTimeDisabled\0"
"BackdoorLogDisabled\0"
"KeepCredentials\0"
"HeapEnabled\0"
))
return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
rc = CFGMR3QueryBoolDef(pCfg, "GetHostTimeDisabled", &pThis->fGetHostTimeDisabled, false);
if (RT_FAILURE(rc))
return PDMDEV_SET_ERROR(pDevIns, rc,
N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
rc = CFGMR3QueryBoolDef(pCfg, "BackdoorLogDisabled", &pThis->fBackdoorLogDisabled, false);
if (RT_FAILURE(rc))
return PDMDEV_SET_ERROR(pDevIns, rc,
N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
rc = CFGMR3QueryBoolDef(pCfg, "KeepCredentials", &pThis->fKeepCredentials, false);
if (RT_FAILURE(rc))
return PDMDEV_SET_ERROR(pDevIns, rc,
N_("Configuration error: Failed querying \"KeepCredentials\" as a boolean"));
rc = CFGMR3QueryBoolDef(pCfg, "HeapEnabled", &pThis->fHeapEnabled, true);
if (RT_FAILURE(rc))
return PDMDEV_SET_ERROR(pDevIns, rc,
N_("Configuration error: Failed querying \"HeapEnabled\" as a boolean"));
/*
* Initialize data (most of it anyway).
*/
/* Save PDM device instance data for future reference. */
pThis->pDevIns = pDevIns;
/* PCI vendor, just a free bogus value */
pThis->dev.config[0x00] = 0xee;
pThis->dev.config[0x01] = 0x80;
/* device ID */
pThis->dev.config[0x02] = 0xfe;
pThis->dev.config[0x03] = 0xca;
/* class sub code (other type of system peripheral) */
pThis->dev.config[0x0a] = 0x80;
/* class base code (base system peripheral) */
pThis->dev.config[0x0b] = 0x08;
/* header type */
pThis->dev.config[0x0e] = 0x00;
/* interrupt on pin 0 */
pThis->dev.config[0x3d] = 0x01;
/*
* Interfaces
*/
/* IBase */
pThis->IBase.pfnQueryInterface = vmmdevPortQueryInterface;
/* VMMDev port */
pThis->IPort.pfnQueryAbsoluteMouse = vmmdevQueryAbsoluteMouse;
pThis->IPort.pfnSetAbsoluteMouse = vmmdevSetAbsoluteMouse;
pThis->IPort.pfnQueryMouseCapabilities = vmmdevQueryMouseCapabilities;
pThis->IPort.pfnSetMouseCapabilities = vmmdevSetMouseCapabilities;
pThis->IPort.pfnRequestDisplayChange = vmmdevRequestDisplayChange;
pThis->IPort.pfnSetCredentials = vmmdevSetCredentials;
pThis->IPort.pfnVBVAChange = vmmdevVBVAChange;
pThis->IPort.pfnRequestSeamlessChange = vmmdevRequestSeamlessChange;
pThis->IPort.pfnSetMemoryBalloon = vmmdevSetMemoryBalloon;
pThis->IPort.pfnSetStatisticsInterval = vmmdevSetStatisticsInterval;
pThis->IPort.pfnVRDPChange = vmmdevVRDPChange;
pThis->IPort.pfnCpuHotUnplug = vmmdevCpuHotUnplug;
pThis->IPort.pfnCpuHotPlug = vmmdevCpuHotPlug;
/* Shared folder LED */
pThis->SharedFolders.Led.u32Magic = PDMLED_MAGIC;
pThis->SharedFolders.ILeds.pfnQueryStatusLed = vmmdevQueryStatusLed;
#ifdef VBOX_WITH_HGCM
/* HGCM port */
pThis->IHGCMPort.pfnCompleted = hgcmCompleted;
#endif
/** @todo convert this into a config parameter like we do everywhere else! */
pThis->cbGuestRAM = MMR3PhysGetRamSize(PDMDevHlpGetVM(pDevIns));
/*
* Create the critical section for the device.
*/
rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "VMMDev");
AssertRCReturn(rc, rc);
/* Later: pDevIns->pCritSectR3 = &pThis->CritSect; */
/*
* Register the backdoor logging port
*/
rc = PDMDevHlpIOPortRegister(pDevIns, RTLOG_DEBUG_PORT, 1, NULL, vmmdevBackdoorLog, NULL, NULL, NULL, "VMMDev backdoor logging");
AssertRCReturn(rc, rc);
#ifdef TIMESYNC_BACKDOOR
/*
* Alternative timesync source (temporary!)
*/
rc = PDMDevHlpIOPortRegister(pDevIns, 0x505, 1, NULL, vmmdevTimesyncBackdoorWrite, vmmdevTimesyncBackdoorRead, NULL, NULL, "VMMDev timesync backdoor");
AssertRCReturn(rc, rc);
#endif
/*
* Allocate and initialize the MMIO2 memory.
*/
rc = PDMDevHlpMMIO2Register(pDevIns, 1 /*iRegion*/, VMMDEV_RAM_SIZE, 0 /*fFlags*/, (void **)&pThis->pVMMDevRAMR3, "VMMDev");
if (RT_FAILURE(rc))
return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
N_("Failed to allocate %u bytes of memory for the VMM device"), VMMDEV_RAM_SIZE);
vmmdevInitRam(pThis);
if (pThis->fHeapEnabled)
{
rc = PDMDevHlpMMIO2Register(pDevIns, 2 /*iRegion*/, VMMDEV_HEAP_SIZE, 0 /*fFlags*/, (void **)&pThis->pVMMDevHeapR3, "VMMDev Heap");
if (RT_FAILURE(rc))
return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
N_("Failed to allocate %u bytes of memory for the VMM device heap"), PAGE_SIZE);
}
/*
* Register the PCI device.
*/
rc = PDMDevHlpPCIRegister(pDevIns, &pThis->dev);
if (RT_FAILURE(rc))
return rc;
if (pThis->dev.devfn == 32 || iInstance != 0)
Log(("!!WARNING!!: pThis->dev.devfn=%d (ignore if testcase or no started by Main)\n", pThis->dev.devfn));
rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 0x20, PCI_ADDRESS_SPACE_IO, vmmdevIOPortRegionMap);
if (RT_FAILURE(rc))
return rc;
rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, vmmdevIORAMRegionMap);
if (RT_FAILURE(rc))
return rc;
if (pThis->fHeapEnabled)
{
rc = PDMDevHlpPCIIORegionRegister(pDevIns, 2, VMMDEV_HEAP_SIZE, PCI_ADDRESS_SPACE_MEM_PREFETCH, vmmdevIORAMRegionMap);
if (RT_FAILURE(rc))
return rc;
}
/*
* Get the corresponding connector interface
*/
rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "VMM Driver Port");
if (RT_SUCCESS(rc))
{
pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIVMMDEVCONNECTOR);
AssertMsgReturn(pThis->pDrv, ("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
#ifdef VBOX_WITH_HGCM
pThis->pHGCMDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIHGCMCONNECTOR);
if (!pThis->pHGCMDrv)
{
Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Rrc\n", rc));
/* this is not actually an error, just means that there is no support for HGCM */
}
#endif
/* Query the initial balloon size. */
rc = pThis->pDrv->pfnQueryBalloonSize(pThis->pDrv, &pThis->u32MemoryBalloonSize);
AssertRC(rc);
Log(("Initial balloon size %x\n", pThis->u32MemoryBalloonSize));
}
else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
{
Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pReg->szName, pDevIns->iInstance));
rc = VINF_SUCCESS;
}
else
AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Rrc\n", rc), rc);
/*
* Attach status driver for shared folders (optional).
*/
PPDMIBASE pBase;
rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pBase, "Status Port");
if (RT_SUCCESS(rc))
pThis->SharedFolders.pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
{
AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
return rc;
}
/*
* Register saved state and init the HGCM CmdList critsect.
*/
rc = PDMDevHlpSSMRegisterEx(pDevIns, VMMDEV_SAVED_STATE_VERSION, sizeof(*pThis), NULL,
NULL, vmmdevLiveExec, NULL,
NULL, vmmdevSaveExec, NULL,
NULL, vmmdevLoadExec, vmmdevLoadStateDone);
AssertRCReturn(rc, rc);
#ifdef VBOX_WITH_HGCM
pThis->pHGCMCmdList = NULL;
rc = RTCritSectInit(&pThis->critsectHGCMCmdList);
AssertRCReturn(rc, rc);
pThis->u32HGCMEnabled = 0;
#endif /* VBOX_WITH_HGCM */
/* The GUI checks whether this changes in this version of VirtualBox. */
pThis->mouseCapabilities |= VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMemBalloonChunks, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Memory balloon size", "/Devices/VMMDev/BalloonChunks");
return rc;
}
/**
* The device registration structure.
*/
extern "C" const PDMDEVREG g_DeviceVMMDev =
{
/* u32Version */
PDM_DEVREG_VERSION,
/* szName */
"VMMDev",
/* szRCMod */
"",
/* szR0Mod */
"",
/* pszDescription */
"VirtualBox VMM Device\n",
/* fFlags */
PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT,
/* fClass */
PDM_DEVREG_CLASS_VMM_DEV,
/* cMaxInstances */
1,
/* cbInstance */
sizeof(VMMDevState),
/* pfnConstruct */
vmmdevConstruct,
/* pfnDestruct */
NULL,
/* pfnRelocate */
NULL,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
vmmdevReset,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnQueryInterface. */
NULL,
/* pfnInitComplete */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32VersionEnd */
PDM_DEVREG_VERSION
};
#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
|