ip22-gio.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * ip22-gio.c: Support for GIO64 bus (inspired by PCI code)
  3.  *
  4.  * Copyright (C) 2002 Ladislav Michl
  5.  */
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/slab.h>
  9. #include <linux/init.h>
  10. #include <linux/proc_fs.h>
  11. #include <asm/addrspace.h>
  12. #include <asm/sgi/sgimc.h>
  13. #include <asm/sgi/sgigio.h>
  14. #define GIO_PIO_MAP_BASE 0x1f000000L
  15. #define GIO_PIO_MAP_SIZE (16 * 1024*1024)
  16. #define GIO_ADDR_GFX 0x1f000000L
  17. #define GIO_ADDR_GIO1 0x1f400000L
  18. #define GIO_ADDR_GIO2 0x1f600000L
  19. #define GIO_GFX_MAP_SIZE (4 * 1024*1024)
  20. #define GIO_GIO1_MAP_SIZE (2 * 1024*1024)
  21. #define GIO_GIO2_MAP_SIZE (4 * 1024*1024)
  22. #define GIO_NO_DEVICE 0x80
  23. static struct gio_dev gio_slot[GIO_NUM_SLOTS] = {
  24. {
  25. 0,
  26. 0,
  27. 0,
  28. GIO_NO_DEVICE,
  29. GIO_SLOT_GFX,
  30. GIO_ADDR_GFX,
  31. GIO_GFX_MAP_SIZE,
  32. NULL,
  33. "GFX"
  34. },
  35. {
  36. 0,
  37. 0,
  38. 0,
  39. GIO_NO_DEVICE,
  40. GIO_SLOT_GIO1,
  41. GIO_ADDR_GIO1,
  42. GIO_GIO1_MAP_SIZE,
  43. NULL,
  44. "EXP0"
  45. },
  46. {
  47. 0,
  48. 0,
  49. 0,
  50. GIO_NO_DEVICE,
  51. GIO_SLOT_GIO2,
  52. GIO_ADDR_GIO2,
  53. GIO_GIO2_MAP_SIZE,
  54. NULL,
  55. "EXP1"
  56. }
  57. };
  58. static int gio_read_proc(char *buf, char **start, off_t off,
  59.  int count, int *eof, void *data)
  60. {
  61. int i;
  62. char *p = buf;
  63. p += sprintf(p, "GIO devices found:n");
  64. for (i = 0; i < GIO_NUM_SLOTS; i++) {
  65. if (gio_slot[i].flags & GIO_NO_DEVICE)
  66. continue;
  67. p += sprintf(p, "  Slot %s, DeviceId 0x%02xn",
  68.      gio_slot[i].slot_name, gio_slot[i].device);
  69. p += sprintf(p, "    BaseAddr 0x%08lx, MapSize 0x%08xn",
  70.      gio_slot[i].base_addr, gio_slot[i].map_size);
  71. }
  72. return p - buf;
  73. }
  74. void create_gio_proc_entry(void)
  75. {
  76. create_proc_read_entry("gio", 0, NULL, gio_read_proc, NULL);
  77. }
  78. /**
  79.  * gio_find_device - begin or continue searching for a GIO device by device id
  80.  * @device: GIO device id to match, or %GIO_ANY_ID to match all device ids
  81.  * @from: Previous GIO device found in search, or %NULL for new search.
  82.  *
  83.  * Iterates through the list of known GIO devices. If a GIO device is found
  84.  * with a matching @device, a pointer to its device structure is returned.
  85.  * Otherwise, %NULL is returned.
  86.  * A new search is initiated by passing %NULL to the @from argument.
  87.  * Otherwise if @from is not %NULL, searches continue from next device.
  88.  */
  89. struct gio_dev *
  90. gio_find_device(unsigned char device, const struct gio_dev *from)
  91. {
  92. int i;
  93. for (i = (from) ? from->slot_number : 0; i < GIO_NUM_SLOTS; i++)
  94. if (!(gio_slot[i].flags & GIO_NO_DEVICE) &&
  95.    (device == GIO_ANY_ID || device == gio_slot[i].device))
  96. return &gio_slot[i];
  97. return NULL;
  98. }
  99. #define GIO_IDCODE(x) (x & 0x7f)
  100. #define GIO_ALL_BITS_VALID 0x80
  101. #define GIO_REV(x) ((x >> 8) & 0xff)
  102. #define GIO_GIO_SIZE_64 0x10000
  103. #define GIO_ROM_PRESENT 0x20000
  104. #define GIO_VENDOR_CODE(x) ((x >> 18) & 0x3fff)
  105. extern int ip22_baddr(unsigned int *val, unsigned long addr);
  106. /**
  107.  * sgigio_init - scan the GIO space and figure out what hardware is actually
  108.  * present.
  109.  */
  110. void __init sgigio_init(void)
  111. {
  112. unsigned int i, id, found = 0;
  113. printk("GIO: Scanning for GIO cards...n");
  114. for (i = 0; i < GIO_NUM_SLOTS; i++) {
  115. if (ip22_baddr(&id, KSEG1ADDR(gio_slot[i].base_addr)))
  116. continue;
  117. found = 1;
  118. gio_slot[i].device = GIO_IDCODE(id);
  119. if (id & GIO_ALL_BITS_VALID) {
  120. gio_slot[i].revision = GIO_REV(id);
  121. gio_slot[i].vendor = GIO_VENDOR_CODE(id);
  122. gio_slot[i].flags =
  123. (id & GIO_GIO_SIZE_64) ? GIO_IFACE_64 : 0 |
  124. (id & GIO_ROM_PRESENT) ? GIO_HAS_ROM : 0;
  125. } else
  126. gio_slot[i].flags = GIO_VALID_ID_ONLY;
  127. printk("GIO: Card 0x%02x @ 0x%08lxn", gio_slot[i].device,
  128. gio_slot[i].base_addr);
  129. }
  130. if (!found)
  131. printk("GIO: No GIO cards present.n");
  132. }