debug.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540
  1. /*
  2. * arch/s390/kernel/debug.c
  3. * S/390 debug facility
  4. *
  5. * Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH,
  6. * IBM Corporation
  7. * Author(s): Michael Holzheu (holzheu@de.ibm.com),
  8. * Holger Smolinski (Holger.Smolinski@de.ibm.com)
  9. *
  10. * Bugreports to: <Linux390@de.ibm.com>
  11. */
  12. #include <linux/stddef.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/slab.h>
  16. #include <linux/ctype.h>
  17. #include <linux/sysctl.h>
  18. #include <asm/uaccess.h>
  19. #include <asm/semaphore.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/fs.h>
  23. #include <linux/debugfs.h>
  24. #include <asm/debug.h>
  25. #define DEBUG_PROLOG_ENTRY -1
  26. #define ALL_AREAS 0 /* copy all debug areas */
  27. #define NO_AREAS 1 /* copy no debug areas */
  28. /* typedefs */
  29. typedef struct file_private_info {
  30. loff_t offset; /* offset of last read in file */
  31. int act_area; /* number of last formated area */
  32. int act_page; /* act page in given area */
  33. int act_entry; /* last formated entry (offset */
  34. /* relative to beginning of last */
  35. /* formated page) */
  36. size_t act_entry_offset; /* up to this offset we copied */
  37. /* in last read the last formated */
  38. /* entry to userland */
  39. char temp_buf[2048]; /* buffer for output */
  40. debug_info_t *debug_info_org; /* original debug information */
  41. debug_info_t *debug_info_snap; /* snapshot of debug information */
  42. struct debug_view *view; /* used view of debug info */
  43. } file_private_info_t;
  44. typedef struct
  45. {
  46. char *string;
  47. /*
  48. * This assumes that all args are converted into longs
  49. * on L/390 this is the case for all types of parameter
  50. * except of floats, and long long (32 bit)
  51. *
  52. */
  53. long args[0];
  54. } debug_sprintf_entry_t;
  55. extern void tod_to_timeval(uint64_t todval, struct timespec *xtime);
  56. /* internal function prototyes */
  57. static int debug_init(void);
  58. static ssize_t debug_output(struct file *file, char __user *user_buf,
  59. size_t user_len, loff_t * offset);
  60. static ssize_t debug_input(struct file *file, const char __user *user_buf,
  61. size_t user_len, loff_t * offset);
  62. static int debug_open(struct inode *inode, struct file *file);
  63. static int debug_close(struct inode *inode, struct file *file);
  64. static debug_info_t* debug_info_create(char *name, int pages_per_area,
  65. int nr_areas, int buf_size);
  66. static void debug_info_get(debug_info_t *);
  67. static void debug_info_put(debug_info_t *);
  68. static int debug_prolog_level_fn(debug_info_t * id,
  69. struct debug_view *view, char *out_buf);
  70. static int debug_input_level_fn(debug_info_t * id, struct debug_view *view,
  71. struct file *file, const char __user *user_buf,
  72. size_t user_buf_size, loff_t * offset);
  73. static int debug_prolog_pages_fn(debug_info_t * id,
  74. struct debug_view *view, char *out_buf);
  75. static int debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
  76. struct file *file, const char __user *user_buf,
  77. size_t user_buf_size, loff_t * offset);
  78. static int debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
  79. struct file *file, const char __user *user_buf,
  80. size_t user_buf_size, loff_t * offset);
  81. static int debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
  82. char *out_buf, const char *in_buf);
  83. static int debug_raw_format_fn(debug_info_t * id,
  84. struct debug_view *view, char *out_buf,
  85. const char *in_buf);
  86. static int debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
  87. int area, debug_entry_t * entry, char *out_buf);
  88. static int debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
  89. char *out_buf, debug_sprintf_entry_t *curr_event);
  90. /* globals */
  91. struct debug_view debug_raw_view = {
  92. "raw",
  93. NULL,
  94. &debug_raw_header_fn,
  95. &debug_raw_format_fn,
  96. NULL,
  97. NULL
  98. };
  99. struct debug_view debug_hex_ascii_view = {
  100. "hex_ascii",
  101. NULL,
  102. &debug_dflt_header_fn,
  103. &debug_hex_ascii_format_fn,
  104. NULL,
  105. NULL
  106. };
  107. static struct debug_view debug_level_view = {
  108. "level",
  109. &debug_prolog_level_fn,
  110. NULL,
  111. NULL,
  112. &debug_input_level_fn,
  113. NULL
  114. };
  115. static struct debug_view debug_pages_view = {
  116. "pages",
  117. &debug_prolog_pages_fn,
  118. NULL,
  119. NULL,
  120. &debug_input_pages_fn,
  121. NULL
  122. };
  123. static struct debug_view debug_flush_view = {
  124. "flush",
  125. NULL,
  126. NULL,
  127. NULL,
  128. &debug_input_flush_fn,
  129. NULL
  130. };
  131. struct debug_view debug_sprintf_view = {
  132. "sprintf",
  133. NULL,
  134. &debug_dflt_header_fn,
  135. (debug_format_proc_t*)&debug_sprintf_format_fn,
  136. NULL,
  137. NULL
  138. };
  139. /* used by dump analysis tools to determine version of debug feature */
  140. unsigned int debug_feature_version = __DEBUG_FEATURE_VERSION;
  141. /* static globals */
  142. static debug_info_t *debug_area_first = NULL;
  143. static debug_info_t *debug_area_last = NULL;
  144. static DECLARE_MUTEX(debug_lock);
  145. static int initialized;
  146. static struct file_operations debug_file_ops = {
  147. .owner = THIS_MODULE,
  148. .read = debug_output,
  149. .write = debug_input,
  150. .open = debug_open,
  151. .release = debug_close,
  152. };
  153. static struct dentry *debug_debugfs_root_entry;
  154. /* functions */
  155. /*
  156. * debug_areas_alloc
  157. * - Debug areas are implemented as a threedimensonal array:
  158. * areas[areanumber][pagenumber][pageoffset]
  159. */
  160. static debug_entry_t***
  161. debug_areas_alloc(int pages_per_area, int nr_areas)
  162. {
  163. debug_entry_t*** areas;
  164. int i,j;
  165. areas = kmalloc(nr_areas *
  166. sizeof(debug_entry_t**),
  167. GFP_KERNEL);
  168. if (!areas)
  169. goto fail_malloc_areas;
  170. for (i = 0; i < nr_areas; i++) {
  171. areas[i] = kmalloc(pages_per_area *
  172. sizeof(debug_entry_t*),GFP_KERNEL);
  173. if (!areas[i]) {
  174. goto fail_malloc_areas2;
  175. }
  176. for(j = 0; j < pages_per_area; j++) {
  177. areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL);
  178. if(!areas[i][j]) {
  179. for(j--; j >=0 ; j--) {
  180. kfree(areas[i][j]);
  181. }
  182. kfree(areas[i]);
  183. goto fail_malloc_areas2;
  184. }
  185. }
  186. }
  187. return areas;
  188. fail_malloc_areas2:
  189. for(i--; i >= 0; i--){
  190. for(j=0; j < pages_per_area;j++){
  191. kfree(areas[i][j]);
  192. }
  193. kfree(areas[i]);
  194. }
  195. kfree(areas);
  196. fail_malloc_areas:
  197. return NULL;
  198. }
  199. /*
  200. * debug_info_alloc
  201. * - alloc new debug-info
  202. */
  203. static debug_info_t*
  204. debug_info_alloc(char *name, int pages_per_area, int nr_areas, int buf_size,
  205. int level, int mode)
  206. {
  207. debug_info_t* rc;
  208. /* alloc everything */
  209. rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL);
  210. if(!rc)
  211. goto fail_malloc_rc;
  212. rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
  213. if(!rc->active_entries)
  214. goto fail_malloc_active_entries;
  215. rc->active_pages = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
  216. if(!rc->active_pages)
  217. goto fail_malloc_active_pages;
  218. if((mode == ALL_AREAS) && (pages_per_area != 0)){
  219. rc->areas = debug_areas_alloc(pages_per_area, nr_areas);
  220. if(!rc->areas)
  221. goto fail_malloc_areas;
  222. } else {
  223. rc->areas = NULL;
  224. }
  225. /* initialize members */
  226. spin_lock_init(&rc->lock);
  227. rc->pages_per_area = pages_per_area;
  228. rc->nr_areas = nr_areas;
  229. rc->active_area = 0;
  230. rc->level = level;
  231. rc->buf_size = buf_size;
  232. rc->entry_size = sizeof(debug_entry_t) + buf_size;
  233. strlcpy(rc->name, name, sizeof(rc->name)-1);
  234. memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
  235. memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS *
  236. sizeof(struct dentry*));
  237. atomic_set(&(rc->ref_count), 0);
  238. return rc;
  239. fail_malloc_areas:
  240. kfree(rc->active_pages);
  241. fail_malloc_active_pages:
  242. kfree(rc->active_entries);
  243. fail_malloc_active_entries:
  244. kfree(rc);
  245. fail_malloc_rc:
  246. return NULL;
  247. }
  248. /*
  249. * debug_areas_free
  250. * - free all debug areas
  251. */
  252. static void
  253. debug_areas_free(debug_info_t* db_info)
  254. {
  255. int i,j;
  256. if(!db_info->areas)
  257. return;
  258. for (i = 0; i < db_info->nr_areas; i++) {
  259. for(j = 0; j < db_info->pages_per_area; j++) {
  260. kfree(db_info->areas[i][j]);
  261. }
  262. kfree(db_info->areas[i]);
  263. }
  264. kfree(db_info->areas);
  265. db_info->areas = NULL;
  266. }
  267. /*
  268. * debug_info_free
  269. * - free memory debug-info
  270. */
  271. static void
  272. debug_info_free(debug_info_t* db_info){
  273. debug_areas_free(db_info);
  274. kfree(db_info->active_entries);
  275. kfree(db_info->active_pages);
  276. kfree(db_info);
  277. }
  278. /*
  279. * debug_info_create
  280. * - create new debug-info
  281. */
  282. static debug_info_t*
  283. debug_info_create(char *name, int pages_per_area, int nr_areas, int buf_size)
  284. {
  285. debug_info_t* rc;
  286. rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size,
  287. DEBUG_DEFAULT_LEVEL, ALL_AREAS);
  288. if(!rc)
  289. goto out;
  290. /* create root directory */
  291. rc->debugfs_root_entry = debugfs_create_dir(rc->name,
  292. debug_debugfs_root_entry);
  293. /* append new element to linked list */
  294. if (!debug_area_first) {
  295. /* first element in list */
  296. debug_area_first = rc;
  297. rc->prev = NULL;
  298. } else {
  299. /* append element to end of list */
  300. debug_area_last->next = rc;
  301. rc->prev = debug_area_last;
  302. }
  303. debug_area_last = rc;
  304. rc->next = NULL;
  305. debug_info_get(rc);
  306. out:
  307. return rc;
  308. }
  309. /*
  310. * debug_info_copy
  311. * - copy debug-info
  312. */
  313. static debug_info_t*
  314. debug_info_copy(debug_info_t* in, int mode)
  315. {
  316. int i,j;
  317. debug_info_t* rc;
  318. unsigned long flags;
  319. /* get a consistent copy of the debug areas */
  320. do {
  321. rc = debug_info_alloc(in->name, in->pages_per_area,
  322. in->nr_areas, in->buf_size, in->level, mode);
  323. spin_lock_irqsave(&in->lock, flags);
  324. if(!rc)
  325. goto out;
  326. /* has something changed in the meantime ? */
  327. if((rc->pages_per_area == in->pages_per_area) &&
  328. (rc->nr_areas == in->nr_areas)) {
  329. break;
  330. }
  331. spin_unlock_irqrestore(&in->lock, flags);
  332. debug_info_free(rc);
  333. } while (1);
  334. if(!rc || (mode == NO_AREAS))
  335. goto out;
  336. for(i = 0; i < in->nr_areas; i++){
  337. for(j = 0; j < in->pages_per_area; j++) {
  338. memcpy(rc->areas[i][j], in->areas[i][j],PAGE_SIZE);
  339. }
  340. }
  341. out:
  342. spin_unlock_irqrestore(&in->lock, flags);
  343. return rc;
  344. }
  345. /*
  346. * debug_info_get
  347. * - increments reference count for debug-info
  348. */
  349. static void
  350. debug_info_get(debug_info_t * db_info)
  351. {
  352. if (db_info)
  353. atomic_inc(&db_info->ref_count);
  354. }
  355. /*
  356. * debug_info_put:
  357. * - decreases reference count for debug-info and frees it if necessary
  358. */
  359. static void
  360. debug_info_put(debug_info_t *db_info)
  361. {
  362. int i;
  363. if (!db_info)
  364. return;
  365. if (atomic_dec_and_test(&db_info->ref_count)) {
  366. for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
  367. if (!db_info->views[i])
  368. continue;
  369. debugfs_remove(db_info->debugfs_entries[i]);
  370. }
  371. debugfs_remove(db_info->debugfs_root_entry);
  372. if(db_info == debug_area_first)
  373. debug_area_first = db_info->next;
  374. if(db_info == debug_area_last)
  375. debug_area_last = db_info->prev;
  376. if(db_info->prev) db_info->prev->next = db_info->next;
  377. if(db_info->next) db_info->next->prev = db_info->prev;
  378. debug_info_free(db_info);
  379. }
  380. }
  381. /*
  382. * debug_format_entry:
  383. * - format one debug entry and return size of formated data
  384. */
  385. static int
  386. debug_format_entry(file_private_info_t *p_info)
  387. {
  388. debug_info_t *id_snap = p_info->debug_info_snap;
  389. struct debug_view *view = p_info->view;
  390. debug_entry_t *act_entry;
  391. size_t len = 0;
  392. if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
  393. /* print prolog */
  394. if (view->prolog_proc)
  395. len += view->prolog_proc(id_snap,view,p_info->temp_buf);
  396. goto out;
  397. }
  398. if (!id_snap->areas) /* this is true, if we have a prolog only view */
  399. goto out; /* or if 'pages_per_area' is 0 */
  400. act_entry = (debug_entry_t *) ((char*)id_snap->areas[p_info->act_area]
  401. [p_info->act_page] + p_info->act_entry);
  402. if (act_entry->id.stck == 0LL)
  403. goto out; /* empty entry */
  404. if (view->header_proc)
  405. len += view->header_proc(id_snap, view, p_info->act_area,
  406. act_entry, p_info->temp_buf + len);
  407. if (view->format_proc)
  408. len += view->format_proc(id_snap, view, p_info->temp_buf + len,
  409. DEBUG_DATA(act_entry));
  410. out:
  411. return len;
  412. }
  413. /*
  414. * debug_next_entry:
  415. * - goto next entry in p_info
  416. */
  417. static inline int
  418. debug_next_entry(file_private_info_t *p_info)
  419. {
  420. debug_info_t *id;
  421. id = p_info->debug_info_snap;
  422. if(p_info->act_entry == DEBUG_PROLOG_ENTRY){
  423. p_info->act_entry = 0;
  424. p_info->act_page = 0;
  425. goto out;
  426. }
  427. if(!id->areas)
  428. return 1;
  429. p_info->act_entry += id->entry_size;
  430. /* switch to next page, if we reached the end of the page */
  431. if (p_info->act_entry > (PAGE_SIZE - id->entry_size)){
  432. /* next page */
  433. p_info->act_entry = 0;
  434. p_info->act_page += 1;
  435. if((p_info->act_page % id->pages_per_area) == 0) {
  436. /* next area */
  437. p_info->act_area++;
  438. p_info->act_page=0;
  439. }
  440. if(p_info->act_area >= id->nr_areas)
  441. return 1;
  442. }
  443. out:
  444. return 0;
  445. }
  446. /*
  447. * debug_output:
  448. * - called for user read()
  449. * - copies formated debug entries to the user buffer
  450. */
  451. static ssize_t
  452. debug_output(struct file *file, /* file descriptor */
  453. char __user *user_buf, /* user buffer */
  454. size_t len, /* length of buffer */
  455. loff_t *offset) /* offset in the file */
  456. {
  457. size_t count = 0;
  458. size_t entry_offset;
  459. file_private_info_t *p_info;
  460. p_info = ((file_private_info_t *) file->private_data);
  461. if (*offset != p_info->offset)
  462. return -EPIPE;
  463. if(p_info->act_area >= p_info->debug_info_snap->nr_areas)
  464. return 0;
  465. entry_offset = p_info->act_entry_offset;
  466. while(count < len){
  467. int formatted_line_size;
  468. int formatted_line_residue;
  469. int user_buf_residue;
  470. size_t copy_size;
  471. formatted_line_size = debug_format_entry(p_info);
  472. formatted_line_residue = formatted_line_size - entry_offset;
  473. user_buf_residue = len-count;
  474. copy_size = min(user_buf_residue, formatted_line_residue);
  475. if(copy_size){
  476. if (copy_to_user(user_buf + count, p_info->temp_buf
  477. + entry_offset, copy_size))
  478. return -EFAULT;
  479. count += copy_size;
  480. entry_offset += copy_size;
  481. }
  482. if(copy_size == formatted_line_residue){
  483. entry_offset = 0;
  484. if(debug_next_entry(p_info))
  485. goto out;
  486. }
  487. }
  488. out:
  489. p_info->offset = *offset + count;
  490. p_info->act_entry_offset = entry_offset;
  491. *offset = p_info->offset;
  492. return count;
  493. }
  494. /*
  495. * debug_input:
  496. * - called for user write()
  497. * - calls input function of view
  498. */
  499. static ssize_t
  500. debug_input(struct file *file, const char __user *user_buf, size_t length,
  501. loff_t *offset)
  502. {
  503. int rc = 0;
  504. file_private_info_t *p_info;
  505. down(&debug_lock);
  506. p_info = ((file_private_info_t *) file->private_data);
  507. if (p_info->view->input_proc)
  508. rc = p_info->view->input_proc(p_info->debug_info_org,
  509. p_info->view, file, user_buf,
  510. length, offset);
  511. else
  512. rc = -EPERM;
  513. up(&debug_lock);
  514. return rc; /* number of input characters */
  515. }
  516. /*
  517. * debug_open:
  518. * - called for user open()
  519. * - copies formated output to private_data area of the file
  520. * handle
  521. */
  522. static int
  523. debug_open(struct inode *inode, struct file *file)
  524. {
  525. int i = 0, rc = 0;
  526. file_private_info_t *p_info;
  527. debug_info_t *debug_info, *debug_info_snapshot;
  528. down(&debug_lock);
  529. debug_info = file->f_path.dentry->d_inode->i_private;
  530. /* find debug view */
  531. for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
  532. if (!debug_info->views[i])
  533. continue;
  534. else if (debug_info->debugfs_entries[i] ==
  535. file->f_path.dentry) {
  536. goto found; /* found view ! */
  537. }
  538. }
  539. /* no entry found */
  540. rc = -EINVAL;
  541. goto out;
  542. found:
  543. /* Make snapshot of current debug areas to get it consistent. */
  544. /* To copy all the areas is only needed, if we have a view which */
  545. /* formats the debug areas. */
  546. if(!debug_info->views[i]->format_proc &&
  547. !debug_info->views[i]->header_proc){
  548. debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS);
  549. } else {
  550. debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS);
  551. }
  552. if(!debug_info_snapshot){
  553. rc = -ENOMEM;
  554. goto out;
  555. }
  556. p_info = kmalloc(sizeof(file_private_info_t),
  557. GFP_KERNEL);
  558. if(!p_info){
  559. if(debug_info_snapshot)
  560. debug_info_free(debug_info_snapshot);
  561. rc = -ENOMEM;
  562. goto out;
  563. }
  564. p_info->offset = 0;
  565. p_info->debug_info_snap = debug_info_snapshot;
  566. p_info->debug_info_org = debug_info;
  567. p_info->view = debug_info->views[i];
  568. p_info->act_area = 0;
  569. p_info->act_page = 0;
  570. p_info->act_entry = DEBUG_PROLOG_ENTRY;
  571. p_info->act_entry_offset = 0;
  572. file->private_data = p_info;
  573. debug_info_get(debug_info);
  574. out:
  575. up(&debug_lock);
  576. return rc;
  577. }
  578. /*
  579. * debug_close:
  580. * - called for user close()
  581. * - deletes private_data area of the file handle
  582. */
  583. static int
  584. debug_close(struct inode *inode, struct file *file)
  585. {
  586. file_private_info_t *p_info;
  587. p_info = (file_private_info_t *) file->private_data;
  588. if(p_info->debug_info_snap)
  589. debug_info_free(p_info->debug_info_snap);
  590. debug_info_put(p_info->debug_info_org);
  591. kfree(file->private_data);
  592. return 0; /* success */
  593. }
  594. /*
  595. * debug_register:
  596. * - creates and initializes debug area for the caller
  597. * - returns handle for debug area
  598. */
  599. debug_info_t*
  600. debug_register (char *name, int pages_per_area, int nr_areas, int buf_size)
  601. {
  602. debug_info_t *rc = NULL;
  603. if (!initialized)
  604. BUG();
  605. down(&debug_lock);
  606. /* create new debug_info */
  607. rc = debug_info_create(name, pages_per_area, nr_areas, buf_size);
  608. if(!rc)
  609. goto out;
  610. debug_register_view(rc, &debug_level_view);
  611. debug_register_view(rc, &debug_flush_view);
  612. debug_register_view(rc, &debug_pages_view);
  613. out:
  614. if (!rc){
  615. printk(KERN_ERR "debug: debug_register failed for %s\n",name);
  616. }
  617. up(&debug_lock);
  618. return rc;
  619. }
  620. /*
  621. * debug_unregister:
  622. * - give back debug area
  623. */
  624. void
  625. debug_unregister(debug_info_t * id)
  626. {
  627. if (!id)
  628. goto out;
  629. down(&debug_lock);
  630. debug_info_put(id);
  631. up(&debug_lock);
  632. out:
  633. return;
  634. }
  635. /*
  636. * debug_set_size:
  637. * - set area size (number of pages) and number of areas
  638. */
  639. static int
  640. debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area)
  641. {
  642. unsigned long flags;
  643. debug_entry_t *** new_areas;
  644. int rc=0;
  645. if(!id || (nr_areas <= 0) || (pages_per_area < 0))
  646. return -EINVAL;
  647. if(pages_per_area > 0){
  648. new_areas = debug_areas_alloc(pages_per_area, nr_areas);
  649. if(!new_areas) {
  650. printk(KERN_WARNING "debug: could not allocate memory "\
  651. "for pagenumber: %i\n",pages_per_area);
  652. rc = -ENOMEM;
  653. goto out;
  654. }
  655. } else {
  656. new_areas = NULL;
  657. }
  658. spin_lock_irqsave(&id->lock,flags);
  659. debug_areas_free(id);
  660. id->areas = new_areas;
  661. id->nr_areas = nr_areas;
  662. id->pages_per_area = pages_per_area;
  663. id->active_area = 0;
  664. memset(id->active_entries,0,sizeof(int)*id->nr_areas);
  665. memset(id->active_pages, 0, sizeof(int)*id->nr_areas);
  666. spin_unlock_irqrestore(&id->lock,flags);
  667. printk(KERN_INFO "debug: %s: set new size (%i pages)\n"\
  668. ,id->name, pages_per_area);
  669. out:
  670. return rc;
  671. }
  672. /*
  673. * debug_set_level:
  674. * - set actual debug level
  675. */
  676. void
  677. debug_set_level(debug_info_t* id, int new_level)
  678. {
  679. unsigned long flags;
  680. if(!id)
  681. return;
  682. spin_lock_irqsave(&id->lock,flags);
  683. if(new_level == DEBUG_OFF_LEVEL){
  684. id->level = DEBUG_OFF_LEVEL;
  685. printk(KERN_INFO "debug: %s: switched off\n",id->name);
  686. } else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
  687. printk(KERN_INFO
  688. "debug: %s: level %i is out of range (%i - %i)\n",
  689. id->name, new_level, 0, DEBUG_MAX_LEVEL);
  690. } else {
  691. id->level = new_level;
  692. }
  693. spin_unlock_irqrestore(&id->lock,flags);
  694. }
  695. /*
  696. * proceed_active_entry:
  697. * - set active entry to next in the ring buffer
  698. */
  699. static inline void
  700. proceed_active_entry(debug_info_t * id)
  701. {
  702. if ((id->active_entries[id->active_area] += id->entry_size)
  703. > (PAGE_SIZE - id->entry_size)){
  704. id->active_entries[id->active_area] = 0;
  705. id->active_pages[id->active_area] =
  706. (id->active_pages[id->active_area] + 1) %
  707. id->pages_per_area;
  708. }
  709. }
  710. /*
  711. * proceed_active_area:
  712. * - set active area to next in the ring buffer
  713. */
  714. static inline void
  715. proceed_active_area(debug_info_t * id)
  716. {
  717. id->active_area++;
  718. id->active_area = id->active_area % id->nr_areas;
  719. }
  720. /*
  721. * get_active_entry:
  722. */
  723. static inline debug_entry_t*
  724. get_active_entry(debug_info_t * id)
  725. {
  726. return (debug_entry_t *) (((char *) id->areas[id->active_area]
  727. [id->active_pages[id->active_area]]) +
  728. id->active_entries[id->active_area]);
  729. }
  730. /*
  731. * debug_finish_entry:
  732. * - set timestamp, caller address, cpu number etc.
  733. */
  734. static inline void
  735. debug_finish_entry(debug_info_t * id, debug_entry_t* active, int level,
  736. int exception)
  737. {
  738. active->id.stck = get_clock();
  739. active->id.fields.cpuid = smp_processor_id();
  740. active->caller = __builtin_return_address(0);
  741. active->id.fields.exception = exception;
  742. active->id.fields.level = level;
  743. proceed_active_entry(id);
  744. if(exception)
  745. proceed_active_area(id);
  746. }
  747. static int debug_stoppable=1;
  748. static int debug_active=1;
  749. #define CTL_S390DBF 5677
  750. #define CTL_S390DBF_STOPPABLE 5678
  751. #define CTL_S390DBF_ACTIVE 5679
  752. /*
  753. * proc handler for the running debug_active sysctl
  754. * always allow read, allow write only if debug_stoppable is set or
  755. * if debug_active is already off
  756. */
  757. static int
  758. s390dbf_procactive(ctl_table *table, int write, struct file *filp,
  759. void __user *buffer, size_t *lenp, loff_t *ppos)
  760. {
  761. if (!write || debug_stoppable || !debug_active)
  762. return proc_dointvec(table, write, filp, buffer, lenp, ppos);
  763. else
  764. return 0;
  765. }
  766. static struct ctl_table s390dbf_table[] = {
  767. {
  768. .ctl_name = CTL_S390DBF_STOPPABLE,
  769. .procname = "debug_stoppable",
  770. .data = &debug_stoppable,
  771. .maxlen = sizeof(int),
  772. .mode = S_IRUGO | S_IWUSR,
  773. .proc_handler = &proc_dointvec,
  774. .strategy = &sysctl_intvec,
  775. },
  776. {
  777. .ctl_name = CTL_S390DBF_ACTIVE,
  778. .procname = "debug_active",
  779. .data = &debug_active,
  780. .maxlen = sizeof(int),
  781. .mode = S_IRUGO | S_IWUSR,
  782. .proc_handler = &s390dbf_procactive,
  783. .strategy = &sysctl_intvec,
  784. },
  785. { .ctl_name = 0 }
  786. };
  787. static struct ctl_table s390dbf_dir_table[] = {
  788. {
  789. .ctl_name = CTL_S390DBF,
  790. .procname = "s390dbf",
  791. .maxlen = 0,
  792. .mode = S_IRUGO | S_IXUGO,
  793. .child = s390dbf_table,
  794. },
  795. { .ctl_name = 0 }
  796. };
  797. static struct ctl_table_header *s390dbf_sysctl_header;
  798. void
  799. debug_stop_all(void)
  800. {
  801. if (debug_stoppable)
  802. debug_active = 0;
  803. }
  804. /*
  805. * debug_event_common:
  806. * - write debug entry with given size
  807. */
  808. debug_entry_t*
  809. debug_event_common(debug_info_t * id, int level, const void *buf, int len)
  810. {
  811. unsigned long flags;
  812. debug_entry_t *active;
  813. if (!debug_active || !id->areas)
  814. return NULL;
  815. spin_lock_irqsave(&id->lock, flags);
  816. active = get_active_entry(id);
  817. memset(DEBUG_DATA(active), 0, id->buf_size);
  818. memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
  819. debug_finish_entry(id, active, level, 0);
  820. spin_unlock_irqrestore(&id->lock, flags);
  821. return active;
  822. }
  823. /*
  824. * debug_exception_common:
  825. * - write debug entry with given size and switch to next debug area
  826. */
  827. debug_entry_t
  828. *debug_exception_common(debug_info_t * id, int level, const void *buf, int len)
  829. {
  830. unsigned long flags;
  831. debug_entry_t *active;
  832. if (!debug_active || !id->areas)
  833. return NULL;
  834. spin_lock_irqsave(&id->lock, flags);
  835. active = get_active_entry(id);
  836. memset(DEBUG_DATA(active), 0, id->buf_size);
  837. memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
  838. debug_finish_entry(id, active, level, 1);
  839. spin_unlock_irqrestore(&id->lock, flags);
  840. return active;
  841. }
  842. /*
  843. * counts arguments in format string for sprintf view
  844. */
  845. static inline int
  846. debug_count_numargs(char *string)
  847. {
  848. int numargs=0;
  849. while(*string) {
  850. if(*string++=='%')
  851. numargs++;
  852. }
  853. return(numargs);
  854. }
  855. /*
  856. * debug_sprintf_event:
  857. */
  858. debug_entry_t*
  859. debug_sprintf_event(debug_info_t* id, int level,char *string,...)
  860. {
  861. va_list ap;
  862. int numargs,idx;
  863. unsigned long flags;
  864. debug_sprintf_entry_t *curr_event;
  865. debug_entry_t *active;
  866. if((!id) || (level > id->level))
  867. return NULL;
  868. if (!debug_active || !id->areas)
  869. return NULL;
  870. numargs=debug_count_numargs(string);
  871. spin_lock_irqsave(&id->lock, flags);
  872. active = get_active_entry(id);
  873. curr_event=(debug_sprintf_entry_t *) DEBUG_DATA(active);
  874. va_start(ap,string);
  875. curr_event->string=string;
  876. for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
  877. curr_event->args[idx]=va_arg(ap,long);
  878. va_end(ap);
  879. debug_finish_entry(id, active, level, 0);
  880. spin_unlock_irqrestore(&id->lock, flags);
  881. return active;
  882. }
  883. /*
  884. * debug_sprintf_exception:
  885. */
  886. debug_entry_t*
  887. debug_sprintf_exception(debug_info_t* id, int level,char *string,...)
  888. {
  889. va_list ap;
  890. int numargs,idx;
  891. unsigned long flags;
  892. debug_sprintf_entry_t *curr_event;
  893. debug_entry_t *active;
  894. if((!id) || (level > id->level))
  895. return NULL;
  896. if (!debug_active || !id->areas)
  897. return NULL;
  898. numargs=debug_count_numargs(string);
  899. spin_lock_irqsave(&id->lock, flags);
  900. active = get_active_entry(id);
  901. curr_event=(debug_sprintf_entry_t *)DEBUG_DATA(active);
  902. va_start(ap,string);
  903. curr_event->string=string;
  904. for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
  905. curr_event->args[idx]=va_arg(ap,long);
  906. va_end(ap);
  907. debug_finish_entry(id, active, level, 1);
  908. spin_unlock_irqrestore(&id->lock, flags);
  909. return active;
  910. }
  911. /*
  912. * debug_init:
  913. * - is called exactly once to initialize the debug feature
  914. */
  915. static int
  916. __init debug_init(void)
  917. {
  918. int rc = 0;
  919. s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table, 1);
  920. down(&debug_lock);
  921. debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT,NULL);
  922. printk(KERN_INFO "debug: Initialization complete\n");
  923. initialized = 1;
  924. up(&debug_lock);
  925. return rc;
  926. }
  927. /*
  928. * debug_register_view:
  929. */
  930. int
  931. debug_register_view(debug_info_t * id, struct debug_view *view)
  932. {
  933. int rc = 0;
  934. int i;
  935. unsigned long flags;
  936. mode_t mode = S_IFREG;
  937. struct dentry *pde;
  938. if (!id)
  939. goto out;
  940. if (view->prolog_proc || view->format_proc || view->header_proc)
  941. mode |= S_IRUSR;
  942. if (view->input_proc)
  943. mode |= S_IWUSR;
  944. pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry,
  945. id , &debug_file_ops);
  946. if (!pde){
  947. printk(KERN_WARNING "debug: debugfs_create_file() failed!"\
  948. " Cannot register view %s/%s\n", id->name,view->name);
  949. rc = -1;
  950. goto out;
  951. }
  952. spin_lock_irqsave(&id->lock, flags);
  953. for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
  954. if (!id->views[i])
  955. break;
  956. }
  957. if (i == DEBUG_MAX_VIEWS) {
  958. printk(KERN_WARNING "debug: cannot register view %s/%s\n",
  959. id->name,view->name);
  960. printk(KERN_WARNING
  961. "debug: maximum number of views reached (%i)!\n", i);
  962. debugfs_remove(pde);
  963. rc = -1;
  964. } else {
  965. id->views[i] = view;
  966. id->debugfs_entries[i] = pde;
  967. }
  968. spin_unlock_irqrestore(&id->lock, flags);
  969. out:
  970. return rc;
  971. }
  972. /*
  973. * debug_unregister_view:
  974. */
  975. int
  976. debug_unregister_view(debug_info_t * id, struct debug_view *view)
  977. {
  978. int rc = 0;
  979. int i;
  980. unsigned long flags;
  981. if (!id)
  982. goto out;
  983. spin_lock_irqsave(&id->lock, flags);
  984. for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
  985. if (id->views[i] == view)
  986. break;
  987. }
  988. if (i == DEBUG_MAX_VIEWS)
  989. rc = -1;
  990. else {
  991. debugfs_remove(id->debugfs_entries[i]);
  992. id->views[i] = NULL;
  993. rc = 0;
  994. }
  995. spin_unlock_irqrestore(&id->lock, flags);
  996. out:
  997. return rc;
  998. }
  999. static inline char *
  1000. debug_get_user_string(const char __user *user_buf, size_t user_len)
  1001. {
  1002. char* buffer;
  1003. buffer = kmalloc(user_len + 1, GFP_KERNEL);
  1004. if (!buffer)
  1005. return ERR_PTR(-ENOMEM);
  1006. if (copy_from_user(buffer, user_buf, user_len) != 0) {
  1007. kfree(buffer);
  1008. return ERR_PTR(-EFAULT);
  1009. }
  1010. /* got the string, now strip linefeed. */
  1011. if (buffer[user_len - 1] == '\n')
  1012. buffer[user_len - 1] = 0;
  1013. else
  1014. buffer[user_len] = 0;
  1015. return buffer;
  1016. }
  1017. static inline int
  1018. debug_get_uint(char *buf)
  1019. {
  1020. int rc;
  1021. for(; isspace(*buf); buf++);
  1022. rc = simple_strtoul(buf, &buf, 10);
  1023. if(*buf){
  1024. printk("debug: no integer specified!\n");
  1025. rc = -EINVAL;
  1026. }
  1027. return rc;
  1028. }
  1029. /*
  1030. * functions for debug-views
  1031. ***********************************
  1032. */
  1033. /*
  1034. * prints out actual debug level
  1035. */
  1036. static int
  1037. debug_prolog_pages_fn(debug_info_t * id,
  1038. struct debug_view *view, char *out_buf)
  1039. {
  1040. return sprintf(out_buf, "%i\n", id->pages_per_area);
  1041. }
  1042. /*
  1043. * reads new size (number of pages per debug area)
  1044. */
  1045. static int
  1046. debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
  1047. struct file *file, const char __user *user_buf,
  1048. size_t user_len, loff_t * offset)
  1049. {
  1050. char *str;
  1051. int rc,new_pages;
  1052. if (user_len > 0x10000)
  1053. user_len = 0x10000;
  1054. if (*offset != 0){
  1055. rc = -EPIPE;
  1056. goto out;
  1057. }
  1058. str = debug_get_user_string(user_buf,user_len);
  1059. if(IS_ERR(str)){
  1060. rc = PTR_ERR(str);
  1061. goto out;
  1062. }
  1063. new_pages = debug_get_uint(str);
  1064. if(new_pages < 0){
  1065. rc = -EINVAL;
  1066. goto free_str;
  1067. }
  1068. rc = debug_set_size(id,id->nr_areas, new_pages);
  1069. if(rc != 0){
  1070. rc = -EINVAL;
  1071. goto free_str;
  1072. }
  1073. rc = user_len;
  1074. free_str:
  1075. kfree(str);
  1076. out:
  1077. *offset += user_len;
  1078. return rc; /* number of input characters */
  1079. }
  1080. /*
  1081. * prints out actual debug level
  1082. */
  1083. static int
  1084. debug_prolog_level_fn(debug_info_t * id, struct debug_view *view, char *out_buf)
  1085. {
  1086. int rc = 0;
  1087. if(id->level == DEBUG_OFF_LEVEL) {
  1088. rc = sprintf(out_buf,"-\n");
  1089. }
  1090. else {
  1091. rc = sprintf(out_buf, "%i\n", id->level);
  1092. }
  1093. return rc;
  1094. }
  1095. /*
  1096. * reads new debug level
  1097. */
  1098. static int
  1099. debug_input_level_fn(debug_info_t * id, struct debug_view *view,
  1100. struct file *file, const char __user *user_buf,
  1101. size_t user_len, loff_t * offset)
  1102. {
  1103. char *str;
  1104. int rc,new_level;
  1105. if (user_len > 0x10000)
  1106. user_len = 0x10000;
  1107. if (*offset != 0){
  1108. rc = -EPIPE;
  1109. goto out;
  1110. }
  1111. str = debug_get_user_string(user_buf,user_len);
  1112. if(IS_ERR(str)){
  1113. rc = PTR_ERR(str);
  1114. goto out;
  1115. }
  1116. if(str[0] == '-'){
  1117. debug_set_level(id, DEBUG_OFF_LEVEL);
  1118. rc = user_len;
  1119. goto free_str;
  1120. } else {
  1121. new_level = debug_get_uint(str);
  1122. }
  1123. if(new_level < 0) {
  1124. printk(KERN_INFO "debug: level `%s` is not valid\n", str);
  1125. rc = -EINVAL;
  1126. } else {
  1127. debug_set_level(id, new_level);
  1128. rc = user_len;
  1129. }
  1130. free_str:
  1131. kfree(str);
  1132. out:
  1133. *offset += user_len;
  1134. return rc; /* number of input characters */
  1135. }
  1136. /*
  1137. * flushes debug areas
  1138. */
  1139. static void debug_flush(debug_info_t* id, int area)
  1140. {
  1141. unsigned long flags;
  1142. int i,j;
  1143. if(!id || !id->areas)
  1144. return;
  1145. spin_lock_irqsave(&id->lock,flags);
  1146. if(area == DEBUG_FLUSH_ALL){
  1147. id->active_area = 0;
  1148. memset(id->active_entries, 0, id->nr_areas * sizeof(int));
  1149. for (i = 0; i < id->nr_areas; i++) {
  1150. id->active_pages[i] = 0;
  1151. for(j = 0; j < id->pages_per_area; j++) {
  1152. memset(id->areas[i][j], 0, PAGE_SIZE);
  1153. }
  1154. }
  1155. printk(KERN_INFO "debug: %s: all areas flushed\n",id->name);
  1156. } else if(area >= 0 && area < id->nr_areas) {
  1157. id->active_entries[area] = 0;
  1158. id->active_pages[area] = 0;
  1159. for(i = 0; i < id->pages_per_area; i++) {
  1160. memset(id->areas[area][i],0,PAGE_SIZE);
  1161. }
  1162. printk(KERN_INFO "debug: %s: area %i has been flushed\n",
  1163. id->name, area);
  1164. } else {
  1165. printk(KERN_INFO
  1166. "debug: %s: area %i cannot be flushed (range: %i - %i)\n",
  1167. id->name, area, 0, id->nr_areas-1);
  1168. }
  1169. spin_unlock_irqrestore(&id->lock,flags);
  1170. }
  1171. /*
  1172. * view function: flushes debug areas
  1173. */
  1174. static int
  1175. debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
  1176. struct file *file, const char __user *user_buf,
  1177. size_t user_len, loff_t * offset)
  1178. {
  1179. char input_buf[1];
  1180. int rc = user_len;
  1181. if (user_len > 0x10000)
  1182. user_len = 0x10000;
  1183. if (*offset != 0){
  1184. rc = -EPIPE;
  1185. goto out;
  1186. }
  1187. if (copy_from_user(input_buf, user_buf, 1)){
  1188. rc = -EFAULT;
  1189. goto out;
  1190. }
  1191. if(input_buf[0] == '-') {
  1192. debug_flush(id, DEBUG_FLUSH_ALL);
  1193. goto out;
  1194. }
  1195. if (isdigit(input_buf[0])) {
  1196. int area = ((int) input_buf[0] - (int) '0');
  1197. debug_flush(id, area);
  1198. goto out;
  1199. }
  1200. printk(KERN_INFO "debug: area `%c` is not valid\n", input_buf[0]);
  1201. out:
  1202. *offset += user_len;
  1203. return rc; /* number of input characters */
  1204. }
  1205. /*
  1206. * prints debug header in raw format
  1207. */
  1208. static int
  1209. debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
  1210. int area, debug_entry_t * entry, char *out_buf)
  1211. {
  1212. int rc;
  1213. rc = sizeof(debug_entry_t);
  1214. memcpy(out_buf,entry,sizeof(debug_entry_t));
  1215. return rc;
  1216. }
  1217. /*
  1218. * prints debug data in raw format
  1219. */
  1220. static int
  1221. debug_raw_format_fn(debug_info_t * id, struct debug_view *view,
  1222. char *out_buf, const char *in_buf)
  1223. {
  1224. int rc;
  1225. rc = id->buf_size;
  1226. memcpy(out_buf, in_buf, id->buf_size);
  1227. return rc;
  1228. }
  1229. /*
  1230. * prints debug data in hex/ascii format
  1231. */
  1232. static int
  1233. debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
  1234. char *out_buf, const char *in_buf)
  1235. {
  1236. int i, rc = 0;
  1237. for (i = 0; i < id->buf_size; i++) {
  1238. rc += sprintf(out_buf + rc, "%02x ",
  1239. ((unsigned char *) in_buf)[i]);
  1240. }
  1241. rc += sprintf(out_buf + rc, "| ");
  1242. for (i = 0; i < id->buf_size; i++) {
  1243. unsigned char c = in_buf[i];
  1244. if (!isprint(c))
  1245. rc += sprintf(out_buf + rc, ".");
  1246. else
  1247. rc += sprintf(out_buf + rc, "%c", c);
  1248. }
  1249. rc += sprintf(out_buf + rc, "\n");
  1250. return rc;
  1251. }
  1252. /*
  1253. * prints header for debug entry
  1254. */
  1255. int
  1256. debug_dflt_header_fn(debug_info_t * id, struct debug_view *view,
  1257. int area, debug_entry_t * entry, char *out_buf)
  1258. {
  1259. struct timespec time_spec;
  1260. unsigned long long time;
  1261. char *except_str;
  1262. unsigned long caller;
  1263. int rc = 0;
  1264. unsigned int level;
  1265. level = entry->id.fields.level;
  1266. time = entry->id.stck;
  1267. /* adjust todclock to 1970 */
  1268. time -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
  1269. tod_to_timeval(time, &time_spec);
  1270. if (entry->id.fields.exception)
  1271. except_str = "*";
  1272. else
  1273. except_str = "-";
  1274. caller = ((unsigned long) entry->caller) & PSW_ADDR_INSN;
  1275. rc += sprintf(out_buf, "%02i %011lu:%06lu %1u %1s %02i %p ",
  1276. area, time_spec.tv_sec, time_spec.tv_nsec / 1000, level,
  1277. except_str, entry->id.fields.cpuid, (void *) caller);
  1278. return rc;
  1279. }
  1280. /*
  1281. * prints debug data sprintf-formated:
  1282. * debug_sprinf_event/exception calls must be used together with this view
  1283. */
  1284. #define DEBUG_SPRINTF_MAX_ARGS 10
  1285. static int
  1286. debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
  1287. char *out_buf, debug_sprintf_entry_t *curr_event)
  1288. {
  1289. int num_longs, num_used_args = 0,i, rc = 0;
  1290. int index[DEBUG_SPRINTF_MAX_ARGS];
  1291. /* count of longs fit into one entry */
  1292. num_longs = id->buf_size / sizeof(long);
  1293. if(num_longs < 1)
  1294. goto out; /* bufsize of entry too small */
  1295. if(num_longs == 1) {
  1296. /* no args, we use only the string */
  1297. strcpy(out_buf, curr_event->string);
  1298. rc = strlen(curr_event->string);
  1299. goto out;
  1300. }
  1301. /* number of arguments used for sprintf (without the format string) */
  1302. num_used_args = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
  1303. memset(index,0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
  1304. for(i = 0; i < num_used_args; i++)
  1305. index[i] = i;
  1306. rc = sprintf(out_buf, curr_event->string, curr_event->args[index[0]],
  1307. curr_event->args[index[1]], curr_event->args[index[2]],
  1308. curr_event->args[index[3]], curr_event->args[index[4]],
  1309. curr_event->args[index[5]], curr_event->args[index[6]],
  1310. curr_event->args[index[7]], curr_event->args[index[8]],
  1311. curr_event->args[index[9]]);
  1312. out:
  1313. return rc;
  1314. }
  1315. /*
  1316. * clean up module
  1317. */
  1318. static void __exit debug_exit(void)
  1319. {
  1320. debugfs_remove(debug_debugfs_root_entry);
  1321. unregister_sysctl_table(s390dbf_sysctl_header);
  1322. return;
  1323. }
  1324. /*
  1325. * module definitions
  1326. */
  1327. postcore_initcall(debug_init);
  1328. module_exit(debug_exit);
  1329. MODULE_LICENSE("GPL");
  1330. EXPORT_SYMBOL(debug_register);
  1331. EXPORT_SYMBOL(debug_unregister);
  1332. EXPORT_SYMBOL(debug_set_level);
  1333. EXPORT_SYMBOL(debug_stop_all);
  1334. EXPORT_SYMBOL(debug_register_view);
  1335. EXPORT_SYMBOL(debug_unregister_view);
  1336. EXPORT_SYMBOL(debug_event_common);
  1337. EXPORT_SYMBOL(debug_exception_common);
  1338. EXPORT_SYMBOL(debug_hex_ascii_view);
  1339. EXPORT_SYMBOL(debug_raw_view);
  1340. EXPORT_SYMBOL(debug_dflt_header_fn);
  1341. EXPORT_SYMBOL(debug_sprintf_view);
  1342. EXPORT_SYMBOL(debug_sprintf_exception);
  1343. EXPORT_SYMBOL(debug_sprintf_event);