1 #include "cudbg.h" 2 3 void 4 init_cudbg_hdr(struct cudbg_init_hdr *hdr) 5 { 6 hdr->major_ver = CUDBG_MAJOR_VERSION; 7 hdr->minor_ver = CUDBG_MINOR_VERSION; 8 hdr->build_ver = CUDBG_BUILD_VERSION; 9 hdr->init_struct_size = sizeof(struct cudbg_init); 10 } 11 12 /** 13 * cudbg_alloc_handle - Allocates and initializes a handle that represents 14 * cudbg state. Needs to called first before calling any other function. 15 * 16 * returns a pointer to memory that has a cudbg_init structure at the begining 17 * and enough space after that for internal book keeping. 18 */ 19 20 void * 21 cudbg_alloc_handle(void) 22 { 23 struct cudbg_private *handle; 24 25 #ifdef _KERNEL 26 handle = kmem_zalloc(sizeof(*handle), KM_NOSLEEP); 27 #else 28 handle = malloc(sizeof(*handle)); 29 #endif 30 31 if (handle == NULL) 32 return NULL; 33 34 init_cudbg_hdr(&handle->dbg_init.header); 35 36 return (handle); 37 } 38 39 /** 40 * cudbg_free_handle - Release cudbg resources. 41 * ## Parameters ## 42 * @handle : A pointer returned by cudbg_alloc_handle. 43 */ 44 void 45 cudbg_free_handle(void *handle) 46 { 47 #ifdef _KERNEL 48 kmem_free(handle, sizeof(struct cudbg_private)); 49 #else 50 free(handle); 51 #endif 52 } 53 54 /********************************* Helper functions *************************/ 55 void 56 set_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type) 57 { 58 int index = type / 8; 59 int bit = type % 8; 60 61 bitmap[index] |= (1 << bit); 62 } 63 64 void 65 reset_dbg_bitmap(u8 *bitmap, enum CUDBG_DBG_ENTITY_TYPE type) 66 { 67 int index = type / 8; 68 int bit = type % 8; 69 70 bitmap[index] &= ~(1 << bit); 71 } 72 73 /********************************* End of Helper functions 74 * *************************/ 75 76 struct cudbg_init * 77 cudbg_get_init(void *handle) 78 { 79 return (handle); 80 } 81