1f9f848faSopenharmony_ci/*- 2f9f848faSopenharmony_ci * Copyright (c) 2010 Isilon Systems, Inc. 3f9f848faSopenharmony_ci * Copyright (c) 2010 iX Systems, Inc. 4f9f848faSopenharmony_ci * Copyright (c) 2010 Panasas, Inc. 5f9f848faSopenharmony_ci * Copyright (c) 2013-2015 Mellanox Technologies, Ltd. 6f9f848faSopenharmony_ci * All rights reserved. 7f9f848faSopenharmony_ci * 8f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without 9f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions 10f9f848faSopenharmony_ci * are met: 11f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 12f9f848faSopenharmony_ci * notice unmodified, this list of conditions, and the following 13f9f848faSopenharmony_ci * disclaimer. 14f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 15f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 16f9f848faSopenharmony_ci * documentation and/or other materials provided with the distribution. 17f9f848faSopenharmony_ci * 18f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19f9f848faSopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20f9f848faSopenharmony_ci * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21f9f848faSopenharmony_ci * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22f9f848faSopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23f9f848faSopenharmony_ci * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24f9f848faSopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25f9f848faSopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26f9f848faSopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27f9f848faSopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28f9f848faSopenharmony_ci */ 29f9f848faSopenharmony_ci 30f9f848faSopenharmony_ci#include "linux/interrupt.h" 31f9f848faSopenharmony_ci#include "los_hwi.h" 32f9f848faSopenharmony_ci 33f9f848faSopenharmony_ci 34f9f848faSopenharmony_ciint linux_request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, 35f9f848faSopenharmony_ci const char *name, void *dev) 36f9f848faSopenharmony_ci{ 37f9f848faSopenharmony_ci UINT32 ret; 38f9f848faSopenharmony_ci HwiIrqParam irqParam; 39f9f848faSopenharmony_ci 40f9f848faSopenharmony_ci if (OS_INT_ACTIVE) { 41f9f848faSopenharmony_ci return OS_ERRNO_HWI_INTERR; 42f9f848faSopenharmony_ci } 43f9f848faSopenharmony_ci 44f9f848faSopenharmony_ci irqParam.swIrq = (INT32)irq; 45f9f848faSopenharmony_ci irqParam.pDevId = dev; 46f9f848faSopenharmony_ci irqParam.pName = name; 47f9f848faSopenharmony_ci 48f9f848faSopenharmony_ci ret = LOS_HwiCreate(irq, IRQ_DEFAULT_PRIORITY, (HWI_MODE_T)flags, (HWI_PROC_FUNC)handler, &irqParam); 49f9f848faSopenharmony_ci if (ret == LOS_OK) { 50f9f848faSopenharmony_ci HalIrqUnmask(irq); 51f9f848faSopenharmony_ci } 52f9f848faSopenharmony_ci return (INT32)ret; 53f9f848faSopenharmony_ci} 54f9f848faSopenharmony_ci 55f9f848faSopenharmony_civoid linux_free_irq(unsigned int irq, void *devID) 56f9f848faSopenharmony_ci{ 57f9f848faSopenharmony_ci HwiIrqParam irqParam; 58f9f848faSopenharmony_ci 59f9f848faSopenharmony_ci if (OS_INT_ACTIVE) { 60f9f848faSopenharmony_ci return; 61f9f848faSopenharmony_ci } 62f9f848faSopenharmony_ci 63f9f848faSopenharmony_ci irqParam.swIrq = (INT32)irq; 64f9f848faSopenharmony_ci irqParam.pDevId = devID; 65f9f848faSopenharmony_ci 66f9f848faSopenharmony_ci (VOID)LOS_HwiDelete(irq, &irqParam); 67f9f848faSopenharmony_ci return; 68f9f848faSopenharmony_ci} 69f9f848faSopenharmony_ci 70f9f848faSopenharmony_civoid linux_enable_irq(unsigned int irq) 71f9f848faSopenharmony_ci{ 72f9f848faSopenharmony_ci HalIrqUnmask(irq); 73f9f848faSopenharmony_ci} 74f9f848faSopenharmony_ci 75f9f848faSopenharmony_civoid linux_disable_irq(unsigned int irq) 76f9f848faSopenharmony_ci{ 77f9f848faSopenharmony_ci HalIrqMask(irq); 78f9f848faSopenharmony_ci} 79f9f848faSopenharmony_ci 80f9f848faSopenharmony_ci#ifdef WORKQUEUE_SUPPORT_PRIORITY 81f9f848faSopenharmony_cibool irq_bottom_half(struct workqueue_struct *workQueue, irq_bottom_half_handler_t handler, void *data, 82f9f848faSopenharmony_ci unsigned int pri) 83f9f848faSopenharmony_ci#else 84f9f848faSopenharmony_cibool irq_bottom_half(struct workqueue_struct *workQueue, irq_bottom_half_handler_t handler, void *data) 85f9f848faSopenharmony_ci#endif 86f9f848faSopenharmony_ci{ 87f9f848faSopenharmony_ci struct work_struct *work = NULL; 88f9f848faSopenharmony_ci 89f9f848faSopenharmony_ci if ((workQueue == NULL) || (handler == NULL)) { 90f9f848faSopenharmony_ci return FALSE; 91f9f848faSopenharmony_ci } 92f9f848faSopenharmony_ci 93f9f848faSopenharmony_ci#ifdef WORKQUEUE_SUPPORT_PRIORITY 94f9f848faSopenharmony_ci if ((pri >= OS_WORK_PRIORITY_DEFAULT) || (pri >= OS_WORK_PRIORITY_LOWEST)) { 95f9f848faSopenharmony_ci return FALSE; 96f9f848faSopenharmony_ci } 97f9f848faSopenharmony_ci#endif 98f9f848faSopenharmony_ci 99f9f848faSopenharmony_ci work = (struct work_struct *)LOS_MemAlloc(m_aucSysMem0, sizeof(struct work_struct)); 100f9f848faSopenharmony_ci if (work == NULL) { 101f9f848faSopenharmony_ci return FALSE; 102f9f848faSopenharmony_ci } 103f9f848faSopenharmony_ci 104f9f848faSopenharmony_ci INIT_WORK(work, handler); 105f9f848faSopenharmony_ci 106f9f848faSopenharmony_ci work->data = (atomic_long_t)data; 107f9f848faSopenharmony_ci#ifdef WORKQUEUE_SUPPORT_PRIORITY 108f9f848faSopenharmony_ci work->work_pri = pri; 109f9f848faSopenharmony_ci#endif 110f9f848faSopenharmony_ci if (!(queue_work(workQueue, work))) { 111f9f848faSopenharmony_ci (VOID)LOS_MemFree(m_aucSysMem0, work); 112f9f848faSopenharmony_ci return FALSE; 113f9f848faSopenharmony_ci } 114f9f848faSopenharmony_ci return TRUE; 115f9f848faSopenharmony_ci} 116f9f848faSopenharmony_ci 117