]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/zorro/zorro-sysfs.c
sysfs: make directory dentries and inodes reclaimable
[mirror_ubuntu-zesty-kernel.git] / drivers / zorro / zorro-sysfs.c
CommitLineData
1da177e4
LT
1/*
2 * File Attributes for Zorro Devices
3 *
4 * Copyright (C) 2003 Geert Uytterhoeven
5 *
6 * Loosely based on drivers/pci/pci-sysfs.c
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
11 */
12
13
14#include <linux/kernel.h>
15#include <linux/zorro.h>
16#include <linux/stat.h>
4e57b681 17#include <linux/string.h>
1da177e4
LT
18
19#include "zorro.h"
20
21
22/* show configuration fields */
23#define zorro_config_attr(name, field, format_string) \
24static ssize_t \
060b8845 25show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
26{ \
27 struct zorro_dev *z; \
28 \
29 z = to_zorro_dev(dev); \
30 return sprintf(buf, format_string, z->field); \
31} \
32static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
33
34zorro_config_attr(id, id, "0x%08x\n");
35zorro_config_attr(type, rom.er_Type, "0x%02x\n");
36zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x\n");
37zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
38zorro_config_attr(slotsize, slotsize, "0x%04x\n");
39
060b8845 40static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
41{
42 struct zorro_dev *z = to_zorro_dev(dev);
43
44 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
31817576
GU
45 (unsigned long)zorro_resource_start(z),
46 (unsigned long)zorro_resource_end(z),
1da177e4
LT
47 zorro_resource_flags(z));
48}
49
50static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
51
52static ssize_t zorro_read_config(struct kobject *kobj, char *buf, loff_t off,
53 size_t count)
54{
55 struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
56 kobj));
57 struct ConfigDev cd;
58 unsigned int size = sizeof(cd);
59
60 if (off > size)
61 return 0;
62 if (off+count > size)
63 count = size-off;
64
65 /* Construct a ConfigDev */
66 memset(&cd, 0, sizeof(cd));
67 cd.cd_Rom = z->rom;
68 cd.cd_SlotAddr = z->slotaddr;
69 cd.cd_SlotSize = z->slotsize;
70 cd.cd_BoardAddr = (void *)zorro_resource_start(z);
71 cd.cd_BoardSize = zorro_resource_len(z);
72
73 memcpy(buf, (void *)&cd+off, count);
74 return count;
75}
76
77static struct bin_attribute zorro_config_attr = {
78 .attr = {
79 .name = "config",
80 .mode = S_IRUGO | S_IWUSR,
1da177e4
LT
81 },
82 .size = sizeof(struct ConfigDev),
83 .read = zorro_read_config,
84};
85
86void zorro_create_sysfs_dev_files(struct zorro_dev *z)
87{
88 struct device *dev = &z->dev;
89
90 /* current configuration's attributes */
91 device_create_file(dev, &dev_attr_id);
92 device_create_file(dev, &dev_attr_type);
93 device_create_file(dev, &dev_attr_serial);
94 device_create_file(dev, &dev_attr_slotaddr);
95 device_create_file(dev, &dev_attr_slotsize);
96 device_create_file(dev, &dev_attr_resource);
97 sysfs_create_bin_file(&dev->kobj, &zorro_config_attr);
98}
99