caif_shm_u5500.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) ST-Ericsson AB 2010
  3. * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com
  4. * Author: Amarnath Revanna / amarnath.bangalore.revanna@stericsson.com
  5. * License terms: GNU General Public License (GPL) version 2
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ":" fmt
  8. #include <linux/version.h>
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/netdevice.h>
  12. #include <mach/mbox-db5500.h>
  13. #include <net/caif/caif_shm.h>
  14. MODULE_LICENSE("GPL");
  15. MODULE_DESCRIPTION("CAIF Shared Memory protocol driver");
  16. #define MAX_SHM_INSTANCES 1
  17. enum {
  18. MBX_ACC0,
  19. MBX_ACC1,
  20. MBX_DSP
  21. };
  22. static struct shmdev_layer shmdev_lyr[MAX_SHM_INSTANCES];
  23. static unsigned int shm_start;
  24. static unsigned int shm_size;
  25. module_param(shm_size, uint , 0440);
  26. MODULE_PARM_DESC(shm_total_size, "Start of SHM shared memory");
  27. module_param(shm_start, uint , 0440);
  28. MODULE_PARM_DESC(shm_total_start, "Total Size of SHM shared memory");
  29. static int shmdev_send_msg(u32 dev_id, u32 mbx_msg)
  30. {
  31. /* Always block until msg is written successfully */
  32. mbox_send(shmdev_lyr[dev_id].hmbx, mbx_msg, true);
  33. return 0;
  34. }
  35. static int shmdev_mbx_setup(void *pshmdrv_cb, struct shmdev_layer *pshm_dev,
  36. void *pshm_drv)
  37. {
  38. /*
  39. * For UX5500, we have only 1 SHM instance which uses MBX0
  40. * for communication with the peer modem
  41. */
  42. pshm_dev->hmbx = mbox_setup(MBX_ACC0, pshmdrv_cb, pshm_drv);
  43. if (!pshm_dev->hmbx)
  44. return -ENODEV;
  45. else
  46. return 0;
  47. }
  48. static int __init caif_shmdev_init(void)
  49. {
  50. int i, result;
  51. /* Loop is currently overkill, there is only one instance */
  52. for (i = 0; i < MAX_SHM_INSTANCES; i++) {
  53. shmdev_lyr[i].shm_base_addr = shm_start;
  54. shmdev_lyr[i].shm_total_sz = shm_size;
  55. if (((char *)shmdev_lyr[i].shm_base_addr == NULL)
  56. || (shmdev_lyr[i].shm_total_sz <= 0)) {
  57. pr_warn("ERROR,"
  58. "Shared memory Address and/or Size incorrect"
  59. ", Bailing out ...\n");
  60. result = -EINVAL;
  61. goto clean;
  62. }
  63. pr_info("SHM AREA (instance %d) STARTS"
  64. " AT %p\n", i, (char *)shmdev_lyr[i].shm_base_addr);
  65. shmdev_lyr[i].shm_id = i;
  66. shmdev_lyr[i].pshmdev_mbxsend = shmdev_send_msg;
  67. shmdev_lyr[i].pshmdev_mbxsetup = shmdev_mbx_setup;
  68. /*
  69. * Finally, CAIF core module is called with details in place:
  70. * 1. SHM base address
  71. * 2. SHM size
  72. * 3. MBX handle
  73. */
  74. result = caif_shmcore_probe(&shmdev_lyr[i]);
  75. if (result) {
  76. pr_warn("ERROR[%d],"
  77. "Could not probe SHM core (instance %d)"
  78. " Bailing out ...\n", result, i);
  79. goto clean;
  80. }
  81. }
  82. return 0;
  83. clean:
  84. /*
  85. * For now, we assume that even if one instance of SHM fails, we bail
  86. * out of the driver support completely. For this, we need to release
  87. * any memory allocated and unregister any instance of SHM net device.
  88. */
  89. for (i = 0; i < MAX_SHM_INSTANCES; i++) {
  90. if (shmdev_lyr[i].pshm_netdev)
  91. unregister_netdev(shmdev_lyr[i].pshm_netdev);
  92. }
  93. return result;
  94. }
  95. static void __exit caif_shmdev_exit(void)
  96. {
  97. int i;
  98. for (i = 0; i < MAX_SHM_INSTANCES; i++) {
  99. caif_shmcore_remove(shmdev_lyr[i].pshm_netdev);
  100. kfree((void *)shmdev_lyr[i].shm_base_addr);
  101. }
  102. }
  103. module_init(caif_shmdev_init);
  104. module_exit(caif_shmdev_exit);