hpios.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. HPI Operating System function implementation for Linux
  15. (C) Copyright AudioScience Inc. 1997-2003
  16. ******************************************************************************/
  17. #define SOURCEFILE_NAME "hpios.c"
  18. #include "hpi_internal.h"
  19. #include "hpidebug.h"
  20. #include <linux/delay.h>
  21. #include <linux/sched.h>
  22. void hpios_delay_micro_seconds(u32 num_micro_sec)
  23. {
  24. if ((usecs_to_jiffies(num_micro_sec) > 1) && !in_interrupt()) {
  25. /* MUST NOT SCHEDULE IN INTERRUPT CONTEXT! */
  26. schedule_timeout_uninterruptible(usecs_to_jiffies
  27. (num_micro_sec));
  28. } else if (num_micro_sec <= 2000)
  29. udelay(num_micro_sec);
  30. else
  31. mdelay(num_micro_sec / 1000);
  32. }
  33. void hpios_locked_mem_init(void)
  34. {
  35. }
  36. /** Allocated an area of locked memory for bus master DMA operations.
  37. On error, return -ENOMEM, and *pMemArea.size = 0
  38. */
  39. u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_mem_area, u32 size,
  40. struct pci_dev *pdev)
  41. {
  42. /*?? any benefit in using managed dmam_alloc_coherent? */
  43. p_mem_area->vaddr =
  44. dma_alloc_coherent(&pdev->dev, size, &p_mem_area->dma_handle,
  45. GFP_DMA32 | GFP_KERNEL);
  46. if (p_mem_area->vaddr) {
  47. HPI_DEBUG_LOG(DEBUG, "allocated %d bytes, dma 0x%x vma %p\n",
  48. size, (unsigned int)p_mem_area->dma_handle,
  49. p_mem_area->vaddr);
  50. p_mem_area->pdev = &pdev->dev;
  51. p_mem_area->size = size;
  52. return 0;
  53. } else {
  54. HPI_DEBUG_LOG(WARNING,
  55. "failed to allocate %d bytes locked memory\n", size);
  56. p_mem_area->size = 0;
  57. return -ENOMEM;
  58. }
  59. }
  60. u16 hpios_locked_mem_free(struct consistent_dma_area *p_mem_area)
  61. {
  62. if (p_mem_area->size) {
  63. dma_free_coherent(p_mem_area->pdev, p_mem_area->size,
  64. p_mem_area->vaddr, p_mem_area->dma_handle);
  65. HPI_DEBUG_LOG(DEBUG, "freed %lu bytes, dma 0x%x vma %p\n",
  66. (unsigned long)p_mem_area->size,
  67. (unsigned int)p_mem_area->dma_handle,
  68. p_mem_area->vaddr);
  69. p_mem_area->size = 0;
  70. return 0;
  71. } else {
  72. return 1;
  73. }
  74. }
  75. void hpios_locked_mem_free_all(void)
  76. {
  77. }