bzr branch
http://darksoft.org/webbzr/alps/bar_resolve
1
by Suren A. Chilingaryan
Test application for resolving user-space BAR addresses |
1 |
#include <linux/init.h> |
2 |
#include <linux/module.h> |
|
3 |
#include <linux/device.h> |
|
4 |
#include <linux/types.h> |
|
5 |
#include <linux/cdev.h> |
|
6 |
#include <linux/fs.h> |
|
7 |
#include <linux/slab.h> |
|
8 |
#include <linux/sysfs.h> |
|
9 |
||
2
by Suren A. Chilingaryan
Finalyze the sample |
10 |
#include <linux/pcidriver.h> |
11 |
||
1
by Suren A. Chilingaryan
Test application for resolving user-space BAR addresses |
12 |
#include "mod.h" |
13 |
#include "dev.h" |
|
14 |
#include "debug.h" |
|
15 |
||
16 |
||
17 |
static ssize_t test_request_show(struct device *dev, struct device_attribute *attr, char *buf) { |
|
18 |
test_dev_t *test = dev_get_drvdata(dev); |
|
19 |
||
20 |
return sprintf(buf, "%lx\n", test->addr); |
|
21 |
}
|
|
22 |
||
23 |
static ssize_t test_request_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { |
|
24 |
unsigned long ua; |
|
25 |
||
26 |
test_dev_t *test = dev_get_drvdata(dev); |
|
27 |
||
28 |
if (sscanf(buf, "%lx", &ua) != 1) { |
|
29 |
mod_info("Error processing request\n"); |
|
30 |
return 0; |
|
31 |
}
|
|
32 |
||
33 |
test->addr = pcidriver_resolve_bar(ua); |
|
34 |
||
35 |
return count; |
|
36 |
}
|
|
37 |
||
38 |
static DEVICE_ATTR(test_request, 0664, test_request_show, test_request_store); |
|
39 |
||
40 |
||
41 |
||
42 |
int test_sysfs_init(test_dev_t *dev) { |
|
43 |
int err; |
|
44 |
||
45 |
err = device_create_file(dev->dev, &dev_attr_test_request); |
|
46 |
||
47 |
return err; |
|
48 |
}
|
|
49 |
||
50 |
void test_sysfs_free(test_dev_t *dev) { |
|
51 |
device_remove_file(dev->dev, &dev_attr_test_request); |
|
52 |
}
|