vio.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * IBM PowerPC iSeries Virtual I/O Infrastructure Support.
  3. *
  4. * Copyright (c) 2005 Stephen Rothwell, IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/device.h>
  13. #include <linux/init.h>
  14. #include <asm/vio.h>
  15. #include <asm/iommu.h>
  16. #include <asm/tce.h>
  17. #include <asm/abs_addr.h>
  18. #include <asm/page.h>
  19. #include <asm/iseries/vio.h>
  20. #include <asm/iseries/hv_types.h>
  21. #include <asm/iseries/hv_lp_config.h>
  22. #include <asm/iseries/hv_call_xm.h>
  23. struct device *iSeries_vio_dev = &vio_bus_device.dev;
  24. EXPORT_SYMBOL(iSeries_vio_dev);
  25. static struct iommu_table veth_iommu_table;
  26. static struct iommu_table vio_iommu_table;
  27. static void __init iommu_vio_init(void)
  28. {
  29. struct iommu_table *t;
  30. struct iommu_table_cb cb;
  31. unsigned long cbp;
  32. unsigned long itc_entries;
  33. cb.itc_busno = 255; /* Bus 255 is the virtual bus */
  34. cb.itc_virtbus = 0xff; /* Ask for virtual bus */
  35. cbp = virt_to_abs(&cb);
  36. HvCallXm_getTceTableParms(cbp);
  37. itc_entries = cb.itc_size * PAGE_SIZE / sizeof(union tce_entry);
  38. veth_iommu_table.it_size = itc_entries / 2;
  39. veth_iommu_table.it_busno = cb.itc_busno;
  40. veth_iommu_table.it_offset = cb.itc_offset;
  41. veth_iommu_table.it_index = cb.itc_index;
  42. veth_iommu_table.it_type = TCE_VB;
  43. veth_iommu_table.it_blocksize = 1;
  44. t = iommu_init_table(&veth_iommu_table);
  45. if (!t)
  46. printk("Virtual Bus VETH TCE table failed.\n");
  47. vio_iommu_table.it_size = itc_entries - veth_iommu_table.it_size;
  48. vio_iommu_table.it_busno = cb.itc_busno;
  49. vio_iommu_table.it_offset = cb.itc_offset +
  50. veth_iommu_table.it_size;
  51. vio_iommu_table.it_index = cb.itc_index;
  52. vio_iommu_table.it_type = TCE_VB;
  53. vio_iommu_table.it_blocksize = 1;
  54. t = iommu_init_table(&vio_iommu_table);
  55. if (!t)
  56. printk("Virtual Bus VIO TCE table failed.\n");
  57. }
  58. /**
  59. * vio_register_device_iseries: - Register a new iSeries vio device.
  60. * @voidev: The device to register.
  61. */
  62. static struct vio_dev *__init vio_register_device_iseries(char *type,
  63. uint32_t unit_num)
  64. {
  65. struct vio_dev *viodev;
  66. /* allocate a vio_dev for this device */
  67. viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL);
  68. if (!viodev)
  69. return NULL;
  70. memset(viodev, 0, sizeof(struct vio_dev));
  71. snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%s%d", type, unit_num);
  72. viodev->name = viodev->dev.bus_id;
  73. viodev->type = type;
  74. viodev->unit_address = unit_num;
  75. viodev->iommu_table = &vio_iommu_table;
  76. if (vio_register_device(viodev) == NULL) {
  77. kfree(viodev);
  78. return NULL;
  79. }
  80. return viodev;
  81. }
  82. void __init probe_bus_iseries(void)
  83. {
  84. HvLpIndexMap vlan_map;
  85. struct vio_dev *viodev;
  86. int i;
  87. /* there is only one of each of these */
  88. vio_register_device_iseries("viocons", 0);
  89. vio_register_device_iseries("vscsi", 0);
  90. vlan_map = HvLpConfig_getVirtualLanIndexMap();
  91. for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
  92. if ((vlan_map & (0x8000 >> i)) == 0)
  93. continue;
  94. viodev = vio_register_device_iseries("vlan", i);
  95. /* veth is special and has it own iommu_table */
  96. viodev->iommu_table = &veth_iommu_table;
  97. }
  98. for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)
  99. vio_register_device_iseries("viodasd", i);
  100. for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)
  101. vio_register_device_iseries("viocd", i);
  102. for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)
  103. vio_register_device_iseries("viotape", i);
  104. }
  105. /**
  106. * vio_match_device_iseries: - Tell if a iSeries VIO device matches a
  107. * vio_device_id
  108. */
  109. static int vio_match_device_iseries(const struct vio_device_id *id,
  110. const struct vio_dev *dev)
  111. {
  112. return strncmp(dev->type, id->type, strlen(id->type)) == 0;
  113. }
  114. static struct vio_bus_ops vio_bus_ops_iseries = {
  115. .match = vio_match_device_iseries,
  116. };
  117. /**
  118. * vio_bus_init_iseries: - Initialize the iSeries virtual IO bus
  119. */
  120. static int __init vio_bus_init_iseries(void)
  121. {
  122. int err;
  123. err = vio_bus_init(&vio_bus_ops_iseries);
  124. if (err == 0) {
  125. iommu_vio_init();
  126. vio_bus_device.iommu_table = &vio_iommu_table;
  127. iSeries_vio_dev = &vio_bus_device.dev;
  128. probe_bus_iseries();
  129. }
  130. return err;
  131. }
  132. __initcall(vio_bus_init_iseries);