vio.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. iommu_table_getparms_iSeries(255, 0, 0xff, &veth_iommu_table);
  30. veth_iommu_table.it_size /= 2;
  31. vio_iommu_table = veth_iommu_table;
  32. vio_iommu_table.it_offset += veth_iommu_table.it_size;
  33. if (!iommu_init_table(&veth_iommu_table))
  34. printk("Virtual Bus VETH TCE table failed.\n");
  35. if (!iommu_init_table(&vio_iommu_table))
  36. printk("Virtual Bus VIO TCE table failed.\n");
  37. }
  38. /**
  39. * vio_register_device_iseries: - Register a new iSeries vio device.
  40. * @voidev: The device to register.
  41. */
  42. static struct vio_dev *__init vio_register_device_iseries(char *type,
  43. uint32_t unit_num)
  44. {
  45. struct vio_dev *viodev;
  46. /* allocate a vio_dev for this device */
  47. viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL);
  48. if (!viodev)
  49. return NULL;
  50. memset(viodev, 0, sizeof(struct vio_dev));
  51. snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%s%d", type, unit_num);
  52. viodev->name = viodev->dev.bus_id;
  53. viodev->type = type;
  54. viodev->unit_address = unit_num;
  55. viodev->iommu_table = &vio_iommu_table;
  56. if (vio_register_device(viodev) == NULL) {
  57. kfree(viodev);
  58. return NULL;
  59. }
  60. return viodev;
  61. }
  62. void __init probe_bus_iseries(void)
  63. {
  64. HvLpIndexMap vlan_map;
  65. struct vio_dev *viodev;
  66. int i;
  67. /* there is only one of each of these */
  68. vio_register_device_iseries("viocons", 0);
  69. vio_register_device_iseries("vscsi", 0);
  70. vlan_map = HvLpConfig_getVirtualLanIndexMap();
  71. for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
  72. if ((vlan_map & (0x8000 >> i)) == 0)
  73. continue;
  74. viodev = vio_register_device_iseries("vlan", i);
  75. /* veth is special and has it own iommu_table */
  76. viodev->iommu_table = &veth_iommu_table;
  77. }
  78. for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)
  79. vio_register_device_iseries("viodasd", i);
  80. for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)
  81. vio_register_device_iseries("viocd", i);
  82. for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)
  83. vio_register_device_iseries("viotape", i);
  84. }
  85. /**
  86. * vio_match_device_iseries: - Tell if a iSeries VIO device matches a
  87. * vio_device_id
  88. */
  89. static int vio_match_device_iseries(const struct vio_device_id *id,
  90. const struct vio_dev *dev)
  91. {
  92. return strncmp(dev->type, id->type, strlen(id->type)) == 0;
  93. }
  94. static struct vio_bus_ops vio_bus_ops_iseries = {
  95. .match = vio_match_device_iseries,
  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(&vio_bus_ops_iseries);
  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);