summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/include/nvos.h
blob: 9f05fcd905d13c914551d8dec5937819e67525e2 (plain)
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
/*
 * Copyright (c) 2006-2009 NVIDIA Corporation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the NVIDIA Corporation nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

/**
 * @file
 * <b> NVIDIA Operating System Abstraction</b>
 *
 * @b Description: Provides interfaces that enable unification of code
 * across all supported operating systems.
 */


#ifndef INCLUDED_NVOS_H
#define INCLUDED_NVOS_H

/**
 * @defgroup nvos_group NvOS - NVIDIA Operating System Abstraction
 *
 * This provides a basic set of interfaces to unify code
 * across all supported operating systems. This layer does @b not
 * handle any hardware specific functions, such as interrupts.
 * "Platform" setup and GPU access are done by other layers.
 *
 * @warning Drivers and applications should @b not make any operating system
 * calls outside of this layer, @b including stdlib functions. Doing so will
 * result in non-portable code.
 *
 * For APIs that take key parameters, keys may be of ::NVOS_KEY_MAX length.
 * Any characters beyond this maximum is ignored.
 *
 * All strings passed to or from NvOS functions are encoded in UTF-8. For
 * character values below 128, this is the same as simple ASCII. For more
 * information, see:
 * <a href="http://en.wikipedia.org/wiki/UTF-8"
 *    target="_blank">http://en.wikipedia.org/wiki/UTF-8</a>
 *
 *
 * @par Important:
 *
 *  At interrupt time there are only a handful of NvOS functions that are safe
 *  to call:
 *  - ::NvOsSemaphoreSignal
 *  - ::NvOsIntrMutexLock
 *  - ::NvOsIntrMutexUnlock
 *  - ::NvOsWaitUS
 *
 * @note Curerntly, ::NvOsWaitUS for ISR has @b only been implemented for AOS and
 * WinCE. Use with caution.
 *
 * @{
 */

#include <stdarg.h>
#include "nvcommon.h"
#include "nverror.h"
#include "nvos_trace.h"

#if defined(__cplusplus)
extern "C"
{
#endif

/**
 * A physical address. Must be 64 bits for OSs that support more than 64 bits
 * of physical addressing, not necessarily correlated to the size of a virtual
 * address.
 *
 * Currently, 64-bit physical addressing is supported by NvOS on WinNT only.
 *
 * XXX 64-bit phys addressing really should be supported on Linux/x86, since
 * all modern x86 CPUs have 36-bit (or more) physical addressing. We might
 * need to control a PCI card that the SBIOS has placed at an address above
 * 4 GB.
 */
#if NVOS_IS_WINDOWS && !NVOS_IS_WINDOWS_CE
typedef NvU64 NvOsPhysAddr;
#else
typedef NvU32 NvOsPhysAddr;
#endif

/** The maximum length of a shared resource identifier string.
 */
#define NVOS_KEY_MAX 128

/** The maximum length for a file system path.
 */
#define NVOS_PATH_MAX 256

/** @name Print Operations
 */
/*@{*/

/** Printf family. */
typedef struct NvOsFileRec *NvOsFileHandle;

/** Prints a string to a file stream.
 *
 *  @param stream The file stream to which to print.
 *  @param format The format string.
 */
NvError
NvOsFprintf(NvOsFileHandle stream, const char *format, ...);

// Doxygen requires escaping backslash characters (\) with another \ so in
// @return, ignore the first backslash if you are reading this in the header.
/** Expands a string into a given string buffer.
 *
 *  @param str A pointer to the target string buffer.
 *  @param size The size of the string buffer.
 *  @param format A pointer to the format string.
 *
 *  @return The number of characters printed (not including the \\0).
 *  The buffer was printed to successfully if the returned value is
 *  greater than -1 and less than \a size.
 */
NvS32
NvOsSnprintf(char *str, size_t size, const char *format, ...);

/** Prints a string to a file stream using a va_list.
 *
 *  @param stream The file stream.
 *  @param format A pointer to the format string.
 *  @param ap The va_list structure.
 */
NvError
NvOsVfprintf(NvOsFileHandle stream, const char *format, va_list ap);

/** Expands a string into a string buffer using a va_list.
 *
 *  @param str A pointer to the target string buffer.
 *  @param size The size of the string buffer.
 *  @param format A pointer to the format string.
 *  @param ap The va_list structure.
 *
 *  @return The number of characters printed (not including the \\0).
 *  The buffer was printed to successfully if the returned value is
 *  greater than -1 and less than \a size.
 */
NvS32
NvOsVsnprintf(char *str, size_t size, const char *format, va_list ap);

/**
 * Outputs a message to the debugging console, if present. All device driver
 * debug printfs should use this. Do not use this for interacting with a user
 * from an application; in that case, use NvTestPrintf() instead.
 *
 * @param format A pointer to the format string.
 */
void
NvOsDebugPrintf(const char *format, ...);

/**
 * Same as ::NvOsDebugPrintf, except takes a va_list.
 */
void
NvOsDebugVprintf( const char *format, va_list ap );

/**
 * Same as ::NvOsDebugPrintf, except returns the number of chars written.
 *
 * @return number of chars written or -1 if that number is unavailable
 */
NvS32
NvOsDebugNprintf( const char *format, ...);

/**
 * Prints an error and the line it appeared on.
 * Does nothing if err==NvSuccess
 *
 * @param err - the error to return
 * @param file - file the error occurred in.
 * @param line - line number the error occurred on.
 * @returns err
 */
NvError
NvOsShowError(NvError err, const char *file, int line);

// Doxygen requires escaping # with a backslash, so in the examples below
// ignore the backslash before the # if reading this in the header file.
/**
 * Helper macro to go along with ::NvOsDebugPrintf. Usage:
 * <pre>
 *     NV_DEBUG_PRINTF(("foo: %s\n", bar));    
   </pre>
 *
 * The debug print will be disabled by default in all builds, debug and
 * release. @note Usage requires double parentheses.
 *
 * To enable debug prints in a particular .c file, add the following
 * to the top of the .c file and rebuild:
 * <pre>
 *     \#define NV_ENABLE_DEBUG_PRINTS 1
   </pre>
 *
 * To enable debug prints in a particular module, add the following 
 * to the makefile and rebuild:
 * <pre>
 *     LCDEFS += -DNV_ENABLE_DEBUG_PRINTS=1
   </pre>
 * 
 */
#if !defined(NV_ENABLE_DEBUG_PRINTS)
#define NV_ENABLE_DEBUG_PRINTS 0
#endif
#if NV_ENABLE_DEBUG_PRINTS
// put the print in an if statement so that the compiler will always parse it
#define NV_DEBUG_PRINTF(x) \
    do { if (NV_ENABLE_DEBUG_PRINTS) { NvOsDebugPrintf x ; } } while (0)
#else
#define NV_DEBUG_PRINTF(x) do {} while (0)
#endif

/*@}*/
/** @name OS Version
 */
/*@{*/

typedef enum
{
    NvOsOs_Unknown,
    NvOsOs_Windows,
    NvOsOs_Linux,
    NvOsOs_Aos,
    NvOsOs_Force32 = 0x7fffffffUL,
} NvOsOs;

typedef enum
{
    NvOsSku_Unknown,
    NvOsSku_CeBase,
    NvOsSku_Mobile_SmartFon,
    NvOsSku_Mobile_PocketPC,
    NvOsSku_Android,
    NvOsSku_Force32 = 0x7fffffffUL,
} NvOsSku;

typedef struct NvOsOsInfoRec
{
    NvOsOs  OsType;
    NvOsSku Sku;
    NvU16   MajorVersion;
    NvU16   MinorVersion;
    NvU32   SubVersion;
    NvU32   Caps;
} NvOsOsInfo;

/**
 * Gets the current OS version.
 *
 * @param pOsInfo A pointer to the operating system information structure.
 */
NvError
NvOsGetOsInformation(NvOsOsInfo *pOsInfo);

/*@}*/

/** @name Resources 
 */
/*@{*/

/** An opaque resource handle.
 */
typedef struct NvOsResourceRec *NvOsResourceHandle;

typedef enum
{
    NvOsResource_Unknown,
    NvOsResource_Storage,
    NvOsResource_Force32 = 0x7fffffffUL,
} NvOsResource;

#define NVOS_DEV_NAME_MAX    16

typedef struct NvOsResourceStorageRec
{
    /// The storage device name.
    NvU8    DeviceName[2*NVOS_DEV_NAME_MAX];
    /// The mount point for this storage device.
    NvU8    MountPoint[NVOS_PATH_MAX];
    /// The free bytes available within the current context.
    NvU64   FreeBytesAvailable;
    /// The total bytes available within the current context (used + free).
    NvU64   TotalBytes;
    /// The total free bytes available on disk.
    NvU64   TotalFreeBytes;
} NvOsResourceStorage;

/**
 * Obtain a list of resources of the specified type. 
 *  
 * This function is used to aquire a NvOsResourceHandle (may be 
 * more than one) for a designated resource type.  The returned 
 * handle list is used to retrieve specific details about the 
 * resource by calling NvOsResouceInfo. 
 *  
 * This function may also be used to obtain just the number of 
 * resources (nResources) if ResourceList is specified as NULL 
 * by the caller. 
 *  
 * If ResourceList is not NULL, this function returns the number 
 * of resources (nResources) and a pointer to the first resource 
 * in the array (ResourceList).
 *  
 * @see NvOsResouceInfo()
 *  
 * @param ResourceType The resource type for which to retrieve a handle.
 * @param nResources The number of resources in the list.
 * @param ResourceList Points to the first resource handle in the list.
 *      If this parameter is NULL, only nResources is returned.
 */
NvError
NvOsListResources(
    NvOsResource ResourceType,
    NvU32 *nResources,
    NvOsResourceHandle *ResourceList);

/**
 * Gets the resource-specific data for a given
 * NvOsResourceHandle.  For example, this might include a data
 * structure which indicates the amount of free space on a
 * particular storage media.
 * 
 * @see NvOsListResources()
 * @see NvOsResourceStorage
 *
 * @param hResource The handle for the resource.
 * @param InfoSize The size of the resource structure (Info).
 * @param Info Points to a specific resource information structure. 
 *  
 * @retval "NvSuccess" if resource information is valid.
 * @retval "NvError_FileOperationFailed" if resource info not found.
 */
NvError
NvOsResourceInfo(
    NvOsResourceHandle hResource,
    NvU32 InfoSize,
    void *Info);

/*@}*/

/** @name String Operations
 */
/*@{*/

/** Copies a string.
 *
 *  @param dest A pointer to the destination of the copy.
 *  @param src A pointer to the source string.
 *  @param size The length of the \a dest string buffer plus NULL terminator.
 */
void
NvOsStrncpy(char *dest, const char *src, size_t size);

/** Defines straight-forward mappings to international language encodings.
 *  Commonly-used encodings on supported operating systems are provided.
 *  @note NvOS string (and file/directory name) processing functions expect
 *  UTF-8 encodings. If the system-default encoding is not UTF-8,
 *  conversion may be required. @see NvUStrConvertCodePage.
 *
 **/
typedef enum
{
    NvOsCodePage_Unknown,
    NvOsCodePage_Utf8,
    NvOsCodePage_Utf16,
    NvOsCodePage_Windows1252,
    NvOsCodePage_Force32 = 0x7fffffffUL,
} NvOsCodePage;

/** @return The default code page for the system.
 *
 */
NvOsCodePage
NvOsStrGetSystemCodePage(void);

/** Gets the length of a string.
 *
 *  @param s A pointer to the string.
 */
size_t
NvOsStrlen(const char *s);

/** Compares two strings.
 *
 *  @param s1 A pointer to the first string.
 *  @param s2 A pointer to the second string.
 *
 *  @return 0 if the strings are identical.
 */
int
NvOsStrcmp(const char *s1, const char *s2);

/** Compares two strings up to the given length.
 *
 *  @param s1 A pointer to the first string.
 *  @param s2 A pointer to the second string.
 *  @param size The length to compare.
 *
 *  @return 0 if the strings are identical.
 */
int
NvOsStrncmp(const char *s1, const char *s2, size_t size);

/*@}*/
/** @name Memory Operations (Basic)
 */
/*@{*/

/** Copies memory.
 *
 *  @param dest A pointer to the destination of the copy.
 *  @param src A pointer to the source memory.
 *  @param size The length of the copy.
 */
void NvOsMemcpy(void *dest, const void *src, size_t size);

/** Compares two memory regions.
 *
 *  @param s1 A pointer to the first memory region.
 *  @param s2 A pointer to the second memory region.
 *  @param size The length to compare.
 *
 *  This returns 0 if the memory regions are identical
 */
int
NvOsMemcmp(const void *s1, const void *s2, size_t size);

/** Sets a region of memory to a value.
 *
 *  @param s A pointer to the memory region.
 *  @param c The value to set.
 *  @param size The length of the region.
 */
void
NvOsMemset(void *s, NvU8 c, size_t size);

/** Moves memory to a new location (may overlap).
 *
 *  @param dest A pointer to the destination memory region.
 *  @param src A pointer to the source region.
 *  @param size The size of the region to move.
 */
void
NvOsMemmove(void *dest, const void *src, size_t size);

/**
 * Like NvOsMemcpy(), but used to safely copy data from an application pointer
 * (usually embedded inside an \c ioctl() struct) into a driver pointer. Does not
 * make any assumptions about whether the application pointer is valid--will
 * return an error instead of crashing if it isn't. Must also validate that
 * the application pointer points to memory that the application owns; for
 * example, it should point to the user mode region of the address space and
 * not the kernel mode region, if such a distinction exists.
 *
 * @see NvOsCopyOut
 *
 * @param pDst A pointer to the destination (driver).
 * @param pSrc A pointer to the source (client/application).
 * @param Bytes The number of bytes to copy.
 */
NvError
NvOsCopyIn(
    void *pDst,
    const void *pSrc,
    size_t Bytes);

/**
 * Like NvOsMemcpy(), but used to safely copy data to an application pointer
 * (usually embedded inside an \c ioctl() struct) from a driver pointer. Does not
 * make any assumptions about whether the application pointer is valid--will
 * return an error instead of crashing if it isn't. Must also validate that
 * the application pointer points to memory that the application owns; for
 * example, it should point to the user mode region of the address space and
 * not the kernel mode region, if such a distinction exists.
 *
 * @see NvOsCopyIn
 *
 * @param pDst A pointer to the destination (client/application).
 * @param pSrc A pointer to the source (driver).
 * @param Bytes The number of bytes to copy.
 */
NvError
NvOsCopyOut(
    void *pDst,
    const void *pSrc,
    size_t Bytes);

/*@}*/
/** @name File Input/Output
 */
/*@{*/

/**
 *
 *  Defines wrappers over stdlib's file stream functions,
 *  with some changes to the API.
 */
typedef enum
{
    /** See the fseek manual page for details of Set, Cur, and End. */
    NvOsSeek_Set = 0,
    NvOsSeek_Cur = 1,
    NvOsSeek_End = 2,

    NvOsSeek_Force32 = 0x7FFFFFFF
} NvOsSeekEnum;

typedef enum
{
    NvOsFileType_Unknown = 0,
    NvOsFileType_File,
    NvOsFileType_Directory,
    NvOsFileType_Fifo,
    NvOsFileType_CharacterDevice,
    NvOsFileType_BlockDevice,

    NvOsFileType_Force32 = 0x7FFFFFFF
} NvOsFileType;

typedef struct NvOsStatTypeRec
{
    NvU64 size;
    NvOsFileType type;
} NvOsStatType;

/** Opens a file with read permissions. */
#define NVOS_OPEN_READ    0x1

/** Opens a file with write persmissions. */
#define NVOS_OPEN_WRITE   0x2

/** Creates a file if is not present on the file system. */
#define NVOS_OPEN_CREATE  0x4

/** Opens a file stream.
 *
 *  If the ::NVOS_OPEN_CREATE flag is specified, ::NVOS_OPEN_WRITE must also
 *  be specified.
 *
 *  If \c NVOS_OPEN_WRITE is specified, the file will be opened for write and
 *  will be truncated if it was previously existing.
 *
 *  If \c NVOS_OPEN_WRITE and ::NVOS_OPEN_READ are specified, the file will not
 *  be truncated.
 *
 *  @param path A pointer to the path to the file.
 *  @param flags Or'd flags for the open operation (\c NVOS_OPEN_*).
 *  @param [out] file A pointer to the file that will be opened, if successful.
 */
NvError
NvOsFopen(const char *path, NvU32 flags, NvOsFileHandle *file);

/** Closes a file stream.
 *
 *  @param stream The file stream to close.
 *  Passing in a null handle is okay.
 */
void NvOsFclose(NvOsFileHandle stream);

/** Writes to a file stream.
 *
 *  @param stream The file stream.
 *  @param ptr A pointer to the data to write.
 *  @param size The length of the write.
 *
 *  @retval NvError_FileWriteFailed Returned on error.
 */
NvError
NvOsFwrite(NvOsFileHandle stream, const void *ptr, size_t size);

/** Reads a file stream.
 *
 *  Buffered read implementation if available for a particular OS may
 *  return corrupted data if multiple threads read from the same
 *  stream simultaneously.
 *
 *  To detect short reads (less that specified amount), pass in \a bytes
 *  and check its value to the expected value. The \a bytes parameter may
 *  be null.
 *
 *  @param stream The file stream.
 *  @param ptr A pointer to the buffer for the read data.
 *  @param size The length of the read.
 *  @param [out] bytes A pointer to the number of bytes readd; may be null.
 *
 *  @retval NvError_FileReadFailed If the file read encountered any
 *      system errors.
 */
NvError
NvOsFread(NvOsFileHandle stream, void *ptr, size_t size, size_t *bytes);

/** Reads a file stream with timeout.
 *
 *  Buffered read implementation if available for a particular OS may
 *  return corrupted data if multiple threads read from the same
 *  stream simultaneously.
 *
 *  To detect short reads (less that specified amount), pass in \a bytes
 *  and check its value to the expected value. The \a bytes parameter may
 *  be null.
 *
 *  @param stream The file stream.
 *  @param ptr A pointer to the buffer for the read data.
 *  @param size The length of the read.
 *  @param [out] bytes A pointer to the number of bytes read; may be null.
 *  @param timeout_msec Timeout for function to return if no bytes available.
 *
 *  @retval NvError_FileReadFailed If the file read encountered any
 *      system errors.
 *  @retval NvError_Timeout If no bytes are available to read.
 */
NvError
NvOsFreadTimeout(
    NvOsFileHandle stream,
    void *ptr,
    size_t size,
    size_t *bytes,
    NvU32 timeout_msec);

/** Gets a character from a file stream.
 *
 *  @param stream The file stream.
 *  @param [out] c A pointer to the character from the file stream.
 *
 *  @retval NvError_EndOfFile When the end of file is reached.
 */
NvError
NvOsFgetc(NvOsFileHandle stream, NvU8 *c);

/** Changes the file position pointer.
 *
 *  @param file The file.
 *  @param offset The offset from whence to seek.
 *  @param whence The starting point for the seek.
 *
 *  @retval NvError_FileOperationFailed On error.
 */
NvError
NvOsFseek(NvOsFileHandle file, NvS64 offset, NvOsSeekEnum whence);

/** Gets the current file position pointer.
 *
 *  @param file The file.
 *  @param [out] position A pointer to the file position.
 *
 *  @retval NvError_FileOperationFailed On error.
 */
NvError
NvOsFtell(NvOsFileHandle file, NvU64 *position);

/** Gets file information.
 *
 *  @param filename A pointer to the file about which to get information.
 *  @param [out] stat A pointer to the information structure.
 */
NvError
NvOsStat(const char *filename, NvOsStatType *stat);

/** Gets file information from an already open file.
 *
 *  @param file The open file.
 *  @param [out] stat A pointer to the information structure.
 */
NvError
NvOsFstat(NvOsFileHandle file, NvOsStatType *stat);

/** Flushes any pending writes to the file stream.
 *
 *  @param stream The file stream.
 */
NvError
NvOsFflush(NvOsFileHandle stream);

/** Commits any pending writes to storage media.
 *
 *  After this completes, any pending writes are guaranteed to be on the
 *  storage media associated with the stream (if any).
 *
 *  @param stream The file stream.
 */
NvError
NvOsFsync(NvOsFileHandle stream);

/** Removes a file from the storage media.  If the file is open,
 *  this function marks the file for deletion upon close.
 *
 *  @param filename The file to remove
 *
 *  The following error conditions are possible:
 *  
 *  NvError_FileOperationFailed - cannot remove file
 */
NvError
NvOsFremove(const char *filename);

/**
 * Thunk into the device driver implementing this file (usually a device file)
 * to perform an I/O control (IOCTL) operation.
 *
 * @param hFile The file on which to perform the IOCTL operation.
 * @param IoctlCode The IOCTL code (which operation to perform).
 * @param pBuffer A pointer to the buffer containing the data for the IOCTL
 *     operation. This buffer must first consist of \a InBufferSize bytes of
 *     input-only data, followed by \a InOutBufferSize bytes of input/output
 *     data, and finally \a OutBufferSize bytes of output-only data. Its total
 *     size is therefore:
 * <pre>
 *     InBufferSize + InOutBufferSize + OutBufferSize
   </pre>
 * @param InBufferSize The number of input-only data bytes in the buffer.
 * @param InOutBufferSize The number of input/output data bytes in the buffer.
 * @param OutBufferSize The number of output-only data bytes in the buffer.
 */
NvError
NvOsIoctl(
    NvOsFileHandle hFile,
    NvU32 IoctlCode,
    void *pBuffer,
    NvU32 InBufferSize,
    NvU32 InOutBufferSize,
    NvU32 OutBufferSize);

/*@}*/
/** @name Directories
 */
/*@{*/

/** A handle to a directory. */
typedef struct NvOsDirRec *NvOsDirHandle;

/** Opens a directory.
 *
 *  @param path A pointer to the path of the directory to open.
 *  @param [out] dir A pointer to the directory that will be opened, if successful.
 *
 *  @retval NvError_DirOperationFailed Returned upon failure.
 */
NvError
NvOsOpendir(const char *path, NvOsDirHandle *dir);

/** Gets the next entry in the directory.
 *
 *  @param dir The directory pointer.
 *  @param [out] name A pointer to the name of the next file.
 *  @param size The size of the name buffer.
 *
 *  @retval NvError_EndOfDirList When there are no more entries in the
 *      directory.
 *  @retval NvError_DirOperationFailed If there is a system error.
 */
NvError
NvOsReaddir(NvOsDirHandle dir, char *name, size_t size);

/** Closes the directory.
 *
 *  @param dir The directory to close.
 *      Passing in a null handle is okay.
 */
void NvOsClosedir(NvOsDirHandle dir);

/** Virtual filesystem hook. */
typedef struct NvOsFileHooksRec {

    NvError (*hookFopen)(
                    const char *path,
                    NvU32 flags,
                    NvOsFileHandle *file );
    void    (*hookFclose)(
                    NvOsFileHandle stream);
    NvError (*hookFwrite)(
                    NvOsFileHandle stream,
                    const void *ptr,
                    size_t size);
    NvError (*hookFread)(
                    NvOsFileHandle stream,
                    void *ptr,
                    size_t size,
                    size_t *bytes,
                    NvU32 timeout_msec);
    NvError (*hookFseek)(
                    NvOsFileHandle file,
                    NvS64 offset,
                    NvOsSeekEnum whence);
    NvError (*hookFtell)(
                    NvOsFileHandle file,
                    NvU64 *position);
    NvError (*hookFstat)(
                    NvOsFileHandle file,
                    NvOsStatType *stat);
    NvError (*hookStat)(
                    const char *filename,
                    NvOsStatType *stat);
    NvError (*hookFflush)(
                    NvOsFileHandle stream);
    NvError (*hookFsync)(
                    NvOsFileHandle stream);
    NvError (*hookFremove)(
                    const char *filename);
    NvError (*hookOpendir)(
                    const char *path,
                    NvOsDirHandle *dir);
    NvError (*hookReaddir)(
                    NvOsDirHandle dir,
                    char *name,
                    size_t size);
    void    (*hookClosedir)(
                    NvOsDirHandle dir);
} NvOsFileHooks;

/** Sets up hook functions for extra stream functionality.
 *
 *  @note All function pointers must be non-NULL.
 *
 *  @param newHooks A pointer to the new set of functions to handle file I/O.
 *  NULL for defaults.
 */
const NvOsFileHooks *NvOsSetFileHooks(NvOsFileHooks *newHooks);

/* configuration variables (in place of getenv) */

/** Retrives an unsigned integer variable from the environment.
 *
 *  @param name A pointer to the name of the variable.
 *  @param [out] value A pointer to the value to write.
 *
 *  @retval NvError_ConfigVarNotFound If the name isn't found in the
 *      environment.
 *  @retval NvError_InvalidConfigVar If the configuration variable cannot
 *      be converted into an unsiged integer.
 */
NvError
NvOsGetConfigU32(const char *name, NvU32 *value);

/** Retreives a string variable from the environment.
 *
 *  @param name A pointer to the name of the variable.
 *  @param value A pointer to the value to write into.
 *  @param size The size of the value buffer.
 *
 *  @retval NvError_ConfigVarNotFound If the name isn't found in the
 *      environment.
 */
NvError
NvOsGetConfigString(const char *name, char *value, NvU32 size);

/*@}*/
/** @name Memory Allocation
 */
/*@{*/

/** Dynamically allocates memory.
 *  Alignment, if desired, must be done by the caller.
 *
 *  @param size The size of the memory to allocate.
 */
void *NvOsAlloc(size_t size);

/** Re-sizes a previous dynamic allocation.
 *
 *  @param ptr A pointer to the original allocation.
 *  @param size The new size to allocate.
 */
void *NvOsRealloc(void *ptr, size_t size);

/** Frees a dynamic memory allocation.
 *
 *  Freeing a null value is okay.
 *
 *  @param ptr A pointer to the memory to free, which should be from
 *      NvOsAlloc().
 */
void NvOsFree(void *ptr);

/**
 * Alocates a block of executable memory.
 *
 * @param size The size of the memory to allocate.
 */
void *NvOsExecAlloc(size_t size);

/**
 * Frees a block of executable memory.
 *
 * @param ptr A pointer from NvOsExecAlloc() to the memory to free; may be null.
 * @param size The size of the allocation.
 */
void NvOsExecFree(void *ptr, size_t size);

/** An opaque handle returned by shared memory allocations.
 */
typedef struct NvOsSharedMemRec *NvOsSharedMemHandle;

/** Dynamically allocates multiprocess shared memory.
 *
 *  The memory will be zero initialized when it is first created.
 *
 *  @param key A pointer to the global key to identify the shared allocation.
 *  @param size The size of the allocation.
 *  @param [out] descriptor A pointer to the result descriptor.
 *
 *  @return If the shared memory for \a key already exists, then this returns
 *  the already allcoated shared memory; otherwise, it creates it.
 */
NvError
NvOsSharedMemAlloc(const char *key, size_t size,
    NvOsSharedMemHandle *descriptor);

/** Maps a shared memory region into the process virtual memory.
 *
 *  @param descriptor The memory descriptor to map.
 *  @param offset The offset in bytes into the mapped area.
 *  @param size The size area to map.
 *  @param [out] ptr A pointer to the result pointer.
 *
 *  @retval NvError_SharedMemMapFailed Returned on failure.
 */
NvError
NvOsSharedMemMap(NvOsSharedMemHandle descriptor, size_t offset,
    size_t size, void **ptr);

/** Unmaps a mapped region of shared memory.
 *
 *  @param ptr A pointer to the pointer to virtual memory.
 *  @param size The size of the mapped region.
 */
void NvOsSharedMemUnmap(void *ptr, size_t size);

/** Frees shared memory from NvOsSharedMemAlloc().
 *
 *  It is valid to call \c NvOsSharedMemFree while mappings are still
 *  outstanding.
 *
 *  @param descriptor The memory descriptor.
 */
void NvOsSharedMemFree(NvOsSharedMemHandle descriptor);

/** Defines memory attributes. */
typedef enum
{
    NvOsMemAttribute_Uncached      = 0,
    NvOsMemAttribute_WriteBack     = 1,
    NvOsMemAttribute_WriteCombined = 2,

    NvOsMemAttribute_Force32 = 0x7FFFFFFF
} NvOsMemAttribute;

/** Specifies no memory flags. */
#define NVOS_MEM_NONE     0x0

/** Specifies the memory may be read. */
#define NVOS_MEM_READ     0x1

/** Specifies the memory may be written to. */
#define NVOS_MEM_WRITE    0x2

/** Specifies the memory may be executed. */
#define NVOS_MEM_EXECUTE  0x4

/**
 * The memory must be visible by all processes, this is only valid for
 * WinCE 5.0.
 */
#define NVOS_MEM_GLOBAL_ADDR 0x8

/** The memory may be both read and writen. */
#define NVOS_MEM_READ_WRITE (NVOS_MEM_READ | NVOS_MEM_WRITE)

/** Maps computer resources into user space.
 *
 *  @param phys The physical address start.
 *  @param size The size of the aperture.
 *  @param attrib Memory attributes (caching).
 *  @param flags Bitwise OR of \c NVOS_MEM_*.
 *  @param [out] ptr A pointer to the result pointer.
 */
NvError
NvOsPhysicalMemMap(NvOsPhysAddr phys, size_t size,
    NvOsMemAttribute attrib, NvU32 flags, void **ptr);

/** Maps computer resources into user space.
 *
 * This function is intended to be called by device drivers only,
 * and will fail in user space. The virtual address can be allocated
 * by calling NvRmOsPhysicalMemMap() with flags set to ::NVOS_MEM_NONE, which
 * should be done by the calling process. That virtual region will be
 * passed to some device driver, and this function will set up the
 * PTEs to make the virtual space point to the supplied physical
 * address.
 *
 * This is used by NvRmMemMap() to map memory under WinCE6 where user
 * mode applications cannot map physical memory directly.
 *
 *  @param pCallerPtr A pointer to the virtual address from the calling process.
 *  @param phys The physical address start.
 *  @param size The size of the aperture.
 *  @param attrib Memory attributes (caching).
 *  @param flags Bitwise OR of NVOS_MEM_*.
 */
NvError
NvOsPhysicalMemMapIntoCaller(void *pCallerPtr, NvOsPhysAddr phys,
    size_t size, NvOsMemAttribute attrib, NvU32 flags);

/**
 * Releases resources previously allocated by NvOsPhysicalMemMap().
 *
 * @param ptr The virtual pointer returned by \c NvOsPhysicalMemMap. If this
 *     pointer is null, this function has no effect.
 * @param size The size of the mapped region.
 */
void NvOsPhysicalMemUnmap(void *ptr, size_t size);

/*@}*/
/** @name Page Allocator
 */
/*@{*/

/** 
 *  Low-level memory allocation of the external system memory.
 */
typedef enum
{
    NvOsPageFlags_Contiguous    = 0,
    NvOsPageFlags_NonContiguous = 1,

    NvOsMemFlags_Forceword = 0x7ffffff,
} NvOsPageFlags;

typedef struct NvOsPageAllocRec *NvOsPageAllocHandle;

/** Allocates memory via the page allocator.
 *
 *  @param size The number of bytes to allocate.
 *  @param attrib Page caching attributes.
 *  @param flags Various memory allocation flags.
 *  @param protect Page protection attributes (\c NVOS_MEM_*).
 *  @param [out] descriptor A pointer to the result descriptor.
 *
 *  @return A descriptor (not a pointer to virtual memory),
 *  which may be passed into other functions.
 */
NvError
NvOsPageAlloc(size_t size, NvOsMemAttribute attrib,
    NvOsPageFlags flags, NvU32 protect, NvOsPageAllocHandle *descriptor);

/**
 * Locks down the pages in a region of memory and provides a descriptor that can
 * be used to query the PTEs. Locked pages are guaranteed to not be swapped
 * out or moved by the OS. To unlock the pages when done, call NvOsPageFree()
 * on the resulting descriptor.
 *
 * @param ptr Pointer to the buffer to lock down.
 * @param size Number of bytes in the buffer to lock down.
 * @param protect Page protection attributes (NVOS_MEM_*)
 * @param [out] descriptor Output parameter to pass back the descriptor.
 *
 * @retval NvSuccess If successful, or the appropriate error code.
 * @note Some operating systems may not support this operation and will return
 *     \a NvError_NotImplemented to all requests.
 */
NvError
NvOsPageLock(void *ptr, size_t size, NvU32 protect, NvOsPageAllocHandle *descriptor);

/** Frees pages from NvOsPageAlloc().
 *
 *  It is not valid to call NvOsPageFree() while there are outstanding
 *  mappings.
 *
 *  @param descriptor The descriptor from \c NvOsPageAlloc.
 */
void
NvOsPageFree(NvOsPageAllocHandle descriptor);

/** Maps pages into the virtual address space.
 *
 *  Upon successful completion, \a *ptr holds a virtual address
 *  that may be accessed.
 *
 *  @param descriptor Allocated pages from NvOsPageAlloc(), etc.
 *  @param offset Offset in bytes into the page range.
 *  @param size The size of the mapping.
 *  @param [out] ptr A pointer to the result pointer.
 *
 * @retval NvSuccess If successful, or the appropriate error code.
 */
NvError
NvOsPageMap(NvOsPageAllocHandle descriptor, size_t offset, size_t size,
    void **ptr);

/** Maps pages into the provided virtual address space.
 *
 *  Virtual address space can be obtained by calling
 *  NvOsPhysicalMemMap() and passing ::NVOS_MEM_NONE for the
 *  flags parameter.
 * 
 * @note You should only use this function if you really, really
 *       know what you are doing(1).
 *
 *  Upon successful completion, \a *ptr holds a virtual address
 *  that may be accessed.
 *
 *  @param descriptor Allocated pages from NvOsPageAlloc(), etc.
 *  @param pCallerPtr Pointer to user supplied virtual address space.
 *  @param offset Offset in bytes into the page range
 *  @param size The size of the mapping
 *
 * @retval NvSuccess If successful, or the appropriate error code.
 */
NvError
NvOsPageMapIntoPtr(NvOsPageAllocHandle descriptor, void *pCallerPtr,
    size_t offset, size_t size);

/** Unmaps the virtual address from NvOsPageMap().
 *
 *  @param descriptor Allocated pages from NvOsPageAlloc(), etc.
 *  @param ptr A pointer to the virtual address to unmap that was returned
 *      from \c NvOsPageMap.
 *  @param size The size of the mapping, which should match what
 *   was passed into \c NvOsPageMap.
 */
void
NvOsPageUnmap(NvOsPageAllocHandle descriptor, void *ptr, size_t size);

/** Returns the physical address given an offset.
 *
 *  This is useful for non-contiguous page allocations.
 *
 *  @param descriptor The descriptor from NvOsPageAlloc(), etc.
 *  @param offset The offset in bytes into the page range.
 */
NvOsPhysAddr
NvOsPageAddress(NvOsPageAllocHandle descriptor, size_t offset);

/*@}*/
/** @name Dynamic Library Handling
 */
/*@{*/

/** A handle to a dynamic library. */
typedef struct NvOsLibraryRec *NvOsLibraryHandle;

/** Load a dynamic library.
 *
 *  No operating system specific suffixes or paths should be used for the
 *  library name. So do not use:
 *  <pre>
        /usr/lib/libnvos.so
        libnvos.dll
    </pre>
 * Just use:
 *  <pre>
    libnvos 
   </pre>
 *
 *  @param name A pointer to the library name.
 *  @param [out] library A pointer to the result library.
 *
 *  @retval NvError_LibraryNotFound If the library cannot be opened.
 */
NvError
NvOsLibraryLoad(const char *name, NvOsLibraryHandle *library);

/** Gets an address of a symbol in a dynamic library.
 *
 *  @param library The dynamic library.
 *  @param symbol A pointer to the symbol to lookup.
 *
 *  @return The address of the symbol, or NULL if the symbol cannot be found.
 */
void*
NvOsLibraryGetSymbol(NvOsLibraryHandle library, const char *symbol);

/** Unloads a dynamic library.
 *
 *  @param library The dynamic library to unload.
 *      It is okay to pass a null \a library value.
 */
void
NvOsLibraryUnload(NvOsLibraryHandle library);

/*@}*/
/** @name Syncronization Objects and Thread Management
 */
/*@{*/

typedef struct NvOsMutexRec *NvOsMutexHandle;
typedef struct NvOsIntrMutexRec *NvOsIntrMutexHandle;
typedef struct NvOsSpinMutexRec *NvOsSpinMutexHandle;
typedef struct NvOsSemaphoreRec *NvOsSemaphoreHandle;
typedef struct NvOsThreadRec *NvOsThreadHandle;

/** Unschedules the calling thread for at least the given
 *      number of milliseconds.
 *
 *  Other threads may run during the sleep time.
 *
 *  @param msec The number of milliseconds to sleep.
 */
void
NvOsSleepMS(NvU32 msec);

/** Stalls the calling thread for at least the given number of
 *  microseconds. The actual time waited might be longer; you cannot
 *  depend on this function for precise timing.
 *
 *  @note It is safe to use this function at ISR time.
 *
 *  @param usec The number of microseconds to wait.
 */
void
NvOsWaitUS(NvU32 usec);

/**
 * Allocates a new (intra-process) mutex.
 *
 * @note Mutexes can be locked recursively; if a thread owns the lock,
 * it can lock it again as long as it unlocks it an equal number of times.
 *
 * @param mutex The mutex to initialize.
 *
 * @return \a NvError_MutexCreateFailed, or one of common error codes on
 * failure.
 */
NvError NvOsMutexCreate(NvOsMutexHandle *mutex);

/** Locks the given unlocked mutex.
 *
 *  If a process is holding a lock on a multi-process mutex when it terminates,
 *  this lock will be automatically released.
 *
 *  @param mutex The mutex to lock; note that this is a recursive lock.
 */
void NvOsMutexLock(NvOsMutexHandle mutex);

/** Unlocks a locked mutex.
 *
 *  A mutex must be unlocked exactly as many times as it has been locked.
 *
 *  @param mutex The mutex to unlock.
 */
void NvOsMutexUnlock(NvOsMutexHandle mutex);

/** Frees the resources held by a mutex.
 *
 *  Mutecies are reference counted across the computer (multiproceses),
 *  and a given mutex will not be destroyed until the last reference has
 *  gone away.
 *
 *  @param mutex The mutex to destroy. Passing in a null mutex is okay.
 */
void NvOsMutexDestroy(NvOsMutexHandle mutex);

/**
 * Creates a mutex that is safe to aquire in an ISR.
 *
 * @param mutex A pointer to the mutex is stored here on success.
 */
NvError NvOsIntrMutexCreate(NvOsIntrMutexHandle *mutex);

/**
 * Aquire an ISR-safe mutex.
 *
 * @param mutex The mutex to lock. For kernel (OAL) implementations,
 *     NULL implies the system-wide lock will be used.
 */
void NvOsIntrMutexLock(NvOsIntrMutexHandle mutex);

/**
 * Releases an ISR-safe mutex.
 *
 * @param mutex The mutex to unlock. For kernel (OAL) implementations,
 *     NULL implies the system-wide lock will be used.
 */
void NvOsIntrMutexUnlock(NvOsIntrMutexHandle mutex);

/**
 * Destroys an ISR-safe mutex.
 *
 * @param mutex The mutex to destroy. If \a mutex is NULL, this API has no
 *     effect.
 */
void NvOsIntrMutexDestroy(NvOsIntrMutexHandle mutex);

/**
 * Creates a spin mutex.
 * This mutex is SMP safe, but it is not ISR-safe.
 *
 * @param mutex A pointer to the mutex is stored here on success.
 */
NvError NvOsSpinMutexCreate(NvOsSpinMutexHandle *mutex);

/**
 * Acquire a spin mutex.
 * Spins until mutex is acquired; when acquired disables kernel preemption.
 *
 * @param mutex The mutex handle to lock.
 */
void NvOsSpinMutexLock(NvOsSpinMutexHandle mutex);

/**
 * Releases a spin mutex.
 *
 * @param mutex The mutex handle to unlock.
 */
void NvOsSpinMutexUnlock(NvOsSpinMutexHandle mutex);

/**
 * Destroys a spin mutex.
 *
 * @param mutex The mutex to destroy. If \a mutex is NULL, this API has no
 *     effect.
 */
void NvOsSpinMutexDestroy(NvOsSpinMutexHandle mutex);

/**
 * Creates a counting semaphore.
 *
 * @param semaphore A pointer to the semaphore to initialize.
 * @param value The initial semaphore value.
 *
 * @retval NvSuccess If successful, or the appropriate error code.
 */
NvError
NvOsSemaphoreCreate(NvOsSemaphoreHandle *semaphore, NvU32 value);

/**
 * Creates a duplicate semaphore from the given semaphore.
 * Freeing the original semaphore has no effect on the new semaphore.
 *
 * @param orig The semaphore to duplicate.
 * @param semaphore A pointer to the new semaphore.
 *
 * @retval NvSuccess If successful, or the appropriate error code.
 */
NvError
NvOsSemaphoreClone( NvOsSemaphoreHandle orig,  NvOsSemaphoreHandle *semaphore);

/**
 * Obtains a safe, usable handle to a semaphore passed across an ioctl()
 * interface by a client to a device driver. Validates that the original
 * semaphore handle is legal, and creates a new handle (valid in the driver's
 * process/address space) that the client cannot asynchronously destroy.
 *
 * The new handle must be freed, just like any other semaphore handle, by
 * passing it to NvOsSemaphoreDestroy().
 *
 * @param hClientSema The client's semaphore handle.
 * @param phDriverSema If successful, returns a new handle to the semaphore
 *     that the driver can safely use.
 *
 * @retval NvSuccess If successful, or the appropriate error code.
 */
NvError
NvOsSemaphoreUnmarshal( NvOsSemaphoreHandle hClientSema,
    NvOsSemaphoreHandle *phDriverSema);

/** Waits until the semaphore value becomes non-zero, then
 *  decrements the value and returns.
 *
 *  @param semaphore The semaphore to wait for.
 */
void NvOsSemaphoreWait(NvOsSemaphoreHandle semaphore);

/**
 * Waits for the given semaphore value to become non-zero with timeout. If
 * the semaphore value becomes non-zero before the timeout, then the value is
 * decremented and \a NvSuccess is returned.
 *
 * @param semaphore The semaphore to wait for.
 * @param msec Timeout value in milliseconds.
 *     ::NV_WAIT_INFINITE can be used to wait forever.
 *
 * @retval NvError_Timeout If the wait expires.
 */
NvError
NvOsSemaphoreWaitTimeout(NvOsSemaphoreHandle semaphore, NvU32 msec);

/** Increments the semaphore value.
 *
 *  @param semaphore The semaphore to signal.
 */
void
NvOsSemaphoreSignal(NvOsSemaphoreHandle semaphore);

/** Frees resources held by the semaphore.
 *
 *  Semaphores are reference counted across the computer (multiproceses),
 *  and a given semaphore will not be destroyed until the last reference has
 *  gone away.
 *
 *  @param semaphore The semaphore to destroy.
 *      Passing in a null semaphore is okay (no op).
 */
void
NvOsSemaphoreDestroy(NvOsSemaphoreHandle semaphore);

/** Sets thread mode.
 *
 * @pre If this is called, it must be called before any other threading function.
 * All but the first call to this function do nothing and return
 * \a NvError_AlreadyAllocated.
 *
 * @param coop 0 to disable coop mode, and 1 to enable coop mode.
 *
 * @returns NvSuccess On success.
 * @returns NvError_AlreadyAllocated If called previously.
 */
NvError NvOsThreadMode(int coop);

/** Entry point for a thread.
 */
typedef void (*NvOsThreadFunction)(void *args);

/** Creates a thread.
 *
 *  @param function The thread entry point.
 *  @param args A pointer to the thread arguments.
 *  @param [out] thread A pointer to the result thread ID structure.
 */
NvError
NvOsThreadCreate( NvOsThreadFunction function, void *args,
    NvOsThreadHandle *thread);

/** Creates a near interrupt priority thread.
 *
 *  @param function The thread entry point.
 *  @param args A pointer to the thread arguments.
 *  @param [out] thread A pointer to the result thread ID structure.
 */
NvError
NvOsInterruptPriorityThreadCreate( NvOsThreadFunction function, void *args,
    NvOsThreadHandle *thread);

/**
 * Sets the thread's priority to low priority.
 *
 * @retval NvError_NotSupported May be returned.
 */
NvError NvOsThreadSetLowPriority(void);

/** Waits for the given thread to exit.
 *
 *  The joined thread will be destroyed automatically. All OS resources
 *  will be reclaimed. There is no method for terminating a thread
 *  before it exits naturally.
 *
 *  @param thread The thread to wait for.
 *  Passing in a null thread ID is okay (no op).
 */
void NvOsThreadJoin(NvOsThreadHandle thread);

/** Yields to another runnable thread.
 */
void NvOsThreadYield(void);

/**
 * Atomically compares the contents of a 32-bit memory location with a value,
 * and if they match, updates it to a new value. This function is the
 * equivalent of the following code, except that other threads or processors
 * are effectively prevented from reading or writing \a *pTarget while we are
 * inside the function.
 *
 * @code
 * NvS32 OldTarget = *pTarget;
 * if (OldTarget == OldValue)
 *     *pTarget = NewValue;
 * return OldTarget;
 * @endcode
 */
NvS32 NvOsAtomicCompareExchange32(NvS32 *pTarget, NvS32 OldValue, NvS32
    NewValue);

/**
 * Atomically swaps the contents of a 32-bit memory location with a value. This
 * function is the equivalent of the following code, except that other threads
 * or processors are effectively prevented from reading or writing \a *pTarget
 * while we are inside the function.
 *
 * @code
 * NvS32 OldTarget = *pTarget;
 * *pTarget = Value;
 * return OldTarget;
 * @endcode
 */
NvS32 NvOsAtomicExchange32(NvS32 *pTarget, NvS32 Value);

/**
 * Atomically increments the contents of a 32-bit memory location by a specified
 * amount. This function is the equivalent of the following code, except that
 * other threads or processors are effectively prevented from reading or
 * writing \a *pTarget while we are inside the function.
 *
 * @code
 * NvS32 OldTarget = *pTarget;
 * *pTarget = OldTarget + Value;
 * return OldTarget;
 * @endcode
 */
NvS32 NvOsAtomicExchangeAdd32(NvS32 *pTarget, NvS32 Value);

/** A TLS index that is guaranteed to be invalid. */
#define NVOS_INVALID_TLS_INDEX 0xFFFFFFFF
#define NVOS_TLS_CNT            4

/**
 * Allocates a thread-local storage variable. All TLS variables have initial
 * value NULL in all threads when first allocated.
 *
 * @returns The TLS index of the TLS variable if successful, or
 *     ::NVOS_INVALID_TLS_INDEX if not.
 */
NvU32 NvOsTlsAlloc(void);

/**
 * Frees a thread-local storage variable.
 *
 * @param TlsIndex The TLS index of the TLS variable. This function is a no-op
 *     if TlsIndex equals ::NVOS_INVALID_TLS_INDEX.
 */
void NvOsTlsFree(NvU32 TlsIndex);

/**
 * Gets the value of a thread-local storage variable.
 *
 * @param TlsIndex The TLS index of the TLS variable.
 *     The current value of the TLS variable is returned.
 */
void *NvOsTlsGet(NvU32 TlsIndex);

/**
 * Sets the value of a thread-local storage variable.
 *
 * @param TlsIndex The TLS index of the TLS variable.
 * @param Value A pointer to the new value of the TLS variable.
 */
void NvOsTlsSet(NvU32 TlsIndex, void *Value);

/*@}*/
/** @name Time Functions
 */
/*@{*/

/** @return The system time in milliseconds.
 *
 *  The returned values are guaranteed to be monotonically increasing,
 *  but may wrap back to zero (after about 50 days of runtime).
 *
 *  In some systems, this is the number of milliseconds since power-on,
 *  or may actually be an accurate date.
 */
NvU32
NvOsGetTimeMS(void);

/** @return The system time in microseconds.
 *
 *  The returned values are guaranteed to be monotonically increasing,
 *  but may wrap back to zero.
 *
 *  Some systems cannot gauantee a microsecond resolution timer.
 *  Even though the time returned is in microseconds, it is not gaurnateed
 *  to have micro-second resolution.
 *
 *  Please be advised that this API is mainly used for code profiling and
 *  meant to be used direclty in driver code.
 */
NvU64
NvOsGetTimeUS(void);

/*@}*/
/** @name CPU Cache
 *  Cache operations for both instruction and data cache, implemented
 *  per processor.
 */
/*@{*/

/** Writes back the entire data cache.
 */
void
NvOsDataCacheWriteback(void);

/** Writes back and invalidates the entire data cache.
 */
void
NvOsDataCacheWritebackInvalidate(void);

/** Writes back a range of the data cache.
 *
 *  @param start A pointer to the start address.
 *  @param length The number of bytes to write back.
 */
void
NvOsDataCacheWritebackRange(void *start, NvU32 length);

/** Writes back and invlidates a range of the data cache.
 *
 *  @param start A pointer to the start address.
 *  @param length The number of bytes to write back.
 */
void
NvOsDataCacheWritebackInvalidateRange(void *start, NvU32 length);

/** Invalidates the entire instruction cache.
 */
void
NvOsInstrCacheInvalidate(void);

/** Invalidates a range of the instruction cache.
 *
 *  @param start A pointer to the start address.
 *  @param length The number of bytes.
 */
void
NvOsInstrCacheInvalidateRange(void *start, NvU32 length);

/** Flushes the CPU's write combine buffer.
 */
void
NvOsFlushWriteCombineBuffer(void);

/** Interrupt handler function.
 */
typedef void (*NvOsInterruptHandler)(void *args);

/** Interrupt handler type.
 */
typedef struct NvOsInterruptRec *NvOsInterruptHandle;

/**
 * Registers the interrupt handler with the IRQ number.
 *
 * @note This function is intended to @b only be called
 *       from NvRmInterruptRegister().
 *
 * @param IrqListSize Size of the \a IrqList passed in for registering the IRQ
 *      handlers for each IRQ number.
 * @param pIrqList Array of IRQ numbers for which interupt handlers are to be
 *     registerd.
 * @param pIrqHandlerList A pointer to an array of interrupt routines to be
 *      called when an interrupt occurs.
 * @param context A pointer to the register's context handle.
 * @param handle A pointer to the interrupt handle.
 * @param InterruptEnable If true, immediately enable interrupt.  Otherwise
 *      enable interrupt only after calling NvOsInterruptEnable().
 *
 * @retval NvError_IrqRegistrationFailed If the interrupt is already registered.
 * @retval NvError_BadParameter If the IRQ number is not valid.
 */
NvError
NvOsInterruptRegister(NvU32 IrqListSize,
    const NvU32 *pIrqList,
    const NvOsInterruptHandler *pIrqHandlerList,
    void *context,
    NvOsInterruptHandle *handle,
    NvBool InterruptEnable);

/**
 * Unregisters the interrupt handler from the associated IRQ number.
 *
 * @note This function is intended to @b only be called
 *       from NvRmInterruptUnregister().
 *
 * @param handle interrupt Handle returned when a successfull call is made to
 *     NvOsInterruptRegister().
 */
void
NvOsInterruptUnregister(NvOsInterruptHandle handle);

/**
 * Enables the interrupt handler with the IRQ number.
 *
 * @note This function is intended to @b only be called
 *       from NvOsInterruptRegister() and NvRmInterruptRegister().
 *
 * @param handle Interrupt handle returned when a successfull call is made to
 *     \c NvOsInterruptRegister.
 *
 * @retval NvError_BadParameter If the handle is not valid.
 * @retval NvError_InsufficientMemory If interrupt enable failed.
 * @retval NvSuccess If interrupt enable is successful.
 */
NvError
NvOsInterruptEnable(NvOsInterruptHandle handle);

/**
 *  Called when the ISR/IST is done handling the interrupt.
 *
 *  @note This API should be called only from NvRmInterruptDone().
 *
 * @param handle Interrupt handle returned when a successfull call is made to
 *     NvOsInterruptRegister().
 */
void
NvOsInterruptDone(NvOsInterruptHandle handle);

/**
 * Mask/unmask an interrupt.
 *
 * Drivers can use this API to fend off interrupts. Mask means no interrupts
 * are forwarded to the CPU. Unmask means, interrupts are forwarded to the
 * CPU. In case of SMP systems, this API masks the interrutps to all the CPUs,
 * not just the calling CPU.
 *
 * @param handle    Interrupt handle returned by NvOsInterruptRegister().
 * @param mask      NV_FALSE to forward the interrupt to CPU; NV_TRUE to
 *     mask the interrupts to CPU.
 */
void NvOsInterruptMask(NvOsInterruptHandle handle, NvBool mask);

#define NVOS_MAX_PROFILE_APERTURES  (4UL)

/**
 * Profile aperture sizes.
 *
 * Code may execute and be profiled from mutliple apertures. This will get the
 * size of each aperture. The caller is expected to allocate the number of
 * bytes for each aperture into a single void* array (void**), which will be
 * used in NvOsProfileStart() and NvOsProfileStop().
 *
 * This may be called twice, the first time to get the number of apertures
 * (sizes should be null), and the second time with the sizes parameter
 * non-null. Alternately, ::NVOS_MAX_PROFILE_APERTURES may be used as the
 * size of the sizes array.
 *
 * @param apertures A pointer to the number of apertures that will be profiled.
 * @param sizes A pointer to the size of each aperture.
 */
void
NvOsProfileApertureSizes( NvU32 *apertures, NvU32 *sizes );

/**
 * Enables statistical profiling.
 *
 * @param apertures A pointer to an array of storage for profile data.
 */
void
NvOsProfileStart( void **apertures );

/**
 * Stops profiling and prepares the profile samples for analysis.
 *
 * @param apertures A pointer to the storage for the profile samples.
 */
void
NvOsProfileStop( void **apertures );

/**
 * Writes profile data to the given file.
 *
 * @post This is expected to close the file after a successful write.
 *
 * @param file The file to write to.
 * @param index The aperture number.
 * @param aperture A pointer to the storage for the profile samples.
 */
NvError
NvOsProfileWrite( NvOsFileHandle file, NvU32 index, void *aperture );

/**
 * Sets the boot arguments from thet system's boot loader. The data may be keyed.
 *
 * @param key The key for the argument.
 * @param arg A pointer to the argument to store.
 * @param size The size of the argument in bytes.
 *
 * @retval NvSuccess If successful, or the appropriate error code.
 */
NvError
NvOsBootArgSet( NvU32 key, void *arg, NvU32 size );

/**
 * Retrieves the system boot arguments. Requires the same key from
 * NvOsBootArgSet().
 *
 * @param key The key for the argument.
 * @param arg A pointer to the argument buffer.
 * @param size The size of the argument in bytes.
 */
NvError
NvOsBootArgGet( NvU32 key, void *arg, NvU32 size );

/*
 * Tracing support. Enable with NVOS_TRACE in nvos_trace.h.
 */
#if NVOS_TRACE || NV_DEBUG

#if NV_DEBUG
void *NvOsAllocLeak( size_t size, const char *f, int l );
void *NvOsReallocLeak( void *ptr, size_t size, const char *f, int l );
void NvOsFreeLeak( void *ptr, const char *f, int l );
#endif

static NV_INLINE void *NvOsAllocTraced(size_t size, const char *f, int l)
{
    void *ptr;

#if NV_DEBUG
    ptr = (NvOsAllocLeak)(size, f, l);
#else
    ptr = (NvOsAlloc)(size);
#endif
#if NVOS_TRACE
    NVOS_TRACE_LOG_PRINTF(("NvOsAlloc, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)ptr));
#endif

    return ptr;
}

static NV_INLINE void *NvOsReallocTraced(void *ptr, size_t size, const char *f,
    int l )
{
    void* ret;

#if NV_DEBUG
    ret = (NvOsReallocLeak)(ptr, size, f, l);
#else
    ret = (NvOsRealloc)(ptr, size);
#endif
#if NVOS_TRACE
    NVOS_TRACE_LOG_PRINTF(("NvOsRealloc, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)ret));
#endif

    return ret;
}

static NV_INLINE void NvOsFreeTraced(void *ptr, const char *f, int l )
{

#if NV_DEBUG
    (NvOsFreeLeak)(ptr, f, l);
#else
    (NvOsFree)(ptr);
#endif
#if NVOS_TRACE
    NVOS_TRACE_LOG_PRINTF(("NvOsFree, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)ptr));
#endif
}


#define NvOsAlloc(size) NvOsAllocTraced(size, __FILE__, __LINE__)
#define NvOsRealloc(ptr, size) \
    NvOsReallocTraced(ptr, size, __FILE__, __LINE__)
#define NvOsFree(ptr) NvOsFreeTraced(ptr, __FILE__, __LINE__)

#endif /* NVOS_TRACE */


#if (NVOS_TRACE || NV_DEBUG)

/**
 * Sets the file and line corresponding to a resource allocation.
 * Call will fill file and line for the most recently stored 
 * allocation location, if not already set.
 *
 * @param userptr A pointer to used by client to identify resource. 
 *     Can be NULL, which leads to no-op.
 * @param file A pointer to the name of the file from which allocation 
 *     originated. Value cannot be NULL; use "" for an empty string.
 * @param l The line.
 */
void NvOsSetResourceAllocFileLine(void* userptr, const char* file, int line);

static NV_INLINE void *
NvOsExecAllocTraced(size_t size, const char *f, int l )
{
    void* ret;
    ret = (NvOsExecAlloc)(size);
    NvOsSetResourceAllocFileLine(ret, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsExecAlloc, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)ret));
    return ret;
}

static NV_INLINE void
NvOsExecFreeTraced(void *ptr, size_t size, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsExecFree, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)ptr));
    (NvOsExecFree)(ptr, size);
}

static NV_INLINE NvError
NvOsSharedMemAllocTraced(const char *key, size_t size,
    NvOsSharedMemHandle *descriptor, const char *f, int l )
{
    NvError status;
    status = (NvOsSharedMemAlloc)(key, size, descriptor);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*descriptor, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsSharedMemAlloc, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*descriptor)));
    return status;
}

static NV_INLINE NvError
NvOsSharedMemMapTraced(NvOsSharedMemHandle descriptor, size_t offset,
    size_t size, void **ptr, const char *f, int l )
{
    NvError status;
    status = (NvOsSharedMemMap)(descriptor, offset, size, ptr);
    NVOS_TRACE_LOG_PRINTF(("NvOsSharedMemMap, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*ptr)));
    return status;
}

static NV_INLINE void
NvOsSharedMemUnmapTraced(void *ptr, size_t size, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsSharedMemUnmap, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(ptr)));
    (NvOsSharedMemUnmap)(ptr, size);
}

static NV_INLINE void
NvOsSharedMemFreeTraced(NvOsSharedMemHandle descriptor, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsSharedMemFree, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(descriptor)));
    (NvOsSharedMemFree)(descriptor);
}

static NV_INLINE NvError
NvOsPhysicalMemMapTraced(NvOsPhysAddr phys, size_t size,
    NvOsMemAttribute attrib, NvU32 flags, void **ptr, const char *f, int l )
{
    NvError status;
    status = (NvOsPhysicalMemMap)(phys, size, attrib, flags, ptr);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*ptr, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsPhysicalMemMap, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*ptr)));
    return status;
}

static NV_INLINE NvError
NvOsPhysicalMemMapIntoCallerTraced( void *pCallerPtr, NvOsPhysAddr phys,
    size_t size, NvOsMemAttribute attrib, NvU32 flags, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsPhysicalMemMapIntoCaller, \
        %s, %d, %ums, 0x%x\n", f, l, NvOsGetTimeMS(), (NvU32)(pCallerPtr)));
    return (NvOsPhysicalMemMapIntoCaller)(pCallerPtr, phys, size, attrib,
        flags);
}

static NV_INLINE void
NvOsPhysicalMemUnmapTraced(void *ptr, size_t size, const char *f, int l )
{
     NVOS_TRACE_LOG_PRINTF(("NvOsPhysicalMemUnmap, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(ptr)));
     (NvOsPhysicalMemUnmap)(ptr, size);
}

static NV_INLINE NvError
NvOsPageAllocTraced(size_t size, NvOsMemAttribute attrib,
    NvOsPageFlags flags, NvU32 protect, NvOsPageAllocHandle *descriptor,
    const char *f, int l )
{
    NvError status;
    status = (NvOsPageAlloc)(size, attrib, flags, protect, descriptor);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*descriptor, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsPageAlloc, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(descriptor)));
    return status;
}

static NV_INLINE NvError
NvOsPageLockTraced(void *ptr, size_t size, NvU32 protect, NvOsPageAllocHandle* descriptor,
    const char *f, int l )
{
    NvError status;
    status = (NvOsPageLock)(ptr, size, protect, descriptor);
    NVOS_TRACE_LOG_PRINTF(("NvOsPageLock, %s, %d, %ums, 0x%x, %d, 0x%x, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(ptr), size, protect, (NvU32)*descriptor));
    return status;
}

static NV_INLINE void
NvOsPageFreeTraced(NvOsPageAllocHandle descriptor, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsPageFree, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(descriptor)));
    (NvOsPageFree)(descriptor);
}

static NV_INLINE NvError
NvOsPageMapTraced(NvOsPageAllocHandle descriptor, size_t offset, size_t size,
    void **ptr, const char *f, int l )
{
    NvError status;
    status = (NvOsPageMap)(descriptor, offset, size, ptr);
    NVOS_TRACE_LOG_PRINTF(("NvOsPageMap, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*ptr)));
    return status;
}

static NV_INLINE NvError
NvOsPageMapIntoPtrTraced( NvOsPageAllocHandle descriptor, void *pCallerPtr,
    size_t offset, size_t size, const char *f, int l )
{
    NvError status;
    status = (NvOsPageMapIntoPtr)(descriptor, pCallerPtr, offset, size);
    NVOS_TRACE_LOG_PRINTF(("NvOsPageMapIntoCaller, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(pCallerPtr)));
    return status;
}

static NV_INLINE void
NvOsPageUnmapTraced(NvOsPageAllocHandle descriptor, void *ptr, size_t size,
    const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsPageUnmap, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(ptr)));
    (NvOsPageUnmap)(descriptor, ptr, size);
}

static NV_INLINE NvOsPhysAddr
NvOsPageAddressTraced(NvOsPageAllocHandle descriptor, size_t offset,
    const char *f, int l )
{
    NvOsPhysAddr PhysAddr;
    PhysAddr = (NvOsPageAddress)(descriptor, offset);
    NVOS_TRACE_LOG_PRINTF(("NvOsPageAddress, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(PhysAddr)));
    return PhysAddr;
}

static NV_INLINE NvError
NvOsMutexCreateTraced(NvOsMutexHandle *mutex, const char *f, int l )
{
    NvError status;
    status = (NvOsMutexCreate)(mutex);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*mutex, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsMutexCreate, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*mutex)));
    return status;
}

static NV_INLINE void
NvOsMutexLockTraced(NvOsMutexHandle mutex, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsMutexLock, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)mutex));
    (NvOsMutexLock)(mutex);
}

static NV_INLINE void
NvOsMutexUnlockTraced(NvOsMutexHandle mutex, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsMutexUnlock, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)mutex));
    (NvOsMutexUnlock)(mutex);
}

static NV_INLINE void NvOsMutexDestroyTraced(
                            NvOsMutexHandle mutex,
                            const char *f,
                            int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsMutexDestroy, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)mutex));
    (NvOsMutexDestroy)(mutex);
}

static NV_INLINE NvError
NvOsIntrMutexCreateTraced(NvOsIntrMutexHandle *mutex, const char *f, int l )
{
    NvError status;
    status = (NvOsIntrMutexCreate)(mutex);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*mutex, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsIntrMutexCreate, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*mutex)));
    return status;
}

static NV_INLINE void
NvOsIntrMutexLockTraced(NvOsIntrMutexHandle mutex, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsIntrMutexLock, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)mutex));
    (NvOsIntrMutexLock)(mutex);
}

static NV_INLINE void
NvOsIntrMutexUnlockTraced(NvOsIntrMutexHandle mutex, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsIntrMutexUnlock, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)mutex));
    (NvOsIntrMutexUnlock)(mutex);
}

static NV_INLINE void
NvOsIntrMutexDestroyTraced(NvOsIntrMutexHandle mutex, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsIntrMutexDestroy, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)mutex));
    (NvOsIntrMutexDestroy)(mutex);
}

static NV_INLINE NvError
NvOsSemaphoreCreateTraced( NvOsSemaphoreHandle *semaphore,  NvU32 value,
    const char *f, int l )
{
    NvError status;
    status = (NvOsSemaphoreCreate)(semaphore, value);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*semaphore, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreCreate, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*semaphore)));
    return status;
}

static NV_INLINE NvError
NvOsSemaphoreCloneTraced( NvOsSemaphoreHandle orig, NvOsSemaphoreHandle *clone,
    const char *f, int l )
{
    NvError status;
    status = (NvOsSemaphoreClone)(orig, clone);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*clone, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreClone, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*clone)));
    return status;
}

static NV_INLINE NvError
NvOsSemaphoreUnmarshalTraced( NvOsSemaphoreHandle hClientSema,
    NvOsSemaphoreHandle *phDriverSema, const char *f, int l )
{
    NvError status;
    status = (NvOsSemaphoreUnmarshal)(hClientSema, phDriverSema);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*phDriverSema, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreUnmarshal, %s, %d, %ums, 0x%x\r\n",
        f, l, NvOsGetTimeMS(), (NvU32)(hClientSema)));
    return status;
}

static NV_INLINE void
NvOsSemaphoreWaitTraced( NvOsSemaphoreHandle semaphore, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreWait, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)semaphore));
    (NvOsSemaphoreWait)(semaphore);
}

static NV_INLINE NvError
NvOsSemaphoreWaitTimeoutTraced( NvOsSemaphoreHandle semaphore, NvU32 msec,
    const char *f, int l )
{
    NvError status;
    NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreWaitTimeout, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)semaphore));
    status = (NvOsSemaphoreWaitTimeout)(semaphore, msec);
    return status;
}

static NV_INLINE void
NvOsSemaphoreSignalTraced( NvOsSemaphoreHandle semaphore, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreSignal, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)semaphore));
    (NvOsSemaphoreSignal)(semaphore);
}

static NV_INLINE void
NvOsSemaphoreDestroyTraced( NvOsSemaphoreHandle semaphore, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreDestory, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)semaphore));
    (NvOsSemaphoreDestroy)(semaphore);
}

static NV_INLINE NvError
NvOsThreadCreateTraced( NvOsThreadFunction function, void *args,
    NvOsThreadHandle *thread, const char *f, int l )
{
    NvError status;
    status = (NvOsThreadCreate)(function, args, thread);
    if (status == NvSuccess)
        NvOsSetResourceAllocFileLine(*thread, f, l);
    NVOS_TRACE_LOG_PRINTF(("NvOsThreadCreate, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(*thread)));
    return status;
}

static NV_INLINE void
NvOsThreadJoinTraced( NvOsThreadHandle thread, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsThreadJoin, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)thread));
    (NvOsThreadJoin)(thread);
}

static NV_INLINE void
NvOsThreadYieldTraced(const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsThreadYield, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)0));
    (NvOsThreadYield)();
}

static NV_INLINE NvError
NvOsInterruptRegisterTraced(NvU32 IrqListSize, const NvU32 *pIrqList,
    const NvOsInterruptHandler *pIrqHandlerList, void *context,
    NvOsInterruptHandle *handle, NvBool InterruptEnable, const char *f, int l )
{
    NvError status;
    status = (NvOsInterruptRegister)(IrqListSize, pIrqList, pIrqHandlerList,
        context, handle, InterruptEnable);
    NVOS_TRACE_LOG_PRINTF(("NvOsInterruptRegister, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(handle)));
    return status;
}

static NV_INLINE void
NvOsInterruptUnregisterTraced(NvOsInterruptHandle handle, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsInterruptUnregister, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(handle)));
    (NvOsInterruptUnregister)(handle);
}

static NV_INLINE NvError
NvOsInterruptEnableTraced(NvOsInterruptHandle handle, const char *f, int l )
{
    NvError status;

    status = (NvOsInterruptEnable)(handle);
    NVOS_TRACE_LOG_PRINTF(("NvOsInterruptRegister, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(handle)));
    return status;
}

static NV_INLINE void
NvOsInterruptDoneTraced(NvOsInterruptHandle handle, const char *f, int l )
{
    NVOS_TRACE_LOG_PRINTF(("NvOsInterruptDone, %s, %d, %ums, 0x%x\n",
        f, l, NvOsGetTimeMS(), (NvU32)(handle)));
    (NvOsInterruptDone)(handle);
}

#define NvOsExecAlloc(size) NvOsExecAllocTraced(size, __FILE__, __LINE__)
#define NvOsExecFree(ptr, size) \
    NvOsExecFreeTraced(ptr, size, __FILE__, __LINE__)
#define NvOsSharedMemAlloc(key, size, descriptor) \
    NvOsSharedMemAllocTraced(key, size, descriptor, __FILE__, __LINE__)
#define NvOsSharedMemMap(descriptor, offset, size, ptr) \
    NvOsSharedMemMapTraced(descriptor, offset, size, ptr, __FILE__, __LINE__)
#define NvOsSharedMemUnmap(ptr, size) \
    NvOsSharedMemUnmapTraced(ptr, size, __FILE__, __LINE__)
#define NvOsSharedMemFree(descriptor) \
    NvOsSharedMemFreeTraced(descriptor, __FILE__, __LINE__)
#define NvOsPhysicalMemMap(phys, size, attrib, flags, ptr)   \
    NvOsPhysicalMemMapTraced(phys, size, attrib, flags, ptr, \
            __FILE__, __LINE__)
#define NvOsPhysicalMemMapIntoCaller(pCallerPtr, phys, size, attrib, flags) \
    NvOsPhysicalMemMapIntoCallerTraced(pCallerPtr, phys, size, attrib, flags, \
            __FILE__, __LINE__)
#define NvOsPhysicalMemUnmap(ptr, size)   \
    NvOsPhysicalMemUnmapTraced(ptr, size, __FILE__, __LINE__)
#define NvOsPageAlloc(size, attrib, flags, protect, descriptor)   \
    NvOsPageAllocTraced(size, attrib, flags, protect, descriptor, \
            __FILE__, __LINE__)
#define NvOsPageFree(descriptor) \
    NvOsPageFreeTraced(descriptor, __FILE__, __LINE__)
#define NvOsPageMap(descriptor, offset, size, ptr)   \
    NvOsPageMapTraced(descriptor, offset, size, ptr, __FILE__, __LINE__)
#define NvOsPageMapIntoPtr(descriptor, pCallerPtr, offset, size)   \
    NvOsPageMapIntoPtrTraced(descriptor, pCallerPtr, offset, size, \
            __FILE__, __LINE__)
#define NvOsPageUnmap(descriptor, ptr, size) \
    NvOsPageUnmapTraced(descriptor, ptr, size, __FILE__, __LINE__)
#define NvOsPageAddress(descriptor, offset)   \
    NvOsPageAddressTraced(descriptor, offset, __FILE__, __LINE__)
#define NvOsMutexCreate(mutex) NvOsMutexCreateTraced(mutex, __FILE__, __LINE__)
#define NvOsMutexLock(mutex) NvOsMutexLockTraced(mutex, __FILE__, __LINE__)
#define NvOsMutexUnlock(mutex) NvOsMutexUnlockTraced(mutex, __FILE__, __LINE__)
#define NvOsMutexDestroy(mutex) \
    NvOsMutexDestroyTraced(mutex, __FILE__, __LINE__)
#define NvOsIntrMutexCreate(mutex) \
    NvOsIntrMutexCreateTraced(mutex, __FILE__, __LINE__)
#define NvOsIntrMutexLock(mutex) \
    NvOsIntrMutexLockTraced(mutex, __FILE__, __LINE__)
#define NvOsIntrMutexUnlock(mutex) \
    NvOsIntrMutexUnlockTraced(mutex, __FILE__, __LINE__)
#define NvOsIntrMutexDestroy(mutex) \
    NvOsIntrMutexDestroyTraced(mutex, __FILE__, __LINE__)
#define NvOsSemaphoreCreate(semaphore, value)   \
    NvOsSemaphoreCreateTraced(semaphore, value, __FILE__, __LINE__)
#define NvOsSemaphoreClone(orig, semaphore)   \
    NvOsSemaphoreCloneTraced(orig, semaphore, __FILE__, __LINE__)
#define NvOsSemaphoreUnmarshal(hClientSema, phDriverSema)   \
    NvOsSemaphoreUnmarshalTraced(hClientSema, phDriverSema, __FILE__, __LINE__)
/*
#define NvOsSemaphoreWait(semaphore)   \
    NvOsSemaphoreWaitTraced(semaphore, __FILE__, __LINE__)
#define NvOsSemaphoreWaitTimeout(semaphore, msec)   \
    NvOsSemaphoreWaitTimeoutTraced(semaphore, msec, __FILE__, __LINE__)
*/
#define NvOsSemaphoreSignal(semaphore)   \
    NvOsSemaphoreSignalTraced(semaphore, __FILE__, __LINE__)
#define NvOsSemaphoreDestroy(semaphore)   \
    NvOsSemaphoreDestroyTraced(semaphore, __FILE__, __LINE__)
#define NvOsThreadCreate(func, args, thread)    \
    NvOsThreadCreateTraced(func, args, thread, __FILE__, __LINE__)
#define NvOsThreadJoin(thread)  \
    NvOsThreadJoinTraced(thread, __FILE__, __LINE__)
#define NvOsThreadYield() NvOsThreadYieldTraced(__FILE__, __LINE__)
#define NvOsInterruptRegister(IrqListSize, pIrqList, pIrqHandlerList, \
        context, handle, InterruptEnable) \
    NvOsInterruptRegisterTraced(IrqListSize, pIrqList, pIrqHandlerList, \
        context, handle, InterruptEnable, __FILE__, __LINE__)
#define NvOsInterruptUnregister(handle) \
    NvOsInterruptUnregisterTraced(handle, __FILE__, __LINE__)
#define NvOsInterruptEnable(handle) \
    NvOsInterruptEnableTraced(handle, __FILE__, __LINE__)
#define NvOsInterruptDone(handle) \
    NvOsInterruptDoneTraced(handle, __FILE__, __LINE__)

#endif // NVOS_TRACE

// Forward declare resource tracking struct.
typedef struct NvCallstackRec     NvCallstack;

typedef enum
{
    NvOsCallstackType_NoStack = 1,
    NvOsCallstackType_HexStack,
    NvOsCallstackType_SymbolStack,
    
    NvOsCallstackType_Last,
    NvOsCallstackType_Force32 = 0x7FFFFFFF
} NvOsCallstackType;

typedef void (*NvOsDumpCallback)(void* context, const char* line);

void NvOsDumpToDebugPrintf(void* context, const char* line);
void NvOsGetProcessInfo(char* buf, NvU32 len);

/* implemented by the OS-backend, for now CE and Linux only */
#if (NVOS_IS_WINDOWS_CE || NVOS_IS_LINUX)
NvCallstack* NvOsCreateCallstack      (NvOsCallstackType stackType);
void         NvOsGetStackFrame        (char* buf, NvU32 len, NvCallstack* stack, NvU32 level);
void         NvOsDestroyCallstack     (NvCallstack* callstack);
NvU32        NvOsHashCallstack        (NvCallstack* stack);
void         NvOsDumpCallstack        (NvCallstack* stack, NvU32 skip, NvOsDumpCallback callBack, void* context);
NvBool       NvOsCallstackContainsPid (NvCallstack* stack, NvU32 pid);
NvU32        NvOsCallstackGetNumLevels(NvCallstack* stack);
#else // (NVOS_IS_WINDOWS_CE || NVOS_IS_LINUX)
static NV_INLINE NvCallstack* NvOsCreateCallstack (NvOsCallstackType stackType) { return NULL; }
static NV_INLINE void NvOsGetStackFrame           (char* buf, NvU32 len, NvCallstack* stack, NvU32 level) { NvOsStrncpy(buf, "<stack>", len); }
static NV_INLINE void NvOsDestroyCallstack        (NvCallstack* callstack) { }
static NV_INLINE NvU32 NvOsHashCallstack          (NvCallstack* stack) { return 0; }
static NV_INLINE void NvOsDumpCallstack           (NvCallstack* stack, NvU32 skip, NvOsDumpCallback callBack, void* context) { }
static NvBool NV_INLINE NvOsCallstackContainsPid  (NvCallstack* stack, NvU32 pid) { return NV_FALSE; }
static NV_INLINE NvU32 NvOsCallstackGetNumLevels  (NvCallstack* stack) { return 0; }
#endif // (NVOS_IS_WINDOWS_CE || NVOS_IS_LINUX)

/*@}*/
/** @} */

#if defined(__cplusplus)
}
#endif

#endif // INCLUDED_NVOS_H