zorro-sysfs.c 2.6 KB

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