iSeries_vio.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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: - Register a new 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 node */
  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. return vio_register_device_common(viodev, viodev->dev.bus_id, type,
  72. unit_num, &vio_iommu_table);
  73. }
  74. void __init probe_bus_iseries(void)
  75. {
  76. HvLpIndexMap vlan_map;
  77. struct vio_dev *viodev;
  78. int i;
  79. /* there is only one of each of these */
  80. vio_register_device_iseries("viocons", 0);
  81. vio_register_device_iseries("vscsi", 0);
  82. vlan_map = HvLpConfig_getVirtualLanIndexMap();
  83. for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
  84. if ((vlan_map & (0x8000 >> i)) == 0)
  85. continue;
  86. viodev = vio_register_device_iseries("vlan", i);
  87. /* veth is special and has it own iommu_table */
  88. viodev->iommu_table = &veth_iommu_table;
  89. }
  90. for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)
  91. vio_register_device_iseries("viodasd", i);
  92. for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)
  93. vio_register_device_iseries("viocd", i);
  94. for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)
  95. vio_register_device_iseries("viotape", i);
  96. }
  97. /**
  98. * vio_bus_init_iseries: - Initialize the iSeries virtual IO bus
  99. */
  100. static int __init vio_bus_init_iseries(void)
  101. {
  102. int err;
  103. err = vio_bus_init();
  104. if (err == 0) {
  105. iommu_vio_init();
  106. vio_bus_device.iommu_table = &vio_iommu_table;
  107. iSeries_vio_dev = &vio_bus_device.dev;
  108. probe_bus_iseries();
  109. }
  110. return err;
  111. }
  112. __initcall(vio_bus_init_iseries);