zorro-sysfs.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #include <linux/kernel.h>
  13. #include <linux/zorro.h>
  14. #include <linux/stat.h>
  15. #include <linux/string.h>
  16. #include "zorro.h"
  17. /* show configuration fields */
  18. #define zorro_config_attr(name, field, format_string) \
  19. static ssize_t \
  20. show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  21. { \
  22. struct zorro_dev *z; \
  23. \
  24. z = to_zorro_dev(dev); \
  25. return sprintf(buf, format_string, z->field); \
  26. } \
  27. static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
  28. zorro_config_attr(id, id, "0x%08x\n");
  29. zorro_config_attr(type, rom.er_Type, "0x%02x\n");
  30. zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x\n");
  31. zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
  32. zorro_config_attr(slotsize, slotsize, "0x%04x\n");
  33. static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
  34. {
  35. struct zorro_dev *z = to_zorro_dev(dev);
  36. return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
  37. (unsigned long)zorro_resource_start(z),
  38. (unsigned long)zorro_resource_end(z),
  39. zorro_resource_flags(z));
  40. }
  41. static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
  42. static ssize_t zorro_read_config(struct kobject *kobj, char *buf, loff_t off,
  43. size_t count)
  44. {
  45. struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
  46. kobj));
  47. struct ConfigDev cd;
  48. unsigned int size = sizeof(cd);
  49. if (off > size)
  50. return 0;
  51. if (off+count > size)
  52. count = size-off;
  53. /* Construct a ConfigDev */
  54. memset(&cd, 0, sizeof(cd));
  55. cd.cd_Rom = z->rom;
  56. cd.cd_SlotAddr = z->slotaddr;
  57. cd.cd_SlotSize = z->slotsize;
  58. cd.cd_BoardAddr = (void *)zorro_resource_start(z);
  59. cd.cd_BoardSize = zorro_resource_len(z);
  60. memcpy(buf, (void *)&cd+off, count);
  61. return count;
  62. }
  63. static struct bin_attribute zorro_config_attr = {
  64. .attr = {
  65. .name = "config",
  66. .mode = S_IRUGO | S_IWUSR,
  67. .owner = THIS_MODULE
  68. },
  69. .size = sizeof(struct ConfigDev),
  70. .read = zorro_read_config,
  71. };
  72. void zorro_create_sysfs_dev_files(struct zorro_dev *z)
  73. {
  74. struct device *dev = &z->dev;
  75. /* current configuration's attributes */
  76. device_create_file(dev, &dev_attr_id);
  77. device_create_file(dev, &dev_attr_type);
  78. device_create_file(dev, &dev_attr_serial);
  79. device_create_file(dev, &dev_attr_slotaddr);
  80. device_create_file(dev, &dev_attr_slotsize);
  81. device_create_file(dev, &dev_attr_resource);
  82. sysfs_create_bin_file(&dev->kobj, &zorro_config_attr);
  83. }