/alps/bar_resolve

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/bar_resolve

« back to all changes in this revision

Viewing changes to sysfs.c

  • Committer: Suren A. Chilingaryan
  • Date: 2016-03-02 05:45:24 UTC
  • Revision ID: csa@suren.me-20160302054524-aqefho92o0ljk3eh
Test application for resolving user-space BAR addresses

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
10
#include "mod.h"
 
11
#include "dev.h"
 
12
#include "debug.h"
 
13
 
 
14
#include "rdma.h"
 
15
 
 
16
static ssize_t test_request_show(struct device *dev, struct device_attribute *attr, char *buf) {
 
17
    test_dev_t *test = dev_get_drvdata(dev);
 
18
 
 
19
    return sprintf(buf, "%lx\n", test->addr);
 
20
}
 
21
 
 
22
static ssize_t test_request_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) {
 
23
    unsigned long ua;
 
24
 
 
25
    test_dev_t *test = dev_get_drvdata(dev);
 
26
 
 
27
    if (sscanf(buf, "%lx", &ua) != 1) {
 
28
        mod_info("Error processing request\n");
 
29
        return 0;
 
30
    }
 
31
 
 
32
    test->addr = pcidriver_resolve_bar(ua);
 
33
 
 
34
    return count;
 
35
}
 
36
 
 
37
static DEVICE_ATTR(test_request, 0664, test_request_show, test_request_store);
 
38
 
 
39
 
 
40
 
 
41
int test_sysfs_init(test_dev_t *dev) {
 
42
    int err;
 
43
 
 
44
    err = device_create_file(dev->dev, &dev_attr_test_request);
 
45
 
 
46
    return err;
 
47
}
 
48
 
 
49
void test_sysfs_free(test_dev_t *dev) {
 
50
    device_remove_file(dev->dev, &dev_attr_test_request);
 
51
}