| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | | - * intel_scu_ipc.c: Driver for the Intel SCU IPC mechanism |
|---|
| 3 | + * Driver for the Intel SCU IPC mechanism |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * (C) Copyright 2008-2010 Intel Corporation |
|---|
| 5 | 6 | * Author: Sreedhara DS (sreedhara.ds@intel.com) |
|---|
| 6 | 7 | * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or |
|---|
| 8 | | - * modify it under the terms of the GNU General Public License |
|---|
| 9 | | - * as published by the Free Software Foundation; version 2 |
|---|
| 10 | | - * of the License. |
|---|
| 11 | | - * |
|---|
| 12 | | - * This driver provides ioctl interfaces to call intel scu ipc driver api |
|---|
| 8 | + * This driver provides IOCTL interfaces to call Intel SCU IPC driver API. |
|---|
| 13 | 9 | */ |
|---|
| 14 | 10 | |
|---|
| 15 | | -#include <linux/module.h> |
|---|
| 16 | | -#include <linux/kernel.h> |
|---|
| 17 | 11 | #include <linux/errno.h> |
|---|
| 18 | | -#include <linux/types.h> |
|---|
| 19 | | -#include <linux/fs.h> |
|---|
| 20 | 12 | #include <linux/fcntl.h> |
|---|
| 13 | +#include <linux/fs.h> |
|---|
| 14 | +#include <linux/kernel.h> |
|---|
| 15 | +#include <linux/module.h> |
|---|
| 21 | 16 | #include <linux/sched.h> |
|---|
| 22 | | -#include <linux/uaccess.h> |
|---|
| 23 | 17 | #include <linux/slab.h> |
|---|
| 24 | | -#include <linux/init.h> |
|---|
| 18 | +#include <linux/types.h> |
|---|
| 19 | +#include <linux/uaccess.h> |
|---|
| 20 | + |
|---|
| 25 | 21 | #include <asm/intel_scu_ipc.h> |
|---|
| 26 | 22 | |
|---|
| 27 | 23 | static int major; |
|---|
| 28 | 24 | |
|---|
| 29 | | -/* ioctl commnds */ |
|---|
| 25 | +struct intel_scu_ipc_dev *scu; |
|---|
| 26 | +static DEFINE_MUTEX(scu_lock); |
|---|
| 27 | + |
|---|
| 28 | +/* IOCTL commands */ |
|---|
| 30 | 29 | #define INTE_SCU_IPC_REGISTER_READ 0 |
|---|
| 31 | 30 | #define INTE_SCU_IPC_REGISTER_WRITE 1 |
|---|
| 32 | 31 | #define INTE_SCU_IPC_REGISTER_UPDATE 2 |
|---|
| .. | .. |
|---|
| 56 | 55 | |
|---|
| 57 | 56 | switch (cmd) { |
|---|
| 58 | 57 | case INTE_SCU_IPC_REGISTER_READ: |
|---|
| 59 | | - return intel_scu_ipc_readv(data->addr, data->data, count); |
|---|
| 58 | + return intel_scu_ipc_dev_readv(scu, data->addr, data->data, count); |
|---|
| 60 | 59 | case INTE_SCU_IPC_REGISTER_WRITE: |
|---|
| 61 | | - return intel_scu_ipc_writev(data->addr, data->data, count); |
|---|
| 60 | + return intel_scu_ipc_dev_writev(scu, data->addr, data->data, count); |
|---|
| 62 | 61 | case INTE_SCU_IPC_REGISTER_UPDATE: |
|---|
| 63 | | - return intel_scu_ipc_update_register(data->addr[0], |
|---|
| 64 | | - data->data[0], data->mask); |
|---|
| 62 | + return intel_scu_ipc_dev_update(scu, data->addr[0], data->data[0], |
|---|
| 63 | + data->mask); |
|---|
| 65 | 64 | default: |
|---|
| 66 | 65 | return -ENOTTY; |
|---|
| 67 | 66 | } |
|---|
| .. | .. |
|---|
| 95 | 94 | return 0; |
|---|
| 96 | 95 | } |
|---|
| 97 | 96 | |
|---|
| 97 | +static int scu_ipc_open(struct inode *inode, struct file *file) |
|---|
| 98 | +{ |
|---|
| 99 | + int ret = 0; |
|---|
| 100 | + |
|---|
| 101 | + /* Only single open at the time */ |
|---|
| 102 | + mutex_lock(&scu_lock); |
|---|
| 103 | + if (scu) { |
|---|
| 104 | + ret = -EBUSY; |
|---|
| 105 | + goto unlock; |
|---|
| 106 | + } |
|---|
| 107 | + |
|---|
| 108 | + scu = intel_scu_ipc_dev_get(); |
|---|
| 109 | + if (!scu) |
|---|
| 110 | + ret = -ENODEV; |
|---|
| 111 | + |
|---|
| 112 | +unlock: |
|---|
| 113 | + mutex_unlock(&scu_lock); |
|---|
| 114 | + return ret; |
|---|
| 115 | +} |
|---|
| 116 | + |
|---|
| 117 | +static int scu_ipc_release(struct inode *inode, struct file *file) |
|---|
| 118 | +{ |
|---|
| 119 | + mutex_lock(&scu_lock); |
|---|
| 120 | + intel_scu_ipc_dev_put(scu); |
|---|
| 121 | + scu = NULL; |
|---|
| 122 | + mutex_unlock(&scu_lock); |
|---|
| 123 | + |
|---|
| 124 | + return 0; |
|---|
| 125 | +} |
|---|
| 126 | + |
|---|
| 98 | 127 | static const struct file_operations scu_ipc_fops = { |
|---|
| 99 | 128 | .unlocked_ioctl = scu_ipc_ioctl, |
|---|
| 129 | + .open = scu_ipc_open, |
|---|
| 130 | + .release = scu_ipc_release, |
|---|
| 100 | 131 | }; |
|---|
| 101 | 132 | |
|---|
| 102 | 133 | static int __init ipc_module_init(void) |
|---|