/drivers/staging/tidspbridge/pmgr/msg.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 129 lines · 59 code · 24 blank · 46 comment · 7 complexity · 843eaa57b00d5632c080333cd2ede503 MD5 · raw file

  1. /*
  2. * msg.c
  3. *
  4. * DSP-BIOS Bridge driver support functions for TI OMAP processors.
  5. *
  6. * DSP/BIOS Bridge msg_ctrl Module.
  7. *
  8. * Copyright (C) 2005-2006 Texas Instruments, Inc.
  9. *
  10. * This package is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17. */
  18. #include <linux/types.h>
  19. /* ----------------------------------- Host OS */
  20. #include <dspbridge/host_os.h>
  21. /* ----------------------------------- DSP/BIOS Bridge */
  22. #include <dspbridge/dbdefs.h>
  23. /* ----------------------------------- Trace & Debug */
  24. #include <dspbridge/dbc.h>
  25. /* ----------------------------------- Bridge Driver */
  26. #include <dspbridge/dspdefs.h>
  27. /* ----------------------------------- Platform Manager */
  28. #include <dspbridge/dev.h>
  29. /* ----------------------------------- This */
  30. #include <msgobj.h>
  31. #include <dspbridge/msg.h>
  32. /* ----------------------------------- Globals */
  33. static u32 refs; /* module reference count */
  34. /*
  35. * ======== msg_create ========
  36. * Purpose:
  37. * Create an object to manage message queues. Only one of these objects
  38. * can exist per device object.
  39. */
  40. int msg_create(struct msg_mgr **msg_man,
  41. struct dev_object *hdev_obj, msg_onexit msg_callback)
  42. {
  43. struct bridge_drv_interface *intf_fxns;
  44. struct msg_mgr_ *msg_mgr_obj;
  45. struct msg_mgr *hmsg_mgr;
  46. int status = 0;
  47. DBC_REQUIRE(refs > 0);
  48. DBC_REQUIRE(msg_man != NULL);
  49. DBC_REQUIRE(msg_callback != NULL);
  50. DBC_REQUIRE(hdev_obj != NULL);
  51. *msg_man = NULL;
  52. dev_get_intf_fxns(hdev_obj, &intf_fxns);
  53. /* Let Bridge message module finish the create: */
  54. status =
  55. (*intf_fxns->msg_create) (&hmsg_mgr, hdev_obj, msg_callback);
  56. if (!status) {
  57. /* Fill in DSP API message module's fields of the msg_mgr
  58. * structure */
  59. msg_mgr_obj = (struct msg_mgr_ *)hmsg_mgr;
  60. msg_mgr_obj->intf_fxns = intf_fxns;
  61. /* Finally, return the new message manager handle: */
  62. *msg_man = hmsg_mgr;
  63. } else {
  64. status = -EPERM;
  65. }
  66. return status;
  67. }
  68. /*
  69. * ======== msg_delete ========
  70. * Purpose:
  71. * Delete a msg_ctrl manager allocated in msg_create().
  72. */
  73. void msg_delete(struct msg_mgr *hmsg_mgr)
  74. {
  75. struct msg_mgr_ *msg_mgr_obj = (struct msg_mgr_ *)hmsg_mgr;
  76. struct bridge_drv_interface *intf_fxns;
  77. DBC_REQUIRE(refs > 0);
  78. if (msg_mgr_obj) {
  79. intf_fxns = msg_mgr_obj->intf_fxns;
  80. /* Let Bridge message module destroy the msg_mgr: */
  81. (*intf_fxns->msg_delete) (hmsg_mgr);
  82. } else {
  83. dev_dbg(bridge, "%s: Error hmsg_mgr handle: %p\n",
  84. __func__, hmsg_mgr);
  85. }
  86. }
  87. /*
  88. * ======== msg_exit ========
  89. */
  90. void msg_exit(void)
  91. {
  92. DBC_REQUIRE(refs > 0);
  93. refs--;
  94. DBC_ENSURE(refs >= 0);
  95. }
  96. /*
  97. * ======== msg_mod_init ========
  98. */
  99. bool msg_mod_init(void)
  100. {
  101. DBC_REQUIRE(refs >= 0);
  102. refs++;
  103. DBC_ENSURE(refs >= 0);
  104. return true;
  105. }