/******************************************************************************12AudioScience HPI driver3Copyright (C) 1997-2010 AudioScience Inc. <[email protected]>45This program is free software; you can redistribute it and/or modify6it under the terms of version 2 of the GNU General Public License as7published by the Free Software Foundation;89This program is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.1314You should have received a copy of the GNU General Public License15along with this program; if not, write to the Free Software16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA1718HPI Operating System function implementation for Linux1920(C) Copyright AudioScience Inc. 1997-200321******************************************************************************/22#define SOURCEFILE_NAME "hpios.c"23#include "hpi_internal.h"24#include "hpidebug.h"25#include <linux/delay.h>26#include <linux/sched.h>2728void hpios_delay_micro_seconds(u32 num_micro_sec)29{30if ((usecs_to_jiffies(num_micro_sec) > 1) && !in_interrupt()) {31/* MUST NOT SCHEDULE IN INTERRUPT CONTEXT! */32schedule_timeout_uninterruptible(usecs_to_jiffies33(num_micro_sec));34} else if (num_micro_sec <= 2000)35udelay(num_micro_sec);36else37mdelay(num_micro_sec / 1000);3839}4041void hpios_locked_mem_init(void)42{43}4445/** Allocated an area of locked memory for bus master DMA operations.4647On error, return -ENOMEM, and *pMemArea.size = 048*/49u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_mem_area, u32 size,50struct pci_dev *pdev)51{52/*?? any benefit in using managed dmam_alloc_coherent? */53p_mem_area->vaddr =54dma_alloc_coherent(&pdev->dev, size, &p_mem_area->dma_handle,55GFP_DMA32 | GFP_KERNEL);5657if (p_mem_area->vaddr) {58HPI_DEBUG_LOG(DEBUG, "allocated %d bytes, dma 0x%x vma %p\n",59size, (unsigned int)p_mem_area->dma_handle,60p_mem_area->vaddr);61p_mem_area->pdev = &pdev->dev;62p_mem_area->size = size;63return 0;64} else {65HPI_DEBUG_LOG(WARNING,66"failed to allocate %d bytes locked memory\n", size);67p_mem_area->size = 0;68return -ENOMEM;69}70}7172u16 hpios_locked_mem_free(struct consistent_dma_area *p_mem_area)73{74if (p_mem_area->size) {75dma_free_coherent(p_mem_area->pdev, p_mem_area->size,76p_mem_area->vaddr, p_mem_area->dma_handle);77HPI_DEBUG_LOG(DEBUG, "freed %lu bytes, dma 0x%x vma %p\n",78(unsigned long)p_mem_area->size,79(unsigned int)p_mem_area->dma_handle,80p_mem_area->vaddr);81p_mem_area->size = 0;82return 0;83} else {84return 1;85}86}8788void hpios_locked_mem_free_all(void)89{90}919293