blob: 2ad526b7d54257003dbb35cd610230389d9bd9cd (
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
|
#include "cudbg.h"
void
init_cudbg_hdr(struct cudbg_init_hdr *hdr)
{
hdr->major_ver = CUDBG_MAJOR_VERSION;
hdr->minor_ver = CUDBG_MINOR_VERSION;
hdr->build_ver = CUDBG_BUILD_VERSION;
hdr->init_struct_size = sizeof(struct cudbg_init);
}
/**
* cudbg_alloc_handle - Allocates and initializes a handle that represents
* cudbg state. Needs to called first before calling any other function.
*
* returns a pointer to memory that has a cudbg_init structure at the begining
* and enough space after that for internal book keeping.
*/
void *
cudbg_alloc_handle(void)
{
struct cudbg_private *handle;
#ifdef _KERNEL
handle = kmem_zalloc(sizeof(*handle), KM_NOSLEEP);
#else
handle = malloc(sizeof(*handle));
#endif
if (handle == NULL)
return NULL;
init_cudbg_hdr(&handle->dbg_init.header);
return (handle);
}
/**
* cudbg_free_handle - Release cudbg resources.
* ## Parameters ##
* @handle : A pointer returned by cudbg_alloc_handle.
*/
void
cudbg_free_handle(void *handle)
{
#ifdef _KERNEL
kmem_free(handle, sizeof(struct cudbg_private));
#else
free(handle);
#endif
}
/********************************* Helper functions *************************/
void
set_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type)
{
int index = type / 8;
int bit = type % 8;
bitmap[index] |= (1 << bit);
}
void
reset_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type)
{
int index = type / 8;
int bit = type % 8;
bitmap[index] &= ~(1 << bit);
}
/********************************* End of Helper functions
* *************************/
struct cudbg_init *
cudbg_get_init(void *handle)
{
return (handle);
}
|