Blame view

kernel/linux-imx6_3.14.28/drivers/misc/mei/debugfs.c 3.48 KB
6b13f685e   김민수   BSP 최초 추가
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  /*
   *
   * Intel Management Engine Interface (Intel MEI) Linux driver
   * Copyright (c) 2012-2013, Intel Corporation.
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms and conditions of the GNU General Public License,
   * version 2, as published by the Free Software Foundation.
   *
   * This program is distributed in the hope it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   * more details.
   *
   */
  #include <linux/slab.h>
  #include <linux/kernel.h>
  #include <linux/device.h>
  #include <linux/debugfs.h>
  #include <linux/pci.h>
  
  #include <linux/mei.h>
  
  #include "mei_dev.h"
  #include "hw.h"
  
  static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
  					size_t cnt, loff_t *ppos)
  {
  	struct mei_device *dev = fp->private_data;
  	struct mei_me_client *cl;
  	const size_t bufsz = 1024;
  	char *buf = kzalloc(bufsz, GFP_KERNEL);
  	int i;
  	int pos = 0;
  	int ret;
  
  	if  (!buf)
  		return -ENOMEM;
  
  	pos += scnprintf(buf + pos, bufsz - pos,
  			"  |id|addr|         UUID                       |con|msg len|
  ");
  
  	mutex_lock(&dev->device_lock);
  
  	/*  if the driver is not enabled the list won't be consistent */
  	if (dev->dev_state != MEI_DEV_ENABLED)
  		goto out;
  
  	for (i = 0; i < dev->me_clients_num; i++) {
  		cl = &dev->me_clients[i];
  
  		/* skip me clients that cannot be connected */
  		if (cl->props.max_number_of_connections == 0)
  			continue;
  
  		pos += scnprintf(buf + pos, bufsz - pos,
  			"%2d|%2d|%4d|%pUl|%3d|%7d|
  ",
  			i, cl->client_id,
  			cl->props.fixed_address,
  			&cl->props.protocol_name,
  			cl->props.max_number_of_connections,
  			cl->props.max_msg_length);
  	}
  out:
  	mutex_unlock(&dev->device_lock);
  	ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  	kfree(buf);
  	return ret;
  }
  
  static const struct file_operations mei_dbgfs_fops_meclients = {
  	.open = simple_open,
  	.read = mei_dbgfs_read_meclients,
  	.llseek = generic_file_llseek,
  };
  
  static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf,
  					size_t cnt, loff_t *ppos)
  {
  	struct mei_device *dev = fp->private_data;
  	const size_t bufsz = 1024;
  	char *buf = kzalloc(bufsz, GFP_KERNEL);
  	int pos = 0;
  	int ret;
  
  	if  (!buf)
  		return -ENOMEM;
  
  	pos += scnprintf(buf + pos, bufsz - pos, "%s
  ",
  			mei_dev_state_str(dev->dev_state));
  	ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
  	kfree(buf);
  	return ret;
  }
  static const struct file_operations mei_dbgfs_fops_devstate = {
  	.open = simple_open,
  	.read = mei_dbgfs_read_devstate,
  	.llseek = generic_file_llseek,
  };
  
  /**
   * mei_dbgfs_deregister - Remove the debugfs files and directories
   * @mei - pointer to mei device private data
   */
  void mei_dbgfs_deregister(struct mei_device *dev)
  {
  	if (!dev->dbgfs_dir)
  		return;
  	debugfs_remove_recursive(dev->dbgfs_dir);
  	dev->dbgfs_dir = NULL;
  }
  
  /**
   * Add the debugfs files
   *
   */
  int mei_dbgfs_register(struct mei_device *dev, const char *name)
  {
  	struct dentry *dir, *f;
  	dir = debugfs_create_dir(name, NULL);
  	if (!dir)
  		return -ENOMEM;
  
  	f = debugfs_create_file("meclients", S_IRUSR, dir,
  				dev, &mei_dbgfs_fops_meclients);
  	if (!f) {
  		dev_err(&dev->pdev->dev, "meclients: registration failed
  ");
  		goto err;
  	}
  	f = debugfs_create_file("devstate", S_IRUSR, dir,
  				dev, &mei_dbgfs_fops_devstate);
  	if (!f) {
  		dev_err(&dev->pdev->dev, "devstate: registration failed
  ");
  		goto err;
  	}
  	dev->dbgfs_dir = dir;
  	return 0;
  err:
  	mei_dbgfs_deregister(dev);
  	return -ENODEV;
  }