^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * File Attributes for Zorro Devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2003 Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Loosely based on drivers/pci/pci-sysfs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * License. See the file COPYING in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/zorro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "zorro.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* show configuration fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define zorro_config_attr(name, field, format_string) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static ssize_t name##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct zorro_dev *z; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) z = to_zorro_dev(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return sprintf(buf, format_string, z->field); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static DEVICE_ATTR_RO(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) zorro_config_attr(id, id, "0x%08x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) zorro_config_attr(type, rom.er_Type, "0x%02x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) zorro_config_attr(slotsize, slotsize, "0x%04x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct zorro_dev *z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) z = to_zorro_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static DEVICE_ATTR_RO(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct zorro_dev *z = to_zorro_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) (unsigned long)zorro_resource_start(z),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) (unsigned long)zorro_resource_end(z),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) zorro_resource_flags(z));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static DEVICE_ATTR_RO(resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct zorro_dev *z = to_zorro_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static DEVICE_ATTR_RO(modalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static struct attribute *zorro_device_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) &dev_attr_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) &dev_attr_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) &dev_attr_serial.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) &dev_attr_slotaddr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) &dev_attr_slotsize.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) &dev_attr_resource.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) &dev_attr_modalias.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct bin_attribute *bin_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) char *buf, loff_t off, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct ConfigDev cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* Construct a ConfigDev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) memset(&cd, 0, sizeof(cd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) cd.cd_Rom = z->rom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) cd.cd_SlotSize = cpu_to_be16(z->slotsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static struct bin_attribute zorro_config_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .name = "config",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .mode = S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .size = sizeof(struct ConfigDev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .read = zorro_read_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static struct bin_attribute *zorro_device_bin_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) &zorro_config_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static const struct attribute_group zorro_device_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .attrs = zorro_device_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .bin_attrs = zorro_device_bin_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) const struct attribute_group *zorro_device_attribute_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) &zorro_device_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };