]>
Commit | Line | Data |
---|---|---|
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 | 18 | |
bd9ba8f4 GU |
19 | #include <asm/byteorder.h> |
20 | ||
1da177e4 LT |
21 | #include "zorro.h" |
22 | ||
23 | ||
24 | /* show configuration fields */ | |
25 | #define zorro_config_attr(name, field, format_string) \ | |
87e715de DT |
26 | static ssize_t name##_show(struct device *dev, \ |
27 | struct device_attribute *attr, char *buf) \ | |
1da177e4 LT |
28 | { \ |
29 | struct zorro_dev *z; \ | |
30 | \ | |
31 | z = to_zorro_dev(dev); \ | |
32 | return sprintf(buf, format_string, z->field); \ | |
33 | } \ | |
87e715de | 34 | static DEVICE_ATTR_RO(name); |
1da177e4 LT |
35 | |
36 | zorro_config_attr(id, id, "0x%08x\n"); | |
37 | zorro_config_attr(type, rom.er_Type, "0x%02x\n"); | |
1da177e4 LT |
38 | zorro_config_attr(slotaddr, slotaddr, "0x%04x\n"); |
39 | zorro_config_attr(slotsize, slotsize, "0x%04x\n"); | |
40 | ||
87e715de DT |
41 | static ssize_t serial_show(struct device *dev, struct device_attribute *attr, |
42 | char *buf) | |
bd9ba8f4 GU |
43 | { |
44 | struct zorro_dev *z; | |
45 | ||
46 | z = to_zorro_dev(dev); | |
47 | return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber)); | |
48 | } | |
87e715de | 49 | static DEVICE_ATTR_RO(serial); |
bd9ba8f4 | 50 | |
87e715de DT |
51 | static ssize_t resource_show(struct device *dev, struct device_attribute *attr, |
52 | char *buf) | |
1da177e4 LT |
53 | { |
54 | struct zorro_dev *z = to_zorro_dev(dev); | |
55 | ||
56 | return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n", | |
31817576 GU |
57 | (unsigned long)zorro_resource_start(z), |
58 | (unsigned long)zorro_resource_end(z), | |
1da177e4 LT |
59 | zorro_resource_flags(z)); |
60 | } | |
87e715de DT |
61 | static DEVICE_ATTR_RO(resource); |
62 | ||
63 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, | |
64 | char *buf) | |
65 | { | |
66 | struct zorro_dev *z = to_zorro_dev(dev); | |
1da177e4 | 67 | |
87e715de DT |
68 | return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); |
69 | } | |
70 | static DEVICE_ATTR_RO(modalias); | |
71 | ||
72 | static struct attribute *zorro_device_attrs[] = { | |
73 | &dev_attr_id.attr, | |
74 | &dev_attr_type.attr, | |
75 | &dev_attr_serial.attr, | |
76 | &dev_attr_slotaddr.attr, | |
77 | &dev_attr_slotsize.attr, | |
78 | &dev_attr_resource.attr, | |
79 | &dev_attr_modalias.attr, | |
80 | NULL | |
81 | }; | |
1da177e4 | 82 | |
2c3c8bea | 83 | static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, |
91a69029 ZR |
84 | struct bin_attribute *bin_attr, |
85 | char *buf, loff_t off, size_t count) | |
1da177e4 | 86 | { |
a9c9d9ac | 87 | struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj)); |
1da177e4 | 88 | struct ConfigDev cd; |
1da177e4 LT |
89 | |
90 | /* Construct a ConfigDev */ | |
91 | memset(&cd, 0, sizeof(cd)); | |
92 | cd.cd_Rom = z->rom; | |
bd9ba8f4 GU |
93 | cd.cd_SlotAddr = cpu_to_be16(z->slotaddr); |
94 | cd.cd_SlotSize = cpu_to_be16(z->slotsize); | |
95 | cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z)); | |
96 | cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z)); | |
1da177e4 | 97 | |
fa7f2893 | 98 | return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd)); |
1da177e4 LT |
99 | } |
100 | ||
101 | static struct bin_attribute zorro_config_attr = { | |
102 | .attr = { | |
103 | .name = "config", | |
a0108668 | 104 | .mode = S_IRUGO, |
1da177e4 LT |
105 | }, |
106 | .size = sizeof(struct ConfigDev), | |
107 | .read = zorro_read_config, | |
108 | }; | |
109 | ||
87e715de DT |
110 | static struct bin_attribute *zorro_device_bin_attrs[] = { |
111 | &zorro_config_attr, | |
112 | NULL | |
113 | }; | |
bf54a2b3 | 114 | |
87e715de DT |
115 | static const struct attribute_group zorro_device_attr_group = { |
116 | .attrs = zorro_device_attrs, | |
117 | .bin_attrs = zorro_device_bin_attrs, | |
118 | }; | |
1da177e4 | 119 | |
87e715de DT |
120 | const struct attribute_group *zorro_device_attribute_groups[] = { |
121 | &zorro_device_attr_group, | |
122 | NULL | |
123 | }; |