Chris Wilson | b98bade | 2013-08-20 21:39:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | */ |
| 24 | |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 25 | #include <sys/stat.h> |
| 26 | #include <sys/mount.h> |
| 27 | #include <errno.h> |
Chris Wilson | 9574cb1 | 2013-08-23 15:51:21 +0100 | [diff] [blame^] | 28 | #include <stdio.h> |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 29 | |
| 30 | #include "debugfs.h" |
| 31 | |
Chris Wilson | 9574cb1 | 2013-08-23 15:51:21 +0100 | [diff] [blame^] | 32 | char debugfs_path[128]; |
| 33 | |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 34 | int debugfs_init(void) |
| 35 | { |
Chris Wilson | 9574cb1 | 2013-08-23 15:51:21 +0100 | [diff] [blame^] | 36 | const char *path = "/sys/kernel/debug"; |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 37 | struct stat st; |
Chris Wilson | 9574cb1 | 2013-08-23 15:51:21 +0100 | [diff] [blame^] | 38 | int n; |
| 39 | |
| 40 | if (stat("/debug/dri", &st) == 0) { |
| 41 | path = "/debug/dri"; |
| 42 | goto find_minor; |
| 43 | } |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 44 | |
| 45 | if (stat("/sys/kernel/debug/dri", &st) == 0) |
Chris Wilson | 9574cb1 | 2013-08-23 15:51:21 +0100 | [diff] [blame^] | 46 | goto find_minor; |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 47 | |
| 48 | if (stat("/sys/kernel/debug", &st)) |
| 49 | return errno; |
| 50 | |
| 51 | if (mount("debug", "/sys/kernel/debug", "debugfs", 0, 0)) |
| 52 | return errno; |
| 53 | |
Chris Wilson | 9574cb1 | 2013-08-23 15:51:21 +0100 | [diff] [blame^] | 54 | find_minor: |
| 55 | for (n = 0; n < 16; n++) { |
| 56 | int len = sprintf(debugfs_path, "%s/dri/%d", path, n); |
| 57 | sprintf(debugfs_path + len, "/i915_error_state"); |
| 58 | if (stat(debugfs_path, &st) == 0) { |
| 59 | debugfs_path[len] = '\0'; |
| 60 | return 0; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | debugfs_path[0] = '\0'; |
| 65 | return ENOENT; |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 66 | } |