iSeries_vio.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/abs_addr.h>
  17. #include <asm/page.h>
  18. #include <asm/iSeries/vio.h>
  19. #include <asm/iSeries/HvTypes.h>
  20. #include <asm/iSeries/HvLpConfig.h>
  21. #include <asm/iSeries/HvCallXm.h>
  22. struct device *iSeries_vio_dev = &vio_bus_device.dev;
  23. EXPORT_SYMBOL(iSeries_vio_dev);
  24. static struct iommu_table veth_iommu_table;
  25. static struct iommu_table vio_iommu_table;
  26. static void __init iommu_vio_init(void)
  27. {
  28. struct iommu_table *t;
  29. struct iommu_table_cb cb;
  30. unsigned long cbp;
  31. unsigned long itc_entries;
  32. cb.itc_busno = 255; /* Bus 255 is the virtual bus */
  33. cb.itc_virtbus = 0xff; /* Ask for virtual bus */
  34. cbp = virt_to_abs(&cb);
  35. HvCallXm_getTceTableParms(cbp);
  36. itc_entries = cb.itc_size * PAGE_SIZE / sizeof(union tce_entry);
  37. veth_iommu_table.it_size = itc_entries / 2;
  38. veth_iommu_table.it_busno = cb.itc_busno;
  39. veth_iommu_table.it_offset = cb.itc_offset;
  40. veth_iommu_table.it_index = cb.itc_index;
  41. veth_iommu_table.it_type = TCE_VB;
  42. veth_iommu_table.it_blocksize = 1;
  43. t = iommu_init_table(&veth_iommu_table);
  44. if (!t)
  45. printk("Virtual Bus VETH TCE table failed.\n");
  46. vio_iommu_table.it_size = itc_entries - veth_iommu_table.it_size;
  47. vio_iommu_table.it_busno = cb.itc_busno;
  48. vio_iommu_table.it_offset = cb.itc_offset +
  49. veth_iommu_table.it_size;
  50. vio_iommu_table.it_index = cb.itc_index;
  51. vio_iommu_table.it_type = TCE_VB;
  52. vio_iommu_table.it_blocksize = 1;
  53. t = iommu_init_table(&vio_iommu_table);
  54. if (!t)
  55. printk("Virtual Bus VIO TCE table failed.\n");
  56. }
  57. /**
  58. * vio_register_device_iseries: - Register a new iSeries vio device.
  59. * @voidev: The device to register.
  60. */
  61. static struct vio_dev *__init vio_register_device_iseries(char *type,
  62. uint32_t unit_num)
  63. {
  64. struct vio_dev *viodev;
  65. /* allocate a vio_dev for this device */
  66. viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL);
  67. if (!viodev)
  68. return NULL;
  69. memset(viodev, 0, sizeof(struct vio_dev));
  70. snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%s%d", type, unit_num);
  71. viodev->name = viodev->dev.bus_id;
  72. viodev->type = type;
  73. viodev->unit_address = unit_num;
  74. viodev->iommu_table = &vio_iommu_table;
  75. if (vio_register_device(viodev) == NULL) {
  76. kfree(viodev);
  77. return NULL;
  78. }
  79. return viodev;
  80. }
  81. void __init probe_bus_iseries(void)
  82. {
  83. HvLpIndexMap vlan_map;
  84. struct vio_dev *viodev;
  85. int i;
  86. /* there is only one of each of these */
  87. vio_register_device_iseries("viocons", 0);
  88. vio_register_device_iseries("vscsi", 0);
  89. vlan_map = HvLpConfig_getVirtualLanIndexMap();
  90. for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
  91. if ((vlan_map & (0x8000 >> i)) == 0)
  92. continue;
  93. viodev = vio_register_device_iseries("vlan", i);
  94. /* veth is special and has it own iommu_table */
  95. viodev->iommu_table = &veth_iommu_table;
  96. }
  97. for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)
  98. vio_register_device_iseries("viodasd", i);
  99. for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)
  100. vio_register_device_iseries("viocd", i);
  101. for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)
  102. vio_register_device_iseries("viotape", i);
  103. }
  104. /**
  105. * vio_match_device_iseries: - Tell if a iSeries VIO device matches a
  106. * vio_device_id
  107. */
  108. static int vio_match_device_iseries(const struct vio_device_id *id,
  109. const struct vio_dev *dev)
  110. {
  111. return strncmp(dev->type, id->type, strlen(id->type)) == 0;
  112. }
  113. static struct vio_bus_ops vio_bus_ops_iseries = {
  114. .match = vio_match_device_iseries,
  115. };
  116. /**
  117. * vio_bus_init_iseries: - Initialize the iSeries virtual IO bus
  118. */
  119. static int __init vio_bus_init_iseries(void)
  120. {
  121. int err;
  122. err = vio_bus_init(&vio_bus_ops_iseries);
  123. if (err == 0) {
  124. iommu_vio_init();
  125. vio_bus_device.iommu_table = &vio_iommu_table;
  126. iSeries_vio_dev = &vio_bus_device.dev;
  127. probe_bus_iseries();
  128. }
  129. return err;
  130. }
  131. __initcall(vio_bus_init_iseries);