Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: arch/arm/mach-tegra/nv/include/nvos.h

Issue 3256004: [ARM] tegra: add nvos/nvrm/nvmap drivers (Closed) Base URL: ssh://git@gitrw.chromium.org/kernel.git
Patch Set: remove ap15 headers Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2006-2009 NVIDIA Corporation.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * Neither the name of the NVIDIA Corporation nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33 /**
34 * @file
35 * <b> NVIDIA Operating System Abstraction</b>
36 *
37 * @b Description: Provides interfaces that enable unification of code
38 * across all supported operating systems.
39 */
40
41
42 #ifndef INCLUDED_NVOS_H
43 #define INCLUDED_NVOS_H
44
45 /**
46 * @defgroup nvos_group NvOS - NVIDIA Operating System Abstraction
47 *
48 * This provides a basic set of interfaces to unify code
49 * across all supported operating systems. This layer does @b not
50 * handle any hardware specific functions, such as interrupts.
51 * "Platform" setup and GPU access are done by other layers.
52 *
53 * @warning Drivers and applications should @b not make any operating system
54 * calls outside of this layer, @b including stdlib functions. Doing so will
55 * result in non-portable code.
56 *
57 * For APIs that take key parameters, keys may be of ::NVOS_KEY_MAX length.
58 * Any characters beyond this maximum is ignored.
59 *
60 * All strings passed to or from NvOS functions are encoded in UTF-8. For
61 * character values below 128, this is the same as simple ASCII. For more
62 * information, see:
63 * <a href="http://en.wikipedia.org/wiki/UTF-8"
64 * target="_blank">http://en.wikipedia.org/wiki/UTF-8</a>
65 *
66 *
67 * @par Important:
68 *
69 * At interrupt time there are only a handful of NvOS functions that are safe
70 * to call:
71 * - ::NvOsSemaphoreSignal
72 * - ::NvOsIntrMutexLock
73 * - ::NvOsIntrMutexUnlock
74 * - ::NvOsWaitUS
75 *
76 * @note Curerntly, ::NvOsWaitUS for ISR has @b only been implemented for AOS an d
77 * WinCE. Use with caution.
78 *
79 * @{
80 */
81
82 #include <stdarg.h>
83 #include "nvcommon.h"
84 #include "nverror.h"
85 #include "nvos_trace.h"
86
87 #if defined(__cplusplus)
88 extern "C"
89 {
90 #endif
91
92 /**
93 * A physical address. Must be 64 bits for OSs that support more than 64 bits
94 * of physical addressing, not necessarily correlated to the size of a virtual
95 * address.
96 *
97 * Currently, 64-bit physical addressing is supported by NvOS on WinNT only.
98 *
99 * XXX 64-bit phys addressing really should be supported on Linux/x86, since
100 * all modern x86 CPUs have 36-bit (or more) physical addressing. We might
101 * need to control a PCI card that the SBIOS has placed at an address above
102 * 4 GB.
103 */
104 #if NVOS_IS_WINDOWS && !NVOS_IS_WINDOWS_CE
105 typedef NvU64 NvOsPhysAddr;
106 #else
107 typedef NvU32 NvOsPhysAddr;
108 #endif
109
110 /** The maximum length of a shared resource identifier string.
111 */
112 #define NVOS_KEY_MAX 128
113
114 /** The maximum length for a file system path.
115 */
116 #define NVOS_PATH_MAX 256
117
118 /** @name Print Operations
119 */
120 /*@{*/
121
122 /** Printf family. */
123 typedef struct NvOsFileRec *NvOsFileHandle;
124
125 /** Prints a string to a file stream.
126 *
127 * @param stream The file stream to which to print.
128 * @param format The format string.
129 */
130 NvError
131 NvOsFprintf(NvOsFileHandle stream, const char *format, ...);
132
133 // Doxygen requires escaping backslash characters (\) with another \ so in
134 // @return, ignore the first backslash if you are reading this in the header.
135 /** Expands a string into a given string buffer.
136 *
137 * @param str A pointer to the target string buffer.
138 * @param size The size of the string buffer.
139 * @param format A pointer to the format string.
140 *
141 * @return The number of characters printed (not including the \\0).
142 * The buffer was printed to successfully if the returned value is
143 * greater than -1 and less than \a size.
144 */
145 NvS32
146 NvOsSnprintf(char *str, size_t size, const char *format, ...);
147
148 /** Prints a string to a file stream using a va_list.
149 *
150 * @param stream The file stream.
151 * @param format A pointer to the format string.
152 * @param ap The va_list structure.
153 */
154 NvError
155 NvOsVfprintf(NvOsFileHandle stream, const char *format, va_list ap);
156
157 /** Expands a string into a string buffer using a va_list.
158 *
159 * @param str A pointer to the target string buffer.
160 * @param size The size of the string buffer.
161 * @param format A pointer to the format string.
162 * @param ap The va_list structure.
163 *
164 * @return The number of characters printed (not including the \\0).
165 * The buffer was printed to successfully if the returned value is
166 * greater than -1 and less than \a size.
167 */
168 NvS32
169 NvOsVsnprintf(char *str, size_t size, const char *format, va_list ap);
170
171 /**
172 * Outputs a message to the debugging console, if present. All device driver
173 * debug printfs should use this. Do not use this for interacting with a user
174 * from an application; in that case, use NvTestPrintf() instead.
175 *
176 * @param format A pointer to the format string.
177 */
178 void
179 NvOsDebugPrintf(const char *format, ...);
180
181 /**
182 * Same as ::NvOsDebugPrintf, except takes a va_list.
183 */
184 void
185 NvOsDebugVprintf( const char *format, va_list ap );
186
187 /**
188 * Same as ::NvOsDebugPrintf, except returns the number of chars written.
189 *
190 * @return number of chars written or -1 if that number is unavailable
191 */
192 NvS32
193 NvOsDebugNprintf( const char *format, ...);
194
195 /**
196 * Prints an error and the line it appeared on.
197 * Does nothing if err==NvSuccess
198 *
199 * @param err - the error to return
200 * @param file - file the error occurred in.
201 * @param line - line number the error occurred on.
202 * @returns err
203 */
204 NvError
205 NvOsShowError(NvError err, const char *file, int line);
206
207 // Doxygen requires escaping # with a backslash, so in the examples below
208 // ignore the backslash before the # if reading this in the header file.
209 /**
210 * Helper macro to go along with ::NvOsDebugPrintf. Usage:
211 * <pre>
212 * NV_DEBUG_PRINTF(("foo: %s\n", bar));
213 </pre>
214 *
215 * The debug print will be disabled by default in all builds, debug and
216 * release. @note Usage requires double parentheses.
217 *
218 * To enable debug prints in a particular .c file, add the following
219 * to the top of the .c file and rebuild:
220 * <pre>
221 * \#define NV_ENABLE_DEBUG_PRINTS 1
222 </pre>
223 *
224 * To enable debug prints in a particular module, add the following
225 * to the makefile and rebuild:
226 * <pre>
227 * LCDEFS += -DNV_ENABLE_DEBUG_PRINTS=1
228 </pre>
229 *
230 */
231 #if !defined(NV_ENABLE_DEBUG_PRINTS)
232 #define NV_ENABLE_DEBUG_PRINTS 0
233 #endif
234 #if NV_ENABLE_DEBUG_PRINTS
235 // put the print in an if statement so that the compiler will always parse it
236 #define NV_DEBUG_PRINTF(x) \
237 do { if (NV_ENABLE_DEBUG_PRINTS) { NvOsDebugPrintf x ; } } while (0)
238 #else
239 #define NV_DEBUG_PRINTF(x) do {} while (0)
240 #endif
241
242 /*@}*/
243 /** @name OS Version
244 */
245 /*@{*/
246
247 typedef enum
248 {
249 NvOsOs_Unknown,
250 NvOsOs_Windows,
251 NvOsOs_Linux,
252 NvOsOs_Aos,
253 NvOsOs_Force32 = 0x7fffffffUL,
254 } NvOsOs;
255
256 typedef enum
257 {
258 NvOsSku_Unknown,
259 NvOsSku_CeBase,
260 NvOsSku_Mobile_SmartFon,
261 NvOsSku_Mobile_PocketPC,
262 NvOsSku_Android,
263 NvOsSku_Force32 = 0x7fffffffUL,
264 } NvOsSku;
265
266 typedef struct NvOsOsInfoRec
267 {
268 NvOsOs OsType;
269 NvOsSku Sku;
270 NvU16 MajorVersion;
271 NvU16 MinorVersion;
272 NvU32 SubVersion;
273 NvU32 Caps;
274 } NvOsOsInfo;
275
276 /**
277 * Gets the current OS version.
278 *
279 * @param pOsInfo A pointer to the operating system information structure.
280 */
281 NvError
282 NvOsGetOsInformation(NvOsOsInfo *pOsInfo);
283
284 /*@}*/
285
286 /** @name Resources
287 */
288 /*@{*/
289
290 /** An opaque resource handle.
291 */
292 typedef struct NvOsResourceRec *NvOsResourceHandle;
293
294 typedef enum
295 {
296 NvOsResource_Unknown,
297 NvOsResource_Storage,
298 NvOsResource_Force32 = 0x7fffffffUL,
299 } NvOsResource;
300
301 #define NVOS_DEV_NAME_MAX 16
302
303 typedef struct NvOsResourceStorageRec
304 {
305 /// The storage device name.
306 NvU8 DeviceName[2*NVOS_DEV_NAME_MAX];
307 /// The mount point for this storage device.
308 NvU8 MountPoint[NVOS_PATH_MAX];
309 /// The free bytes available within the current context.
310 NvU64 FreeBytesAvailable;
311 /// The total bytes available within the current context (used + free).
312 NvU64 TotalBytes;
313 /// The total free bytes available on disk.
314 NvU64 TotalFreeBytes;
315 } NvOsResourceStorage;
316
317 /**
318 * Obtain a list of resources of the specified type.
319 *
320 * This function is used to aquire a NvOsResourceHandle (may be
321 * more than one) for a designated resource type. The returned
322 * handle list is used to retrieve specific details about the
323 * resource by calling NvOsResouceInfo.
324 *
325 * This function may also be used to obtain just the number of
326 * resources (nResources) if ResourceList is specified as NULL
327 * by the caller.
328 *
329 * If ResourceList is not NULL, this function returns the number
330 * of resources (nResources) and a pointer to the first resource
331 * in the array (ResourceList).
332 *
333 * @see NvOsResouceInfo()
334 *
335 * @param ResourceType The resource type for which to retrieve a handle.
336 * @param nResources The number of resources in the list.
337 * @param ResourceList Points to the first resource handle in the list.
338 * If this parameter is NULL, only nResources is returned.
339 */
340 NvError
341 NvOsListResources(
342 NvOsResource ResourceType,
343 NvU32 *nResources,
344 NvOsResourceHandle *ResourceList);
345
346 /**
347 * Gets the resource-specific data for a given
348 * NvOsResourceHandle. For example, this might include a data
349 * structure which indicates the amount of free space on a
350 * particular storage media.
351 *
352 * @see NvOsListResources()
353 * @see NvOsResourceStorage
354 *
355 * @param hResource The handle for the resource.
356 * @param InfoSize The size of the resource structure (Info).
357 * @param Info Points to a specific resource information structure.
358 *
359 * @retval "NvSuccess" if resource information is valid.
360 * @retval "NvError_FileOperationFailed" if resource info not found.
361 */
362 NvError
363 NvOsResourceInfo(
364 NvOsResourceHandle hResource,
365 NvU32 InfoSize,
366 void *Info);
367
368 /*@}*/
369
370 /** @name String Operations
371 */
372 /*@{*/
373
374 /** Copies a string.
375 *
376 * @param dest A pointer to the destination of the copy.
377 * @param src A pointer to the source string.
378 * @param size The length of the \a dest string buffer plus NULL terminator.
379 */
380 void
381 NvOsStrncpy(char *dest, const char *src, size_t size);
382
383 /** Defines straight-forward mappings to international language encodings.
384 * Commonly-used encodings on supported operating systems are provided.
385 * @note NvOS string (and file/directory name) processing functions expect
386 * UTF-8 encodings. If the system-default encoding is not UTF-8,
387 * conversion may be required. @see NvUStrConvertCodePage.
388 *
389 **/
390 typedef enum
391 {
392 NvOsCodePage_Unknown,
393 NvOsCodePage_Utf8,
394 NvOsCodePage_Utf16,
395 NvOsCodePage_Windows1252,
396 NvOsCodePage_Force32 = 0x7fffffffUL,
397 } NvOsCodePage;
398
399 /** @return The default code page for the system.
400 *
401 */
402 NvOsCodePage
403 NvOsStrGetSystemCodePage(void);
404
405 /** Gets the length of a string.
406 *
407 * @param s A pointer to the string.
408 */
409 size_t
410 NvOsStrlen(const char *s);
411
412 /** Compares two strings.
413 *
414 * @param s1 A pointer to the first string.
415 * @param s2 A pointer to the second string.
416 *
417 * @return 0 if the strings are identical.
418 */
419 int
420 NvOsStrcmp(const char *s1, const char *s2);
421
422 /** Compares two strings up to the given length.
423 *
424 * @param s1 A pointer to the first string.
425 * @param s2 A pointer to the second string.
426 * @param size The length to compare.
427 *
428 * @return 0 if the strings are identical.
429 */
430 int
431 NvOsStrncmp(const char *s1, const char *s2, size_t size);
432
433 /*@}*/
434 /** @name Memory Operations (Basic)
435 */
436 /*@{*/
437
438 /** Copies memory.
439 *
440 * @param dest A pointer to the destination of the copy.
441 * @param src A pointer to the source memory.
442 * @param size The length of the copy.
443 */
444 void NvOsMemcpy(void *dest, const void *src, size_t size);
445
446 /** Compares two memory regions.
447 *
448 * @param s1 A pointer to the first memory region.
449 * @param s2 A pointer to the second memory region.
450 * @param size The length to compare.
451 *
452 * This returns 0 if the memory regions are identical
453 */
454 int
455 NvOsMemcmp(const void *s1, const void *s2, size_t size);
456
457 /** Sets a region of memory to a value.
458 *
459 * @param s A pointer to the memory region.
460 * @param c The value to set.
461 * @param size The length of the region.
462 */
463 void
464 NvOsMemset(void *s, NvU8 c, size_t size);
465
466 /** Moves memory to a new location (may overlap).
467 *
468 * @param dest A pointer to the destination memory region.
469 * @param src A pointer to the source region.
470 * @param size The size of the region to move.
471 */
472 void
473 NvOsMemmove(void *dest, const void *src, size_t size);
474
475 /**
476 * Like NvOsMemcpy(), but used to safely copy data from an application pointer
477 * (usually embedded inside an \c ioctl() struct) into a driver pointer. Does no t
478 * make any assumptions about whether the application pointer is valid--will
479 * return an error instead of crashing if it isn't. Must also validate that
480 * the application pointer points to memory that the application owns; for
481 * example, it should point to the user mode region of the address space and
482 * not the kernel mode region, if such a distinction exists.
483 *
484 * @see NvOsCopyOut
485 *
486 * @param pDst A pointer to the destination (driver).
487 * @param pSrc A pointer to the source (client/application).
488 * @param Bytes The number of bytes to copy.
489 */
490 NvError
491 NvOsCopyIn(
492 void *pDst,
493 const void *pSrc,
494 size_t Bytes);
495
496 /**
497 * Like NvOsMemcpy(), but used to safely copy data to an application pointer
498 * (usually embedded inside an \c ioctl() struct) from a driver pointer. Does no t
499 * make any assumptions about whether the application pointer is valid--will
500 * return an error instead of crashing if it isn't. Must also validate that
501 * the application pointer points to memory that the application owns; for
502 * example, it should point to the user mode region of the address space and
503 * not the kernel mode region, if such a distinction exists.
504 *
505 * @see NvOsCopyIn
506 *
507 * @param pDst A pointer to the destination (client/application).
508 * @param pSrc A pointer to the source (driver).
509 * @param Bytes The number of bytes to copy.
510 */
511 NvError
512 NvOsCopyOut(
513 void *pDst,
514 const void *pSrc,
515 size_t Bytes);
516
517 /*@}*/
518 /** @name File Input/Output
519 */
520 /*@{*/
521
522 /**
523 *
524 * Defines wrappers over stdlib's file stream functions,
525 * with some changes to the API.
526 */
527 typedef enum
528 {
529 /** See the fseek manual page for details of Set, Cur, and End. */
530 NvOsSeek_Set = 0,
531 NvOsSeek_Cur = 1,
532 NvOsSeek_End = 2,
533
534 NvOsSeek_Force32 = 0x7FFFFFFF
535 } NvOsSeekEnum;
536
537 typedef enum
538 {
539 NvOsFileType_Unknown = 0,
540 NvOsFileType_File,
541 NvOsFileType_Directory,
542 NvOsFileType_Fifo,
543 NvOsFileType_CharacterDevice,
544 NvOsFileType_BlockDevice,
545
546 NvOsFileType_Force32 = 0x7FFFFFFF
547 } NvOsFileType;
548
549 typedef struct NvOsStatTypeRec
550 {
551 NvU64 size;
552 NvOsFileType type;
553 } NvOsStatType;
554
555 /** Opens a file with read permissions. */
556 #define NVOS_OPEN_READ 0x1
557
558 /** Opens a file with write persmissions. */
559 #define NVOS_OPEN_WRITE 0x2
560
561 /** Creates a file if is not present on the file system. */
562 #define NVOS_OPEN_CREATE 0x4
563
564 /** Opens a file stream.
565 *
566 * If the ::NVOS_OPEN_CREATE flag is specified, ::NVOS_OPEN_WRITE must also
567 * be specified.
568 *
569 * If \c NVOS_OPEN_WRITE is specified, the file will be opened for write and
570 * will be truncated if it was previously existing.
571 *
572 * If \c NVOS_OPEN_WRITE and ::NVOS_OPEN_READ are specified, the file will not
573 * be truncated.
574 *
575 * @param path A pointer to the path to the file.
576 * @param flags Or'd flags for the open operation (\c NVOS_OPEN_*).
577 * @param [out] file A pointer to the file that will be opened, if successful.
578 */
579 NvError
580 NvOsFopen(const char *path, NvU32 flags, NvOsFileHandle *file);
581
582 /** Closes a file stream.
583 *
584 * @param stream The file stream to close.
585 * Passing in a null handle is okay.
586 */
587 void NvOsFclose(NvOsFileHandle stream);
588
589 /** Writes to a file stream.
590 *
591 * @param stream The file stream.
592 * @param ptr A pointer to the data to write.
593 * @param size The length of the write.
594 *
595 * @retval NvError_FileWriteFailed Returned on error.
596 */
597 NvError
598 NvOsFwrite(NvOsFileHandle stream, const void *ptr, size_t size);
599
600 /** Reads a file stream.
601 *
602 * Buffered read implementation if available for a particular OS may
603 * return corrupted data if multiple threads read from the same
604 * stream simultaneously.
605 *
606 * To detect short reads (less that specified amount), pass in \a bytes
607 * and check its value to the expected value. The \a bytes parameter may
608 * be null.
609 *
610 * @param stream The file stream.
611 * @param ptr A pointer to the buffer for the read data.
612 * @param size The length of the read.
613 * @param [out] bytes A pointer to the number of bytes readd; may be null.
614 *
615 * @retval NvError_FileReadFailed If the file read encountered any
616 * system errors.
617 */
618 NvError
619 NvOsFread(NvOsFileHandle stream, void *ptr, size_t size, size_t *bytes);
620
621 /** Reads a file stream with timeout.
622 *
623 * Buffered read implementation if available for a particular OS may
624 * return corrupted data if multiple threads read from the same
625 * stream simultaneously.
626 *
627 * To detect short reads (less that specified amount), pass in \a bytes
628 * and check its value to the expected value. The \a bytes parameter may
629 * be null.
630 *
631 * @param stream The file stream.
632 * @param ptr A pointer to the buffer for the read data.
633 * @param size The length of the read.
634 * @param [out] bytes A pointer to the number of bytes read; may be null.
635 * @param timeout_msec Timeout for function to return if no bytes available.
636 *
637 * @retval NvError_FileReadFailed If the file read encountered any
638 * system errors.
639 * @retval NvError_Timeout If no bytes are available to read.
640 */
641 NvError
642 NvOsFreadTimeout(
643 NvOsFileHandle stream,
644 void *ptr,
645 size_t size,
646 size_t *bytes,
647 NvU32 timeout_msec);
648
649 /** Gets a character from a file stream.
650 *
651 * @param stream The file stream.
652 * @param [out] c A pointer to the character from the file stream.
653 *
654 * @retval NvError_EndOfFile When the end of file is reached.
655 */
656 NvError
657 NvOsFgetc(NvOsFileHandle stream, NvU8 *c);
658
659 /** Changes the file position pointer.
660 *
661 * @param file The file.
662 * @param offset The offset from whence to seek.
663 * @param whence The starting point for the seek.
664 *
665 * @retval NvError_FileOperationFailed On error.
666 */
667 NvError
668 NvOsFseek(NvOsFileHandle file, NvS64 offset, NvOsSeekEnum whence);
669
670 /** Gets the current file position pointer.
671 *
672 * @param file The file.
673 * @param [out] position A pointer to the file position.
674 *
675 * @retval NvError_FileOperationFailed On error.
676 */
677 NvError
678 NvOsFtell(NvOsFileHandle file, NvU64 *position);
679
680 /** Gets file information.
681 *
682 * @param filename A pointer to the file about which to get information.
683 * @param [out] stat A pointer to the information structure.
684 */
685 NvError
686 NvOsStat(const char *filename, NvOsStatType *stat);
687
688 /** Gets file information from an already open file.
689 *
690 * @param file The open file.
691 * @param [out] stat A pointer to the information structure.
692 */
693 NvError
694 NvOsFstat(NvOsFileHandle file, NvOsStatType *stat);
695
696 /** Flushes any pending writes to the file stream.
697 *
698 * @param stream The file stream.
699 */
700 NvError
701 NvOsFflush(NvOsFileHandle stream);
702
703 /** Commits any pending writes to storage media.
704 *
705 * After this completes, any pending writes are guaranteed to be on the
706 * storage media associated with the stream (if any).
707 *
708 * @param stream The file stream.
709 */
710 NvError
711 NvOsFsync(NvOsFileHandle stream);
712
713 /** Removes a file from the storage media. If the file is open,
714 * this function marks the file for deletion upon close.
715 *
716 * @param filename The file to remove
717 *
718 * The following error conditions are possible:
719 *
720 * NvError_FileOperationFailed - cannot remove file
721 */
722 NvError
723 NvOsFremove(const char *filename);
724
725 /**
726 * Thunk into the device driver implementing this file (usually a device file)
727 * to perform an I/O control (IOCTL) operation.
728 *
729 * @param hFile The file on which to perform the IOCTL operation.
730 * @param IoctlCode The IOCTL code (which operation to perform).
731 * @param pBuffer A pointer to the buffer containing the data for the IOCTL
732 * operation. This buffer must first consist of \a InBufferSize bytes of
733 * input-only data, followed by \a InOutBufferSize bytes of input/output
734 * data, and finally \a OutBufferSize bytes of output-only data. Its total
735 * size is therefore:
736 * <pre>
737 * InBufferSize + InOutBufferSize + OutBufferSize
738 </pre>
739 * @param InBufferSize The number of input-only data bytes in the buffer.
740 * @param InOutBufferSize The number of input/output data bytes in the buffer.
741 * @param OutBufferSize The number of output-only data bytes in the buffer.
742 */
743 NvError
744 NvOsIoctl(
745 NvOsFileHandle hFile,
746 NvU32 IoctlCode,
747 void *pBuffer,
748 NvU32 InBufferSize,
749 NvU32 InOutBufferSize,
750 NvU32 OutBufferSize);
751
752 /*@}*/
753 /** @name Directories
754 */
755 /*@{*/
756
757 /** A handle to a directory. */
758 typedef struct NvOsDirRec *NvOsDirHandle;
759
760 /** Opens a directory.
761 *
762 * @param path A pointer to the path of the directory to open.
763 * @param [out] dir A pointer to the directory that will be opened, if successf ul.
764 *
765 * @retval NvError_DirOperationFailed Returned upon failure.
766 */
767 NvError
768 NvOsOpendir(const char *path, NvOsDirHandle *dir);
769
770 /** Gets the next entry in the directory.
771 *
772 * @param dir The directory pointer.
773 * @param [out] name A pointer to the name of the next file.
774 * @param size The size of the name buffer.
775 *
776 * @retval NvError_EndOfDirList When there are no more entries in the
777 * directory.
778 * @retval NvError_DirOperationFailed If there is a system error.
779 */
780 NvError
781 NvOsReaddir(NvOsDirHandle dir, char *name, size_t size);
782
783 /** Closes the directory.
784 *
785 * @param dir The directory to close.
786 * Passing in a null handle is okay.
787 */
788 void NvOsClosedir(NvOsDirHandle dir);
789
790 /** Virtual filesystem hook. */
791 typedef struct NvOsFileHooksRec {
792
793 NvError (*hookFopen)(
794 const char *path,
795 NvU32 flags,
796 NvOsFileHandle *file );
797 void (*hookFclose)(
798 NvOsFileHandle stream);
799 NvError (*hookFwrite)(
800 NvOsFileHandle stream,
801 const void *ptr,
802 size_t size);
803 NvError (*hookFread)(
804 NvOsFileHandle stream,
805 void *ptr,
806 size_t size,
807 size_t *bytes,
808 NvU32 timeout_msec);
809 NvError (*hookFseek)(
810 NvOsFileHandle file,
811 NvS64 offset,
812 NvOsSeekEnum whence);
813 NvError (*hookFtell)(
814 NvOsFileHandle file,
815 NvU64 *position);
816 NvError (*hookFstat)(
817 NvOsFileHandle file,
818 NvOsStatType *stat);
819 NvError (*hookStat)(
820 const char *filename,
821 NvOsStatType *stat);
822 NvError (*hookFflush)(
823 NvOsFileHandle stream);
824 NvError (*hookFsync)(
825 NvOsFileHandle stream);
826 NvError (*hookFremove)(
827 const char *filename);
828 NvError (*hookOpendir)(
829 const char *path,
830 NvOsDirHandle *dir);
831 NvError (*hookReaddir)(
832 NvOsDirHandle dir,
833 char *name,
834 size_t size);
835 void (*hookClosedir)(
836 NvOsDirHandle dir);
837 } NvOsFileHooks;
838
839 /** Sets up hook functions for extra stream functionality.
840 *
841 * @note All function pointers must be non-NULL.
842 *
843 * @param newHooks A pointer to the new set of functions to handle file I/O.
844 * NULL for defaults.
845 */
846 const NvOsFileHooks *NvOsSetFileHooks(NvOsFileHooks *newHooks);
847
848 /* configuration variables (in place of getenv) */
849
850 /** Retrives an unsigned integer variable from the environment.
851 *
852 * @param name A pointer to the name of the variable.
853 * @param [out] value A pointer to the value to write.
854 *
855 * @retval NvError_ConfigVarNotFound If the name isn't found in the
856 * environment.
857 * @retval NvError_InvalidConfigVar If the configuration variable cannot
858 * be converted into an unsiged integer.
859 */
860 NvError
861 NvOsGetConfigU32(const char *name, NvU32 *value);
862
863 /** Retreives a string variable from the environment.
864 *
865 * @param name A pointer to the name of the variable.
866 * @param value A pointer to the value to write into.
867 * @param size The size of the value buffer.
868 *
869 * @retval NvError_ConfigVarNotFound If the name isn't found in the
870 * environment.
871 */
872 NvError
873 NvOsGetConfigString(const char *name, char *value, NvU32 size);
874
875 /*@}*/
876 /** @name Memory Allocation
877 */
878 /*@{*/
879
880 /** Dynamically allocates memory.
881 * Alignment, if desired, must be done by the caller.
882 *
883 * @param size The size of the memory to allocate.
884 */
885 void *NvOsAlloc(size_t size);
886
887 /** Re-sizes a previous dynamic allocation.
888 *
889 * @param ptr A pointer to the original allocation.
890 * @param size The new size to allocate.
891 */
892 void *NvOsRealloc(void *ptr, size_t size);
893
894 /** Frees a dynamic memory allocation.
895 *
896 * Freeing a null value is okay.
897 *
898 * @param ptr A pointer to the memory to free, which should be from
899 * NvOsAlloc().
900 */
901 void NvOsFree(void *ptr);
902
903 /**
904 * Alocates a block of executable memory.
905 *
906 * @param size The size of the memory to allocate.
907 */
908 void *NvOsExecAlloc(size_t size);
909
910 /**
911 * Frees a block of executable memory.
912 *
913 * @param ptr A pointer from NvOsExecAlloc() to the memory to free; may be null.
914 * @param size The size of the allocation.
915 */
916 void NvOsExecFree(void *ptr, size_t size);
917
918 /** An opaque handle returned by shared memory allocations.
919 */
920 typedef struct NvOsSharedMemRec *NvOsSharedMemHandle;
921
922 /** Dynamically allocates multiprocess shared memory.
923 *
924 * The memory will be zero initialized when it is first created.
925 *
926 * @param key A pointer to the global key to identify the shared allocation.
927 * @param size The size of the allocation.
928 * @param [out] descriptor A pointer to the result descriptor.
929 *
930 * @return If the shared memory for \a key already exists, then this returns
931 * the already allcoated shared memory; otherwise, it creates it.
932 */
933 NvError
934 NvOsSharedMemAlloc(const char *key, size_t size,
935 NvOsSharedMemHandle *descriptor);
936
937 /** Maps a shared memory region into the process virtual memory.
938 *
939 * @param descriptor The memory descriptor to map.
940 * @param offset The offset in bytes into the mapped area.
941 * @param size The size area to map.
942 * @param [out] ptr A pointer to the result pointer.
943 *
944 * @retval NvError_SharedMemMapFailed Returned on failure.
945 */
946 NvError
947 NvOsSharedMemMap(NvOsSharedMemHandle descriptor, size_t offset,
948 size_t size, void **ptr);
949
950 /** Unmaps a mapped region of shared memory.
951 *
952 * @param ptr A pointer to the pointer to virtual memory.
953 * @param size The size of the mapped region.
954 */
955 void NvOsSharedMemUnmap(void *ptr, size_t size);
956
957 /** Frees shared memory from NvOsSharedMemAlloc().
958 *
959 * It is valid to call \c NvOsSharedMemFree while mappings are still
960 * outstanding.
961 *
962 * @param descriptor The memory descriptor.
963 */
964 void NvOsSharedMemFree(NvOsSharedMemHandle descriptor);
965
966 /** Defines memory attributes. */
967 typedef enum
968 {
969 NvOsMemAttribute_Uncached = 0,
970 NvOsMemAttribute_WriteBack = 1,
971 NvOsMemAttribute_WriteCombined = 2,
972
973 NvOsMemAttribute_Force32 = 0x7FFFFFFF
974 } NvOsMemAttribute;
975
976 /** Specifies no memory flags. */
977 #define NVOS_MEM_NONE 0x0
978
979 /** Specifies the memory may be read. */
980 #define NVOS_MEM_READ 0x1
981
982 /** Specifies the memory may be written to. */
983 #define NVOS_MEM_WRITE 0x2
984
985 /** Specifies the memory may be executed. */
986 #define NVOS_MEM_EXECUTE 0x4
987
988 /**
989 * The memory must be visible by all processes, this is only valid for
990 * WinCE 5.0.
991 */
992 #define NVOS_MEM_GLOBAL_ADDR 0x8
993
994 /** The memory may be both read and writen. */
995 #define NVOS_MEM_READ_WRITE (NVOS_MEM_READ | NVOS_MEM_WRITE)
996
997 /** Maps computer resources into user space.
998 *
999 * @param phys The physical address start.
1000 * @param size The size of the aperture.
1001 * @param attrib Memory attributes (caching).
1002 * @param flags Bitwise OR of \c NVOS_MEM_*.
1003 * @param [out] ptr A pointer to the result pointer.
1004 */
1005 NvError
1006 NvOsPhysicalMemMap(NvOsPhysAddr phys, size_t size,
1007 NvOsMemAttribute attrib, NvU32 flags, void **ptr);
1008
1009 /** Maps computer resources into user space.
1010 *
1011 * This function is intended to be called by device drivers only,
1012 * and will fail in user space. The virtual address can be allocated
1013 * by calling NvRmOsPhysicalMemMap() with flags set to ::NVOS_MEM_NONE, which
1014 * should be done by the calling process. That virtual region will be
1015 * passed to some device driver, and this function will set up the
1016 * PTEs to make the virtual space point to the supplied physical
1017 * address.
1018 *
1019 * This is used by NvRmMemMap() to map memory under WinCE6 where user
1020 * mode applications cannot map physical memory directly.
1021 *
1022 * @param pCallerPtr A pointer to the virtual address from the calling process.
1023 * @param phys The physical address start.
1024 * @param size The size of the aperture.
1025 * @param attrib Memory attributes (caching).
1026 * @param flags Bitwise OR of NVOS_MEM_*.
1027 */
1028 NvError
1029 NvOsPhysicalMemMapIntoCaller(void *pCallerPtr, NvOsPhysAddr phys,
1030 size_t size, NvOsMemAttribute attrib, NvU32 flags);
1031
1032 /**
1033 * Releases resources previously allocated by NvOsPhysicalMemMap().
1034 *
1035 * @param ptr The virtual pointer returned by \c NvOsPhysicalMemMap. If this
1036 * pointer is null, this function has no effect.
1037 * @param size The size of the mapped region.
1038 */
1039 void NvOsPhysicalMemUnmap(void *ptr, size_t size);
1040
1041 /*@}*/
1042 /** @name Page Allocator
1043 */
1044 /*@{*/
1045
1046 /**
1047 * Low-level memory allocation of the external system memory.
1048 */
1049 typedef enum
1050 {
1051 NvOsPageFlags_Contiguous = 0,
1052 NvOsPageFlags_NonContiguous = 1,
1053
1054 NvOsMemFlags_Forceword = 0x7ffffff,
1055 } NvOsPageFlags;
1056
1057 typedef struct NvOsPageAllocRec *NvOsPageAllocHandle;
1058
1059 /** Allocates memory via the page allocator.
1060 *
1061 * @param size The number of bytes to allocate.
1062 * @param attrib Page caching attributes.
1063 * @param flags Various memory allocation flags.
1064 * @param protect Page protection attributes (\c NVOS_MEM_*).
1065 * @param [out] descriptor A pointer to the result descriptor.
1066 *
1067 * @return A descriptor (not a pointer to virtual memory),
1068 * which may be passed into other functions.
1069 */
1070 NvError
1071 NvOsPageAlloc(size_t size, NvOsMemAttribute attrib,
1072 NvOsPageFlags flags, NvU32 protect, NvOsPageAllocHandle *descriptor);
1073
1074 /**
1075 * Locks down the pages in a region of memory and provides a descriptor that can
1076 * be used to query the PTEs. Locked pages are guaranteed to not be swapped
1077 * out or moved by the OS. To unlock the pages when done, call NvOsPageFree()
1078 * on the resulting descriptor.
1079 *
1080 * @param ptr Pointer to the buffer to lock down.
1081 * @param size Number of bytes in the buffer to lock down.
1082 * @param protect Page protection attributes (NVOS_MEM_*)
1083 * @param [out] descriptor Output parameter to pass back the descriptor.
1084 *
1085 * @retval NvSuccess If successful, or the appropriate error code.
1086 * @note Some operating systems may not support this operation and will return
1087 * \a NvError_NotImplemented to all requests.
1088 */
1089 NvError
1090 NvOsPageLock(void *ptr, size_t size, NvU32 protect, NvOsPageAllocHandle *descrip tor);
1091
1092 /** Frees pages from NvOsPageAlloc().
1093 *
1094 * It is not valid to call NvOsPageFree() while there are outstanding
1095 * mappings.
1096 *
1097 * @param descriptor The descriptor from \c NvOsPageAlloc.
1098 */
1099 void
1100 NvOsPageFree(NvOsPageAllocHandle descriptor);
1101
1102 /** Maps pages into the virtual address space.
1103 *
1104 * Upon successful completion, \a *ptr holds a virtual address
1105 * that may be accessed.
1106 *
1107 * @param descriptor Allocated pages from NvOsPageAlloc(), etc.
1108 * @param offset Offset in bytes into the page range.
1109 * @param size The size of the mapping.
1110 * @param [out] ptr A pointer to the result pointer.
1111 *
1112 * @retval NvSuccess If successful, or the appropriate error code.
1113 */
1114 NvError
1115 NvOsPageMap(NvOsPageAllocHandle descriptor, size_t offset, size_t size,
1116 void **ptr);
1117
1118 /** Maps pages into the provided virtual address space.
1119 *
1120 * Virtual address space can be obtained by calling
1121 * NvOsPhysicalMemMap() and passing ::NVOS_MEM_NONE for the
1122 * flags parameter.
1123 *
1124 * @note You should only use this function if you really, really
1125 * know what you are doing(1).
1126 *
1127 * Upon successful completion, \a *ptr holds a virtual address
1128 * that may be accessed.
1129 *
1130 * @param descriptor Allocated pages from NvOsPageAlloc(), etc.
1131 * @param pCallerPtr Pointer to user supplied virtual address space.
1132 * @param offset Offset in bytes into the page range
1133 * @param size The size of the mapping
1134 *
1135 * @retval NvSuccess If successful, or the appropriate error code.
1136 */
1137 NvError
1138 NvOsPageMapIntoPtr(NvOsPageAllocHandle descriptor, void *pCallerPtr,
1139 size_t offset, size_t size);
1140
1141 /** Unmaps the virtual address from NvOsPageMap().
1142 *
1143 * @param descriptor Allocated pages from NvOsPageAlloc(), etc.
1144 * @param ptr A pointer to the virtual address to unmap that was returned
1145 * from \c NvOsPageMap.
1146 * @param size The size of the mapping, which should match what
1147 * was passed into \c NvOsPageMap.
1148 */
1149 void
1150 NvOsPageUnmap(NvOsPageAllocHandle descriptor, void *ptr, size_t size);
1151
1152 /** Returns the physical address given an offset.
1153 *
1154 * This is useful for non-contiguous page allocations.
1155 *
1156 * @param descriptor The descriptor from NvOsPageAlloc(), etc.
1157 * @param offset The offset in bytes into the page range.
1158 */
1159 NvOsPhysAddr
1160 NvOsPageAddress(NvOsPageAllocHandle descriptor, size_t offset);
1161
1162 /*@}*/
1163 /** @name Dynamic Library Handling
1164 */
1165 /*@{*/
1166
1167 /** A handle to a dynamic library. */
1168 typedef struct NvOsLibraryRec *NvOsLibraryHandle;
1169
1170 /** Load a dynamic library.
1171 *
1172 * No operating system specific suffixes or paths should be used for the
1173 * library name. So do not use:
1174 * <pre>
1175 /usr/lib/libnvos.so
1176 libnvos.dll
1177 </pre>
1178 * Just use:
1179 * <pre>
1180 libnvos
1181 </pre>
1182 *
1183 * @param name A pointer to the library name.
1184 * @param [out] library A pointer to the result library.
1185 *
1186 * @retval NvError_LibraryNotFound If the library cannot be opened.
1187 */
1188 NvError
1189 NvOsLibraryLoad(const char *name, NvOsLibraryHandle *library);
1190
1191 /** Gets an address of a symbol in a dynamic library.
1192 *
1193 * @param library The dynamic library.
1194 * @param symbol A pointer to the symbol to lookup.
1195 *
1196 * @return The address of the symbol, or NULL if the symbol cannot be found.
1197 */
1198 void*
1199 NvOsLibraryGetSymbol(NvOsLibraryHandle library, const char *symbol);
1200
1201 /** Unloads a dynamic library.
1202 *
1203 * @param library The dynamic library to unload.
1204 * It is okay to pass a null \a library value.
1205 */
1206 void
1207 NvOsLibraryUnload(NvOsLibraryHandle library);
1208
1209 /*@}*/
1210 /** @name Syncronization Objects and Thread Management
1211 */
1212 /*@{*/
1213
1214 typedef struct NvOsMutexRec *NvOsMutexHandle;
1215 typedef struct NvOsIntrMutexRec *NvOsIntrMutexHandle;
1216 typedef struct NvOsSpinMutexRec *NvOsSpinMutexHandle;
1217 typedef struct NvOsSemaphoreRec *NvOsSemaphoreHandle;
1218 typedef struct NvOsThreadRec *NvOsThreadHandle;
1219
1220 /** Unschedules the calling thread for at least the given
1221 * number of milliseconds.
1222 *
1223 * Other threads may run during the sleep time.
1224 *
1225 * @param msec The number of milliseconds to sleep.
1226 */
1227 void
1228 NvOsSleepMS(NvU32 msec);
1229
1230 /** Stalls the calling thread for at least the given number of
1231 * microseconds. The actual time waited might be longer; you cannot
1232 * depend on this function for precise timing.
1233 *
1234 * @note It is safe to use this function at ISR time.
1235 *
1236 * @param usec The number of microseconds to wait.
1237 */
1238 void
1239 NvOsWaitUS(NvU32 usec);
1240
1241 /**
1242 * Allocates a new (intra-process) mutex.
1243 *
1244 * @note Mutexes can be locked recursively; if a thread owns the lock,
1245 * it can lock it again as long as it unlocks it an equal number of times.
1246 *
1247 * @param mutex The mutex to initialize.
1248 *
1249 * @return \a NvError_MutexCreateFailed, or one of common error codes on
1250 * failure.
1251 */
1252 NvError NvOsMutexCreate(NvOsMutexHandle *mutex);
1253
1254 /** Locks the given unlocked mutex.
1255 *
1256 * If a process is holding a lock on a multi-process mutex when it terminates,
1257 * this lock will be automatically released.
1258 *
1259 * @param mutex The mutex to lock; note that this is a recursive lock.
1260 */
1261 void NvOsMutexLock(NvOsMutexHandle mutex);
1262
1263 /** Unlocks a locked mutex.
1264 *
1265 * A mutex must be unlocked exactly as many times as it has been locked.
1266 *
1267 * @param mutex The mutex to unlock.
1268 */
1269 void NvOsMutexUnlock(NvOsMutexHandle mutex);
1270
1271 /** Frees the resources held by a mutex.
1272 *
1273 * Mutecies are reference counted across the computer (multiproceses),
1274 * and a given mutex will not be destroyed until the last reference has
1275 * gone away.
1276 *
1277 * @param mutex The mutex to destroy. Passing in a null mutex is okay.
1278 */
1279 void NvOsMutexDestroy(NvOsMutexHandle mutex);
1280
1281 /**
1282 * Creates a mutex that is safe to aquire in an ISR.
1283 *
1284 * @param mutex A pointer to the mutex is stored here on success.
1285 */
1286 NvError NvOsIntrMutexCreate(NvOsIntrMutexHandle *mutex);
1287
1288 /**
1289 * Aquire an ISR-safe mutex.
1290 *
1291 * @param mutex The mutex to lock. For kernel (OAL) implementations,
1292 * NULL implies the system-wide lock will be used.
1293 */
1294 void NvOsIntrMutexLock(NvOsIntrMutexHandle mutex);
1295
1296 /**
1297 * Releases an ISR-safe mutex.
1298 *
1299 * @param mutex The mutex to unlock. For kernel (OAL) implementations,
1300 * NULL implies the system-wide lock will be used.
1301 */
1302 void NvOsIntrMutexUnlock(NvOsIntrMutexHandle mutex);
1303
1304 /**
1305 * Destroys an ISR-safe mutex.
1306 *
1307 * @param mutex The mutex to destroy. If \a mutex is NULL, this API has no
1308 * effect.
1309 */
1310 void NvOsIntrMutexDestroy(NvOsIntrMutexHandle mutex);
1311
1312 /**
1313 * Creates a spin mutex.
1314 * This mutex is SMP safe, but it is not ISR-safe.
1315 *
1316 * @param mutex A pointer to the mutex is stored here on success.
1317 */
1318 NvError NvOsSpinMutexCreate(NvOsSpinMutexHandle *mutex);
1319
1320 /**
1321 * Acquire a spin mutex.
1322 * Spins until mutex is acquired; when acquired disables kernel preemption.
1323 *
1324 * @param mutex The mutex handle to lock.
1325 */
1326 void NvOsSpinMutexLock(NvOsSpinMutexHandle mutex);
1327
1328 /**
1329 * Releases a spin mutex.
1330 *
1331 * @param mutex The mutex handle to unlock.
1332 */
1333 void NvOsSpinMutexUnlock(NvOsSpinMutexHandle mutex);
1334
1335 /**
1336 * Destroys a spin mutex.
1337 *
1338 * @param mutex The mutex to destroy. If \a mutex is NULL, this API has no
1339 * effect.
1340 */
1341 void NvOsSpinMutexDestroy(NvOsSpinMutexHandle mutex);
1342
1343 /**
1344 * Creates a counting semaphore.
1345 *
1346 * @param semaphore A pointer to the semaphore to initialize.
1347 * @param value The initial semaphore value.
1348 *
1349 * @retval NvSuccess If successful, or the appropriate error code.
1350 */
1351 NvError
1352 NvOsSemaphoreCreate(NvOsSemaphoreHandle *semaphore, NvU32 value);
1353
1354 /**
1355 * Creates a duplicate semaphore from the given semaphore.
1356 * Freeing the original semaphore has no effect on the new semaphore.
1357 *
1358 * @param orig The semaphore to duplicate.
1359 * @param semaphore A pointer to the new semaphore.
1360 *
1361 * @retval NvSuccess If successful, or the appropriate error code.
1362 */
1363 NvError
1364 NvOsSemaphoreClone( NvOsSemaphoreHandle orig, NvOsSemaphoreHandle *semaphore);
1365
1366 /**
1367 * Obtains a safe, usable handle to a semaphore passed across an ioctl()
1368 * interface by a client to a device driver. Validates that the original
1369 * semaphore handle is legal, and creates a new handle (valid in the driver's
1370 * process/address space) that the client cannot asynchronously destroy.
1371 *
1372 * The new handle must be freed, just like any other semaphore handle, by
1373 * passing it to NvOsSemaphoreDestroy().
1374 *
1375 * @param hClientSema The client's semaphore handle.
1376 * @param phDriverSema If successful, returns a new handle to the semaphore
1377 * that the driver can safely use.
1378 *
1379 * @retval NvSuccess If successful, or the appropriate error code.
1380 */
1381 NvError
1382 NvOsSemaphoreUnmarshal( NvOsSemaphoreHandle hClientSema,
1383 NvOsSemaphoreHandle *phDriverSema);
1384
1385 /** Waits until the semaphore value becomes non-zero, then
1386 * decrements the value and returns.
1387 *
1388 * @param semaphore The semaphore to wait for.
1389 */
1390 void NvOsSemaphoreWait(NvOsSemaphoreHandle semaphore);
1391
1392 /**
1393 * Waits for the given semaphore value to become non-zero with timeout. If
1394 * the semaphore value becomes non-zero before the timeout, then the value is
1395 * decremented and \a NvSuccess is returned.
1396 *
1397 * @param semaphore The semaphore to wait for.
1398 * @param msec Timeout value in milliseconds.
1399 * ::NV_WAIT_INFINITE can be used to wait forever.
1400 *
1401 * @retval NvError_Timeout If the wait expires.
1402 */
1403 NvError
1404 NvOsSemaphoreWaitTimeout(NvOsSemaphoreHandle semaphore, NvU32 msec);
1405
1406 /** Increments the semaphore value.
1407 *
1408 * @param semaphore The semaphore to signal.
1409 */
1410 void
1411 NvOsSemaphoreSignal(NvOsSemaphoreHandle semaphore);
1412
1413 /** Frees resources held by the semaphore.
1414 *
1415 * Semaphores are reference counted across the computer (multiproceses),
1416 * and a given semaphore will not be destroyed until the last reference has
1417 * gone away.
1418 *
1419 * @param semaphore The semaphore to destroy.
1420 * Passing in a null semaphore is okay (no op).
1421 */
1422 void
1423 NvOsSemaphoreDestroy(NvOsSemaphoreHandle semaphore);
1424
1425 /** Sets thread mode.
1426 *
1427 * @pre If this is called, it must be called before any other threading function .
1428 * All but the first call to this function do nothing and return
1429 * \a NvError_AlreadyAllocated.
1430 *
1431 * @param coop 0 to disable coop mode, and 1 to enable coop mode.
1432 *
1433 * @returns NvSuccess On success.
1434 * @returns NvError_AlreadyAllocated If called previously.
1435 */
1436 NvError NvOsThreadMode(int coop);
1437
1438 /** Entry point for a thread.
1439 */
1440 typedef void (*NvOsThreadFunction)(void *args);
1441
1442 /** Creates a thread.
1443 *
1444 * @param function The thread entry point.
1445 * @param args A pointer to the thread arguments.
1446 * @param [out] thread A pointer to the result thread ID structure.
1447 */
1448 NvError
1449 NvOsThreadCreate( NvOsThreadFunction function, void *args,
1450 NvOsThreadHandle *thread);
1451
1452 /** Creates a near interrupt priority thread.
1453 *
1454 * @param function The thread entry point.
1455 * @param args A pointer to the thread arguments.
1456 * @param [out] thread A pointer to the result thread ID structure.
1457 */
1458 NvError
1459 NvOsInterruptPriorityThreadCreate( NvOsThreadFunction function, void *args,
1460 NvOsThreadHandle *thread);
1461
1462 /**
1463 * Sets the thread's priority to low priority.
1464 *
1465 * @retval NvError_NotSupported May be returned.
1466 */
1467 NvError NvOsThreadSetLowPriority(void);
1468
1469 /** Waits for the given thread to exit.
1470 *
1471 * The joined thread will be destroyed automatically. All OS resources
1472 * will be reclaimed. There is no method for terminating a thread
1473 * before it exits naturally.
1474 *
1475 * @param thread The thread to wait for.
1476 * Passing in a null thread ID is okay (no op).
1477 */
1478 void NvOsThreadJoin(NvOsThreadHandle thread);
1479
1480 /** Yields to another runnable thread.
1481 */
1482 void NvOsThreadYield(void);
1483
1484 /**
1485 * Atomically compares the contents of a 32-bit memory location with a value,
1486 * and if they match, updates it to a new value. This function is the
1487 * equivalent of the following code, except that other threads or processors
1488 * are effectively prevented from reading or writing \a *pTarget while we are
1489 * inside the function.
1490 *
1491 * @code
1492 * NvS32 OldTarget = *pTarget;
1493 * if (OldTarget == OldValue)
1494 * *pTarget = NewValue;
1495 * return OldTarget;
1496 * @endcode
1497 */
1498 NvS32 NvOsAtomicCompareExchange32(NvS32 *pTarget, NvS32 OldValue, NvS32
1499 NewValue);
1500
1501 /**
1502 * Atomically swaps the contents of a 32-bit memory location with a value. This
1503 * function is the equivalent of the following code, except that other threads
1504 * or processors are effectively prevented from reading or writing \a *pTarget
1505 * while we are inside the function.
1506 *
1507 * @code
1508 * NvS32 OldTarget = *pTarget;
1509 * *pTarget = Value;
1510 * return OldTarget;
1511 * @endcode
1512 */
1513 NvS32 NvOsAtomicExchange32(NvS32 *pTarget, NvS32 Value);
1514
1515 /**
1516 * Atomically increments the contents of a 32-bit memory location by a specified
1517 * amount. This function is the equivalent of the following code, except that
1518 * other threads or processors are effectively prevented from reading or
1519 * writing \a *pTarget while we are inside the function.
1520 *
1521 * @code
1522 * NvS32 OldTarget = *pTarget;
1523 * *pTarget = OldTarget + Value;
1524 * return OldTarget;
1525 * @endcode
1526 */
1527 NvS32 NvOsAtomicExchangeAdd32(NvS32 *pTarget, NvS32 Value);
1528
1529 /** A TLS index that is guaranteed to be invalid. */
1530 #define NVOS_INVALID_TLS_INDEX 0xFFFFFFFF
1531 #define NVOS_TLS_CNT 4
1532
1533 /**
1534 * Allocates a thread-local storage variable. All TLS variables have initial
1535 * value NULL in all threads when first allocated.
1536 *
1537 * @returns The TLS index of the TLS variable if successful, or
1538 * ::NVOS_INVALID_TLS_INDEX if not.
1539 */
1540 NvU32 NvOsTlsAlloc(void);
1541
1542 /**
1543 * Frees a thread-local storage variable.
1544 *
1545 * @param TlsIndex The TLS index of the TLS variable. This function is a no-op
1546 * if TlsIndex equals ::NVOS_INVALID_TLS_INDEX.
1547 */
1548 void NvOsTlsFree(NvU32 TlsIndex);
1549
1550 /**
1551 * Gets the value of a thread-local storage variable.
1552 *
1553 * @param TlsIndex The TLS index of the TLS variable.
1554 * The current value of the TLS variable is returned.
1555 */
1556 void *NvOsTlsGet(NvU32 TlsIndex);
1557
1558 /**
1559 * Sets the value of a thread-local storage variable.
1560 *
1561 * @param TlsIndex The TLS index of the TLS variable.
1562 * @param Value A pointer to the new value of the TLS variable.
1563 */
1564 void NvOsTlsSet(NvU32 TlsIndex, void *Value);
1565
1566 /*@}*/
1567 /** @name Time Functions
1568 */
1569 /*@{*/
1570
1571 /** @return The system time in milliseconds.
1572 *
1573 * The returned values are guaranteed to be monotonically increasing,
1574 * but may wrap back to zero (after about 50 days of runtime).
1575 *
1576 * In some systems, this is the number of milliseconds since power-on,
1577 * or may actually be an accurate date.
1578 */
1579 NvU32
1580 NvOsGetTimeMS(void);
1581
1582 /** @return The system time in microseconds.
1583 *
1584 * The returned values are guaranteed to be monotonically increasing,
1585 * but may wrap back to zero.
1586 *
1587 * Some systems cannot gauantee a microsecond resolution timer.
1588 * Even though the time returned is in microseconds, it is not gaurnateed
1589 * to have micro-second resolution.
1590 *
1591 * Please be advised that this API is mainly used for code profiling and
1592 * meant to be used direclty in driver code.
1593 */
1594 NvU64
1595 NvOsGetTimeUS(void);
1596
1597 /*@}*/
1598 /** @name CPU Cache
1599 * Cache operations for both instruction and data cache, implemented
1600 * per processor.
1601 */
1602 /*@{*/
1603
1604 /** Writes back the entire data cache.
1605 */
1606 void
1607 NvOsDataCacheWriteback(void);
1608
1609 /** Writes back and invalidates the entire data cache.
1610 */
1611 void
1612 NvOsDataCacheWritebackInvalidate(void);
1613
1614 /** Writes back a range of the data cache.
1615 *
1616 * @param start A pointer to the start address.
1617 * @param length The number of bytes to write back.
1618 */
1619 void
1620 NvOsDataCacheWritebackRange(void *start, NvU32 length);
1621
1622 /** Writes back and invlidates a range of the data cache.
1623 *
1624 * @param start A pointer to the start address.
1625 * @param length The number of bytes to write back.
1626 */
1627 void
1628 NvOsDataCacheWritebackInvalidateRange(void *start, NvU32 length);
1629
1630 /** Invalidates the entire instruction cache.
1631 */
1632 void
1633 NvOsInstrCacheInvalidate(void);
1634
1635 /** Invalidates a range of the instruction cache.
1636 *
1637 * @param start A pointer to the start address.
1638 * @param length The number of bytes.
1639 */
1640 void
1641 NvOsInstrCacheInvalidateRange(void *start, NvU32 length);
1642
1643 /** Flushes the CPU's write combine buffer.
1644 */
1645 void
1646 NvOsFlushWriteCombineBuffer(void);
1647
1648 /** Interrupt handler function.
1649 */
1650 typedef void (*NvOsInterruptHandler)(void *args);
1651
1652 /** Interrupt handler type.
1653 */
1654 typedef struct NvOsInterruptRec *NvOsInterruptHandle;
1655
1656 /**
1657 * Registers the interrupt handler with the IRQ number.
1658 *
1659 * @note This function is intended to @b only be called
1660 * from NvRmInterruptRegister().
1661 *
1662 * @param IrqListSize Size of the \a IrqList passed in for registering the IRQ
1663 * handlers for each IRQ number.
1664 * @param pIrqList Array of IRQ numbers for which interupt handlers are to be
1665 * registerd.
1666 * @param pIrqHandlerList A pointer to an array of interrupt routines to be
1667 * called when an interrupt occurs.
1668 * @param context A pointer to the register's context handle.
1669 * @param handle A pointer to the interrupt handle.
1670 * @param InterruptEnable If true, immediately enable interrupt. Otherwise
1671 * enable interrupt only after calling NvOsInterruptEnable().
1672 *
1673 * @retval NvError_IrqRegistrationFailed If the interrupt is already registered.
1674 * @retval NvError_BadParameter If the IRQ number is not valid.
1675 */
1676 NvError
1677 NvOsInterruptRegister(NvU32 IrqListSize,
1678 const NvU32 *pIrqList,
1679 const NvOsInterruptHandler *pIrqHandlerList,
1680 void *context,
1681 NvOsInterruptHandle *handle,
1682 NvBool InterruptEnable);
1683
1684 /**
1685 * Unregisters the interrupt handler from the associated IRQ number.
1686 *
1687 * @note This function is intended to @b only be called
1688 * from NvRmInterruptUnregister().
1689 *
1690 * @param handle interrupt Handle returned when a successfull call is made to
1691 * NvOsInterruptRegister().
1692 */
1693 void
1694 NvOsInterruptUnregister(NvOsInterruptHandle handle);
1695
1696 /**
1697 * Enables the interrupt handler with the IRQ number.
1698 *
1699 * @note This function is intended to @b only be called
1700 * from NvOsInterruptRegister() and NvRmInterruptRegister().
1701 *
1702 * @param handle Interrupt handle returned when a successfull call is made to
1703 * \c NvOsInterruptRegister.
1704 *
1705 * @retval NvError_BadParameter If the handle is not valid.
1706 * @retval NvError_InsufficientMemory If interrupt enable failed.
1707 * @retval NvSuccess If interrupt enable is successful.
1708 */
1709 NvError
1710 NvOsInterruptEnable(NvOsInterruptHandle handle);
1711
1712 /**
1713 * Called when the ISR/IST is done handling the interrupt.
1714 *
1715 * @note This API should be called only from NvRmInterruptDone().
1716 *
1717 * @param handle Interrupt handle returned when a successfull call is made to
1718 * NvOsInterruptRegister().
1719 */
1720 void
1721 NvOsInterruptDone(NvOsInterruptHandle handle);
1722
1723 /**
1724 * Mask/unmask an interrupt.
1725 *
1726 * Drivers can use this API to fend off interrupts. Mask means no interrupts
1727 * are forwarded to the CPU. Unmask means, interrupts are forwarded to the
1728 * CPU. In case of SMP systems, this API masks the interrutps to all the CPUs,
1729 * not just the calling CPU.
1730 *
1731 * @param handle Interrupt handle returned by NvOsInterruptRegister().
1732 * @param mask NV_FALSE to forward the interrupt to CPU; NV_TRUE to
1733 * mask the interrupts to CPU.
1734 */
1735 void NvOsInterruptMask(NvOsInterruptHandle handle, NvBool mask);
1736
1737 #define NVOS_MAX_PROFILE_APERTURES (4UL)
1738
1739 /**
1740 * Profile aperture sizes.
1741 *
1742 * Code may execute and be profiled from mutliple apertures. This will get the
1743 * size of each aperture. The caller is expected to allocate the number of
1744 * bytes for each aperture into a single void* array (void**), which will be
1745 * used in NvOsProfileStart() and NvOsProfileStop().
1746 *
1747 * This may be called twice, the first time to get the number of apertures
1748 * (sizes should be null), and the second time with the sizes parameter
1749 * non-null. Alternately, ::NVOS_MAX_PROFILE_APERTURES may be used as the
1750 * size of the sizes array.
1751 *
1752 * @param apertures A pointer to the number of apertures that will be profiled.
1753 * @param sizes A pointer to the size of each aperture.
1754 */
1755 void
1756 NvOsProfileApertureSizes( NvU32 *apertures, NvU32 *sizes );
1757
1758 /**
1759 * Enables statistical profiling.
1760 *
1761 * @param apertures A pointer to an array of storage for profile data.
1762 */
1763 void
1764 NvOsProfileStart( void **apertures );
1765
1766 /**
1767 * Stops profiling and prepares the profile samples for analysis.
1768 *
1769 * @param apertures A pointer to the storage for the profile samples.
1770 */
1771 void
1772 NvOsProfileStop( void **apertures );
1773
1774 /**
1775 * Writes profile data to the given file.
1776 *
1777 * @post This is expected to close the file after a successful write.
1778 *
1779 * @param file The file to write to.
1780 * @param index The aperture number.
1781 * @param aperture A pointer to the storage for the profile samples.
1782 */
1783 NvError
1784 NvOsProfileWrite( NvOsFileHandle file, NvU32 index, void *aperture );
1785
1786 /**
1787 * Sets the boot arguments from thet system's boot loader. The data may be keyed .
1788 *
1789 * @param key The key for the argument.
1790 * @param arg A pointer to the argument to store.
1791 * @param size The size of the argument in bytes.
1792 *
1793 * @retval NvSuccess If successful, or the appropriate error code.
1794 */
1795 NvError
1796 NvOsBootArgSet( NvU32 key, void *arg, NvU32 size );
1797
1798 /**
1799 * Retrieves the system boot arguments. Requires the same key from
1800 * NvOsBootArgSet().
1801 *
1802 * @param key The key for the argument.
1803 * @param arg A pointer to the argument buffer.
1804 * @param size The size of the argument in bytes.
1805 */
1806 NvError
1807 NvOsBootArgGet( NvU32 key, void *arg, NvU32 size );
1808
1809 /*
1810 * Tracing support. Enable with NVOS_TRACE in nvos_trace.h.
1811 */
1812 #if NVOS_TRACE || NV_DEBUG
1813
1814 #if NV_DEBUG
1815 void *NvOsAllocLeak( size_t size, const char *f, int l );
1816 void *NvOsReallocLeak( void *ptr, size_t size, const char *f, int l );
1817 void NvOsFreeLeak( void *ptr, const char *f, int l );
1818 #endif
1819
1820 static NV_INLINE void *NvOsAllocTraced(size_t size, const char *f, int l)
1821 {
1822 void *ptr;
1823
1824 #if NV_DEBUG
1825 ptr = (NvOsAllocLeak)(size, f, l);
1826 #else
1827 ptr = (NvOsAlloc)(size);
1828 #endif
1829 #if NVOS_TRACE
1830 NVOS_TRACE_LOG_PRINTF(("NvOsAlloc, %s, %d, %ums, 0x%x\n",
1831 f, l, NvOsGetTimeMS(), (NvU32)ptr));
1832 #endif
1833
1834 return ptr;
1835 }
1836
1837 static NV_INLINE void *NvOsReallocTraced(void *ptr, size_t size, const char *f,
1838 int l )
1839 {
1840 void* ret;
1841
1842 #if NV_DEBUG
1843 ret = (NvOsReallocLeak)(ptr, size, f, l);
1844 #else
1845 ret = (NvOsRealloc)(ptr, size);
1846 #endif
1847 #if NVOS_TRACE
1848 NVOS_TRACE_LOG_PRINTF(("NvOsRealloc, %s, %d, %ums, 0x%x\n",
1849 f, l, NvOsGetTimeMS(), (NvU32)ret));
1850 #endif
1851
1852 return ret;
1853 }
1854
1855 static NV_INLINE void NvOsFreeTraced(void *ptr, const char *f, int l )
1856 {
1857
1858 #if NV_DEBUG
1859 (NvOsFreeLeak)(ptr, f, l);
1860 #else
1861 (NvOsFree)(ptr);
1862 #endif
1863 #if NVOS_TRACE
1864 NVOS_TRACE_LOG_PRINTF(("NvOsFree, %s, %d, %ums, 0x%x\n",
1865 f, l, NvOsGetTimeMS(), (NvU32)ptr));
1866 #endif
1867 }
1868
1869
1870 #define NvOsAlloc(size) NvOsAllocTraced(size, __FILE__, __LINE__)
1871 #define NvOsRealloc(ptr, size) \
1872 NvOsReallocTraced(ptr, size, __FILE__, __LINE__)
1873 #define NvOsFree(ptr) NvOsFreeTraced(ptr, __FILE__, __LINE__)
1874
1875 #endif /* NVOS_TRACE */
1876
1877
1878 #if (NVOS_TRACE || NV_DEBUG)
1879
1880 /**
1881 * Sets the file and line corresponding to a resource allocation.
1882 * Call will fill file and line for the most recently stored
1883 * allocation location, if not already set.
1884 *
1885 * @param userptr A pointer to used by client to identify resource.
1886 * Can be NULL, which leads to no-op.
1887 * @param file A pointer to the name of the file from which allocation
1888 * originated. Value cannot be NULL; use "" for an empty string.
1889 * @param l The line.
1890 */
1891 void NvOsSetResourceAllocFileLine(void* userptr, const char* file, int line);
1892
1893 static NV_INLINE void *
1894 NvOsExecAllocTraced(size_t size, const char *f, int l )
1895 {
1896 void* ret;
1897 ret = (NvOsExecAlloc)(size);
1898 NvOsSetResourceAllocFileLine(ret, f, l);
1899 NVOS_TRACE_LOG_PRINTF(("NvOsExecAlloc, %s, %d, %ums, 0x%x\n",
1900 f, l, NvOsGetTimeMS(), (NvU32)ret));
1901 return ret;
1902 }
1903
1904 static NV_INLINE void
1905 NvOsExecFreeTraced(void *ptr, size_t size, const char *f, int l )
1906 {
1907 NVOS_TRACE_LOG_PRINTF(("NvOsExecFree, %s, %d, %ums, 0x%x\n",
1908 f, l, NvOsGetTimeMS(), (NvU32)ptr));
1909 (NvOsExecFree)(ptr, size);
1910 }
1911
1912 static NV_INLINE NvError
1913 NvOsSharedMemAllocTraced(const char *key, size_t size,
1914 NvOsSharedMemHandle *descriptor, const char *f, int l )
1915 {
1916 NvError status;
1917 status = (NvOsSharedMemAlloc)(key, size, descriptor);
1918 if (status == NvSuccess)
1919 NvOsSetResourceAllocFileLine(*descriptor, f, l);
1920 NVOS_TRACE_LOG_PRINTF(("NvOsSharedMemAlloc, %s, %d, %ums, 0x%x\n",
1921 f, l, NvOsGetTimeMS(), (NvU32)(*descriptor)));
1922 return status;
1923 }
1924
1925 static NV_INLINE NvError
1926 NvOsSharedMemMapTraced(NvOsSharedMemHandle descriptor, size_t offset,
1927 size_t size, void **ptr, const char *f, int l )
1928 {
1929 NvError status;
1930 status = (NvOsSharedMemMap)(descriptor, offset, size, ptr);
1931 NVOS_TRACE_LOG_PRINTF(("NvOsSharedMemMap, %s, %d, %ums, 0x%x\n",
1932 f, l, NvOsGetTimeMS(), (NvU32)(*ptr)));
1933 return status;
1934 }
1935
1936 static NV_INLINE void
1937 NvOsSharedMemUnmapTraced(void *ptr, size_t size, const char *f, int l )
1938 {
1939 NVOS_TRACE_LOG_PRINTF(("NvOsSharedMemUnmap, %s, %d, %ums, 0x%x\n",
1940 f, l, NvOsGetTimeMS(), (NvU32)(ptr)));
1941 (NvOsSharedMemUnmap)(ptr, size);
1942 }
1943
1944 static NV_INLINE void
1945 NvOsSharedMemFreeTraced(NvOsSharedMemHandle descriptor, const char *f, int l )
1946 {
1947 NVOS_TRACE_LOG_PRINTF(("NvOsSharedMemFree, %s, %d, %ums, 0x%x\n",
1948 f, l, NvOsGetTimeMS(), (NvU32)(descriptor)));
1949 (NvOsSharedMemFree)(descriptor);
1950 }
1951
1952 static NV_INLINE NvError
1953 NvOsPhysicalMemMapTraced(NvOsPhysAddr phys, size_t size,
1954 NvOsMemAttribute attrib, NvU32 flags, void **ptr, const char *f, int l )
1955 {
1956 NvError status;
1957 status = (NvOsPhysicalMemMap)(phys, size, attrib, flags, ptr);
1958 if (status == NvSuccess)
1959 NvOsSetResourceAllocFileLine(*ptr, f, l);
1960 NVOS_TRACE_LOG_PRINTF(("NvOsPhysicalMemMap, %s, %d, %ums, 0x%x\n",
1961 f, l, NvOsGetTimeMS(), (NvU32)(*ptr)));
1962 return status;
1963 }
1964
1965 static NV_INLINE NvError
1966 NvOsPhysicalMemMapIntoCallerTraced( void *pCallerPtr, NvOsPhysAddr phys,
1967 size_t size, NvOsMemAttribute attrib, NvU32 flags, const char *f, int l )
1968 {
1969 NVOS_TRACE_LOG_PRINTF(("NvOsPhysicalMemMapIntoCaller, \
1970 %s, %d, %ums, 0x%x\n", f, l, NvOsGetTimeMS(), (NvU32)(pCallerPtr)));
1971 return (NvOsPhysicalMemMapIntoCaller)(pCallerPtr, phys, size, attrib,
1972 flags);
1973 }
1974
1975 static NV_INLINE void
1976 NvOsPhysicalMemUnmapTraced(void *ptr, size_t size, const char *f, int l )
1977 {
1978 NVOS_TRACE_LOG_PRINTF(("NvOsPhysicalMemUnmap, %s, %d, %ums, 0x%x\n",
1979 f, l, NvOsGetTimeMS(), (NvU32)(ptr)));
1980 (NvOsPhysicalMemUnmap)(ptr, size);
1981 }
1982
1983 static NV_INLINE NvError
1984 NvOsPageAllocTraced(size_t size, NvOsMemAttribute attrib,
1985 NvOsPageFlags flags, NvU32 protect, NvOsPageAllocHandle *descriptor,
1986 const char *f, int l )
1987 {
1988 NvError status;
1989 status = (NvOsPageAlloc)(size, attrib, flags, protect, descriptor);
1990 if (status == NvSuccess)
1991 NvOsSetResourceAllocFileLine(*descriptor, f, l);
1992 NVOS_TRACE_LOG_PRINTF(("NvOsPageAlloc, %s, %d, %ums, 0x%x\n",
1993 f, l, NvOsGetTimeMS(), (NvU32)(descriptor)));
1994 return status;
1995 }
1996
1997 static NV_INLINE NvError
1998 NvOsPageLockTraced(void *ptr, size_t size, NvU32 protect, NvOsPageAllocHandle* d escriptor,
1999 const char *f, int l )
2000 {
2001 NvError status;
2002 status = (NvOsPageLock)(ptr, size, protect, descriptor);
2003 NVOS_TRACE_LOG_PRINTF(("NvOsPageLock, %s, %d, %ums, 0x%x, %d, 0x%x, 0x%x\n",
2004 f, l, NvOsGetTimeMS(), (NvU32)(ptr), size, protect, (NvU32)*descriptor)) ;
2005 return status;
2006 }
2007
2008 static NV_INLINE void
2009 NvOsPageFreeTraced(NvOsPageAllocHandle descriptor, const char *f, int l )
2010 {
2011 NVOS_TRACE_LOG_PRINTF(("NvOsPageFree, %s, %d, %ums, 0x%x\n",
2012 f, l, NvOsGetTimeMS(), (NvU32)(descriptor)));
2013 (NvOsPageFree)(descriptor);
2014 }
2015
2016 static NV_INLINE NvError
2017 NvOsPageMapTraced(NvOsPageAllocHandle descriptor, size_t offset, size_t size,
2018 void **ptr, const char *f, int l )
2019 {
2020 NvError status;
2021 status = (NvOsPageMap)(descriptor, offset, size, ptr);
2022 NVOS_TRACE_LOG_PRINTF(("NvOsPageMap, %s, %d, %ums, 0x%x\n",
2023 f, l, NvOsGetTimeMS(), (NvU32)(*ptr)));
2024 return status;
2025 }
2026
2027 static NV_INLINE NvError
2028 NvOsPageMapIntoPtrTraced( NvOsPageAllocHandle descriptor, void *pCallerPtr,
2029 size_t offset, size_t size, const char *f, int l )
2030 {
2031 NvError status;
2032 status = (NvOsPageMapIntoPtr)(descriptor, pCallerPtr, offset, size);
2033 NVOS_TRACE_LOG_PRINTF(("NvOsPageMapIntoCaller, %s, %d, %ums, 0x%x\n",
2034 f, l, NvOsGetTimeMS(), (NvU32)(pCallerPtr)));
2035 return status;
2036 }
2037
2038 static NV_INLINE void
2039 NvOsPageUnmapTraced(NvOsPageAllocHandle descriptor, void *ptr, size_t size,
2040 const char *f, int l )
2041 {
2042 NVOS_TRACE_LOG_PRINTF(("NvOsPageUnmap, %s, %d, %ums, 0x%x\n",
2043 f, l, NvOsGetTimeMS(), (NvU32)(ptr)));
2044 (NvOsPageUnmap)(descriptor, ptr, size);
2045 }
2046
2047 static NV_INLINE NvOsPhysAddr
2048 NvOsPageAddressTraced(NvOsPageAllocHandle descriptor, size_t offset,
2049 const char *f, int l )
2050 {
2051 NvOsPhysAddr PhysAddr;
2052 PhysAddr = (NvOsPageAddress)(descriptor, offset);
2053 NVOS_TRACE_LOG_PRINTF(("NvOsPageAddress, %s, %d, %ums, 0x%x\n",
2054 f, l, NvOsGetTimeMS(), (NvU32)(PhysAddr)));
2055 return PhysAddr;
2056 }
2057
2058 static NV_INLINE NvError
2059 NvOsMutexCreateTraced(NvOsMutexHandle *mutex, const char *f, int l )
2060 {
2061 NvError status;
2062 status = (NvOsMutexCreate)(mutex);
2063 if (status == NvSuccess)
2064 NvOsSetResourceAllocFileLine(*mutex, f, l);
2065 NVOS_TRACE_LOG_PRINTF(("NvOsMutexCreate, %s, %d, %ums, 0x%x\n",
2066 f, l, NvOsGetTimeMS(), (NvU32)(*mutex)));
2067 return status;
2068 }
2069
2070 static NV_INLINE void
2071 NvOsMutexLockTraced(NvOsMutexHandle mutex, const char *f, int l )
2072 {
2073 NVOS_TRACE_LOG_PRINTF(("NvOsMutexLock, %s, %d, %ums, 0x%x\n",
2074 f, l, NvOsGetTimeMS(), (NvU32)mutex));
2075 (NvOsMutexLock)(mutex);
2076 }
2077
2078 static NV_INLINE void
2079 NvOsMutexUnlockTraced(NvOsMutexHandle mutex, const char *f, int l )
2080 {
2081 NVOS_TRACE_LOG_PRINTF(("NvOsMutexUnlock, %s, %d, %ums, 0x%x\n",
2082 f, l, NvOsGetTimeMS(), (NvU32)mutex));
2083 (NvOsMutexUnlock)(mutex);
2084 }
2085
2086 static NV_INLINE void NvOsMutexDestroyTraced(
2087 NvOsMutexHandle mutex,
2088 const char *f,
2089 int l )
2090 {
2091 NVOS_TRACE_LOG_PRINTF(("NvOsMutexDestroy, %s, %d, %ums, 0x%x\n",
2092 f, l, NvOsGetTimeMS(), (NvU32)mutex));
2093 (NvOsMutexDestroy)(mutex);
2094 }
2095
2096 static NV_INLINE NvError
2097 NvOsIntrMutexCreateTraced(NvOsIntrMutexHandle *mutex, const char *f, int l )
2098 {
2099 NvError status;
2100 status = (NvOsIntrMutexCreate)(mutex);
2101 if (status == NvSuccess)
2102 NvOsSetResourceAllocFileLine(*mutex, f, l);
2103 NVOS_TRACE_LOG_PRINTF(("NvOsIntrMutexCreate, %s, %d, %ums, 0x%x\n",
2104 f, l, NvOsGetTimeMS(), (NvU32)(*mutex)));
2105 return status;
2106 }
2107
2108 static NV_INLINE void
2109 NvOsIntrMutexLockTraced(NvOsIntrMutexHandle mutex, const char *f, int l )
2110 {
2111 NVOS_TRACE_LOG_PRINTF(("NvOsIntrMutexLock, %s, %d, %ums, 0x%x\n",
2112 f, l, NvOsGetTimeMS(), (NvU32)mutex));
2113 (NvOsIntrMutexLock)(mutex);
2114 }
2115
2116 static NV_INLINE void
2117 NvOsIntrMutexUnlockTraced(NvOsIntrMutexHandle mutex, const char *f, int l )
2118 {
2119 NVOS_TRACE_LOG_PRINTF(("NvOsIntrMutexUnlock, %s, %d, %ums, 0x%x\n",
2120 f, l, NvOsGetTimeMS(), (NvU32)mutex));
2121 (NvOsIntrMutexUnlock)(mutex);
2122 }
2123
2124 static NV_INLINE void
2125 NvOsIntrMutexDestroyTraced(NvOsIntrMutexHandle mutex, const char *f, int l )
2126 {
2127 NVOS_TRACE_LOG_PRINTF(("NvOsIntrMutexDestroy, %s, %d, %ums, 0x%x\n",
2128 f, l, NvOsGetTimeMS(), (NvU32)mutex));
2129 (NvOsIntrMutexDestroy)(mutex);
2130 }
2131
2132 static NV_INLINE NvError
2133 NvOsSemaphoreCreateTraced( NvOsSemaphoreHandle *semaphore, NvU32 value,
2134 const char *f, int l )
2135 {
2136 NvError status;
2137 status = (NvOsSemaphoreCreate)(semaphore, value);
2138 if (status == NvSuccess)
2139 NvOsSetResourceAllocFileLine(*semaphore, f, l);
2140 NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreCreate, %s, %d, %ums, 0x%x\n",
2141 f, l, NvOsGetTimeMS(), (NvU32)(*semaphore)));
2142 return status;
2143 }
2144
2145 static NV_INLINE NvError
2146 NvOsSemaphoreCloneTraced( NvOsSemaphoreHandle orig, NvOsSemaphoreHandle *clone,
2147 const char *f, int l )
2148 {
2149 NvError status;
2150 status = (NvOsSemaphoreClone)(orig, clone);
2151 if (status == NvSuccess)
2152 NvOsSetResourceAllocFileLine(*clone, f, l);
2153 NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreClone, %s, %d, %ums, 0x%x\n",
2154 f, l, NvOsGetTimeMS(), (NvU32)(*clone)));
2155 return status;
2156 }
2157
2158 static NV_INLINE NvError
2159 NvOsSemaphoreUnmarshalTraced( NvOsSemaphoreHandle hClientSema,
2160 NvOsSemaphoreHandle *phDriverSema, const char *f, int l )
2161 {
2162 NvError status;
2163 status = (NvOsSemaphoreUnmarshal)(hClientSema, phDriverSema);
2164 if (status == NvSuccess)
2165 NvOsSetResourceAllocFileLine(*phDriverSema, f, l);
2166 NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreUnmarshal, %s, %d, %ums, 0x%x\r\n",
2167 f, l, NvOsGetTimeMS(), (NvU32)(hClientSema)));
2168 return status;
2169 }
2170
2171 static NV_INLINE void
2172 NvOsSemaphoreWaitTraced( NvOsSemaphoreHandle semaphore, const char *f, int l )
2173 {
2174 NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreWait, %s, %d, %ums, 0x%x\n",
2175 f, l, NvOsGetTimeMS(), (NvU32)semaphore));
2176 (NvOsSemaphoreWait)(semaphore);
2177 }
2178
2179 static NV_INLINE NvError
2180 NvOsSemaphoreWaitTimeoutTraced( NvOsSemaphoreHandle semaphore, NvU32 msec,
2181 const char *f, int l )
2182 {
2183 NvError status;
2184 NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreWaitTimeout, %s, %d, %ums, 0x%x\n",
2185 f, l, NvOsGetTimeMS(), (NvU32)semaphore));
2186 status = (NvOsSemaphoreWaitTimeout)(semaphore, msec);
2187 return status;
2188 }
2189
2190 static NV_INLINE void
2191 NvOsSemaphoreSignalTraced( NvOsSemaphoreHandle semaphore, const char *f, int l )
2192 {
2193 NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreSignal, %s, %d, %ums, 0x%x\n",
2194 f, l, NvOsGetTimeMS(), (NvU32)semaphore));
2195 (NvOsSemaphoreSignal)(semaphore);
2196 }
2197
2198 static NV_INLINE void
2199 NvOsSemaphoreDestroyTraced( NvOsSemaphoreHandle semaphore, const char *f, int l )
2200 {
2201 NVOS_TRACE_LOG_PRINTF(("NvOsSemaphoreDestory, %s, %d, %ums, 0x%x\n",
2202 f, l, NvOsGetTimeMS(), (NvU32)semaphore));
2203 (NvOsSemaphoreDestroy)(semaphore);
2204 }
2205
2206 static NV_INLINE NvError
2207 NvOsThreadCreateTraced( NvOsThreadFunction function, void *args,
2208 NvOsThreadHandle *thread, const char *f, int l )
2209 {
2210 NvError status;
2211 status = (NvOsThreadCreate)(function, args, thread);
2212 if (status == NvSuccess)
2213 NvOsSetResourceAllocFileLine(*thread, f, l);
2214 NVOS_TRACE_LOG_PRINTF(("NvOsThreadCreate, %s, %d, %ums, 0x%x\n",
2215 f, l, NvOsGetTimeMS(), (NvU32)(*thread)));
2216 return status;
2217 }
2218
2219 static NV_INLINE void
2220 NvOsThreadJoinTraced( NvOsThreadHandle thread, const char *f, int l )
2221 {
2222 NVOS_TRACE_LOG_PRINTF(("NvOsThreadJoin, %s, %d, %ums, 0x%x\n",
2223 f, l, NvOsGetTimeMS(), (NvU32)thread));
2224 (NvOsThreadJoin)(thread);
2225 }
2226
2227 static NV_INLINE void
2228 NvOsThreadYieldTraced(const char *f, int l )
2229 {
2230 NVOS_TRACE_LOG_PRINTF(("NvOsThreadYield, %s, %d, %ums, 0x%x\n",
2231 f, l, NvOsGetTimeMS(), (NvU32)0));
2232 (NvOsThreadYield)();
2233 }
2234
2235 static NV_INLINE NvError
2236 NvOsInterruptRegisterTraced(NvU32 IrqListSize, const NvU32 *pIrqList,
2237 const NvOsInterruptHandler *pIrqHandlerList, void *context,
2238 NvOsInterruptHandle *handle, NvBool InterruptEnable, const char *f, int l )
2239 {
2240 NvError status;
2241 status = (NvOsInterruptRegister)(IrqListSize, pIrqList, pIrqHandlerList,
2242 context, handle, InterruptEnable);
2243 NVOS_TRACE_LOG_PRINTF(("NvOsInterruptRegister, %s, %d, %ums, 0x%x\n",
2244 f, l, NvOsGetTimeMS(), (NvU32)(handle)));
2245 return status;
2246 }
2247
2248 static NV_INLINE void
2249 NvOsInterruptUnregisterTraced(NvOsInterruptHandle handle, const char *f, int l )
2250 {
2251 NVOS_TRACE_LOG_PRINTF(("NvOsInterruptUnregister, %s, %d, %ums, 0x%x\n",
2252 f, l, NvOsGetTimeMS(), (NvU32)(handle)));
2253 (NvOsInterruptUnregister)(handle);
2254 }
2255
2256 static NV_INLINE NvError
2257 NvOsInterruptEnableTraced(NvOsInterruptHandle handle, const char *f, int l )
2258 {
2259 NvError status;
2260
2261 status = (NvOsInterruptEnable)(handle);
2262 NVOS_TRACE_LOG_PRINTF(("NvOsInterruptRegister, %s, %d, %ums, 0x%x\n",
2263 f, l, NvOsGetTimeMS(), (NvU32)(handle)));
2264 return status;
2265 }
2266
2267 static NV_INLINE void
2268 NvOsInterruptDoneTraced(NvOsInterruptHandle handle, const char *f, int l )
2269 {
2270 NVOS_TRACE_LOG_PRINTF(("NvOsInterruptDone, %s, %d, %ums, 0x%x\n",
2271 f, l, NvOsGetTimeMS(), (NvU32)(handle)));
2272 (NvOsInterruptDone)(handle);
2273 }
2274
2275 #define NvOsExecAlloc(size) NvOsExecAllocTraced(size, __FILE__, __LINE__)
2276 #define NvOsExecFree(ptr, size) \
2277 NvOsExecFreeTraced(ptr, size, __FILE__, __LINE__)
2278 #define NvOsSharedMemAlloc(key, size, descriptor) \
2279 NvOsSharedMemAllocTraced(key, size, descriptor, __FILE__, __LINE__)
2280 #define NvOsSharedMemMap(descriptor, offset, size, ptr) \
2281 NvOsSharedMemMapTraced(descriptor, offset, size, ptr, __FILE__, __LINE__)
2282 #define NvOsSharedMemUnmap(ptr, size) \
2283 NvOsSharedMemUnmapTraced(ptr, size, __FILE__, __LINE__)
2284 #define NvOsSharedMemFree(descriptor) \
2285 NvOsSharedMemFreeTraced(descriptor, __FILE__, __LINE__)
2286 #define NvOsPhysicalMemMap(phys, size, attrib, flags, ptr) \
2287 NvOsPhysicalMemMapTraced(phys, size, attrib, flags, ptr, \
2288 __FILE__, __LINE__)
2289 #define NvOsPhysicalMemMapIntoCaller(pCallerPtr, phys, size, attrib, flags) \
2290 NvOsPhysicalMemMapIntoCallerTraced(pCallerPtr, phys, size, attrib, flags, \
2291 __FILE__, __LINE__)
2292 #define NvOsPhysicalMemUnmap(ptr, size) \
2293 NvOsPhysicalMemUnmapTraced(ptr, size, __FILE__, __LINE__)
2294 #define NvOsPageAlloc(size, attrib, flags, protect, descriptor) \
2295 NvOsPageAllocTraced(size, attrib, flags, protect, descriptor, \
2296 __FILE__, __LINE__)
2297 #define NvOsPageFree(descriptor) \
2298 NvOsPageFreeTraced(descriptor, __FILE__, __LINE__)
2299 #define NvOsPageMap(descriptor, offset, size, ptr) \
2300 NvOsPageMapTraced(descriptor, offset, size, ptr, __FILE__, __LINE__)
2301 #define NvOsPageMapIntoPtr(descriptor, pCallerPtr, offset, size) \
2302 NvOsPageMapIntoPtrTraced(descriptor, pCallerPtr, offset, size, \
2303 __FILE__, __LINE__)
2304 #define NvOsPageUnmap(descriptor, ptr, size) \
2305 NvOsPageUnmapTraced(descriptor, ptr, size, __FILE__, __LINE__)
2306 #define NvOsPageAddress(descriptor, offset) \
2307 NvOsPageAddressTraced(descriptor, offset, __FILE__, __LINE__)
2308 #define NvOsMutexCreate(mutex) NvOsMutexCreateTraced(mutex, __FILE__, __LINE__)
2309 #define NvOsMutexLock(mutex) NvOsMutexLockTraced(mutex, __FILE__, __LINE__)
2310 #define NvOsMutexUnlock(mutex) NvOsMutexUnlockTraced(mutex, __FILE__, __LINE__)
2311 #define NvOsMutexDestroy(mutex) \
2312 NvOsMutexDestroyTraced(mutex, __FILE__, __LINE__)
2313 #define NvOsIntrMutexCreate(mutex) \
2314 NvOsIntrMutexCreateTraced(mutex, __FILE__, __LINE__)
2315 #define NvOsIntrMutexLock(mutex) \
2316 NvOsIntrMutexLockTraced(mutex, __FILE__, __LINE__)
2317 #define NvOsIntrMutexUnlock(mutex) \
2318 NvOsIntrMutexUnlockTraced(mutex, __FILE__, __LINE__)
2319 #define NvOsIntrMutexDestroy(mutex) \
2320 NvOsIntrMutexDestroyTraced(mutex, __FILE__, __LINE__)
2321 #define NvOsSemaphoreCreate(semaphore, value) \
2322 NvOsSemaphoreCreateTraced(semaphore, value, __FILE__, __LINE__)
2323 #define NvOsSemaphoreClone(orig, semaphore) \
2324 NvOsSemaphoreCloneTraced(orig, semaphore, __FILE__, __LINE__)
2325 #define NvOsSemaphoreUnmarshal(hClientSema, phDriverSema) \
2326 NvOsSemaphoreUnmarshalTraced(hClientSema, phDriverSema, __FILE__, __LINE__)
2327 /*
2328 #define NvOsSemaphoreWait(semaphore) \
2329 NvOsSemaphoreWaitTraced(semaphore, __FILE__, __LINE__)
2330 #define NvOsSemaphoreWaitTimeout(semaphore, msec) \
2331 NvOsSemaphoreWaitTimeoutTraced(semaphore, msec, __FILE__, __LINE__)
2332 */
2333 #define NvOsSemaphoreSignal(semaphore) \
2334 NvOsSemaphoreSignalTraced(semaphore, __FILE__, __LINE__)
2335 #define NvOsSemaphoreDestroy(semaphore) \
2336 NvOsSemaphoreDestroyTraced(semaphore, __FILE__, __LINE__)
2337 #define NvOsThreadCreate(func, args, thread) \
2338 NvOsThreadCreateTraced(func, args, thread, __FILE__, __LINE__)
2339 #define NvOsThreadJoin(thread) \
2340 NvOsThreadJoinTraced(thread, __FILE__, __LINE__)
2341 #define NvOsThreadYield() NvOsThreadYieldTraced(__FILE__, __LINE__)
2342 #define NvOsInterruptRegister(IrqListSize, pIrqList, pIrqHandlerList, \
2343 context, handle, InterruptEnable) \
2344 NvOsInterruptRegisterTraced(IrqListSize, pIrqList, pIrqHandlerList, \
2345 context, handle, InterruptEnable, __FILE__, __LINE__)
2346 #define NvOsInterruptUnregister(handle) \
2347 NvOsInterruptUnregisterTraced(handle, __FILE__, __LINE__)
2348 #define NvOsInterruptEnable(handle) \
2349 NvOsInterruptEnableTraced(handle, __FILE__, __LINE__)
2350 #define NvOsInterruptDone(handle) \
2351 NvOsInterruptDoneTraced(handle, __FILE__, __LINE__)
2352
2353 #endif // NVOS_TRACE
2354
2355 // Forward declare resource tracking struct.
2356 typedef struct NvCallstackRec NvCallstack;
2357
2358 typedef enum
2359 {
2360 NvOsCallstackType_NoStack = 1,
2361 NvOsCallstackType_HexStack,
2362 NvOsCallstackType_SymbolStack,
2363
2364 NvOsCallstackType_Last,
2365 NvOsCallstackType_Force32 = 0x7FFFFFFF
2366 } NvOsCallstackType;
2367
2368 typedef void (*NvOsDumpCallback)(void* context, const char* line);
2369
2370 void NvOsDumpToDebugPrintf(void* context, const char* line);
2371 void NvOsGetProcessInfo(char* buf, NvU32 len);
2372
2373 /* implemented by the OS-backend, for now CE and Linux only */
2374 #if (NVOS_IS_WINDOWS_CE || NVOS_IS_LINUX)
2375 NvCallstack* NvOsCreateCallstack (NvOsCallstackType stackType);
2376 void NvOsGetStackFrame (char* buf, NvU32 len, NvCallstack* stack, NvU32 level);
2377 void NvOsDestroyCallstack (NvCallstack* callstack);
2378 NvU32 NvOsHashCallstack (NvCallstack* stack);
2379 void NvOsDumpCallstack (NvCallstack* stack, NvU32 skip, NvOsDumpC allback callBack, void* context);
2380 NvBool NvOsCallstackContainsPid (NvCallstack* stack, NvU32 pid);
2381 NvU32 NvOsCallstackGetNumLevels(NvCallstack* stack);
2382 #else // (NVOS_IS_WINDOWS_CE || NVOS_IS_LINUX)
2383 static NV_INLINE NvCallstack* NvOsCreateCallstack (NvOsCallstackType stackType) { return NULL; }
2384 static NV_INLINE void NvOsGetStackFrame (char* buf, NvU32 len, NvCalls tack* stack, NvU32 level) { NvOsStrncpy(buf, "<stack>", len); }
2385 static NV_INLINE void NvOsDestroyCallstack (NvCallstack* callstack) { }
2386 static NV_INLINE NvU32 NvOsHashCallstack (NvCallstack* stack) { return 0; }
2387 static NV_INLINE void NvOsDumpCallstack (NvCallstack* stack, NvU32 ski p, NvOsDumpCallback callBack, void* context) { }
2388 static NvBool NV_INLINE NvOsCallstackContainsPid (NvCallstack* stack, NvU32 pid ) { return NV_FALSE; }
2389 static NV_INLINE NvU32 NvOsCallstackGetNumLevels (NvCallstack* stack) { return 0; }
2390 #endif // (NVOS_IS_WINDOWS_CE || NVOS_IS_LINUX)
2391
2392 /*@}*/
2393 /** @} */
2394
2395 #if defined(__cplusplus)
2396 }
2397 #endif
2398
2399 #endif // INCLUDED_NVOS_H
OLDNEW
« no previous file with comments | « arch/arm/mach-tegra/nv/include/nvodm_vibrate.h ('k') | arch/arm/mach-tegra/nv/include/nvos_linux_ioctls.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698