vio.c 3.5 KB

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