blob: 53c28d750a45bea73e1bb3a10da53ee42a11a85d [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0 */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright © 2016 Intel Corporation
4 *
5 * Authors:
6 * Rafael Antognolli <rafael.antognolli@intel.com>
7 * Scott Bauer <scott.bauer@intel.com>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00008 */
9
10#ifndef LINUX_OPAL_H
11#define LINUX_OPAL_H
12
13#include <uapi/linux/sed-opal.h>
14#include <linux/kernel.h>
15
16struct opal_dev;
17
18typedef int (sec_send_recv)(void *data, u16 spsp, u8 secp, void *buffer,
19 size_t len, bool send);
20
21#ifdef CONFIG_BLK_SED_OPAL
22void free_opal_dev(struct opal_dev *dev);
23bool opal_unlock_from_suspend(struct opal_dev *dev);
24struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv);
25int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *ioctl_ptr);
26
27static inline bool is_sed_ioctl(unsigned int cmd)
28{
29 switch (cmd) {
30 case IOC_OPAL_SAVE:
31 case IOC_OPAL_LOCK_UNLOCK:
32 case IOC_OPAL_TAKE_OWNERSHIP:
33 case IOC_OPAL_ACTIVATE_LSP:
34 case IOC_OPAL_SET_PW:
35 case IOC_OPAL_ACTIVATE_USR:
36 case IOC_OPAL_REVERT_TPR:
37 case IOC_OPAL_LR_SETUP:
38 case IOC_OPAL_ADD_USR_TO_LR:
39 case IOC_OPAL_ENABLE_DISABLE_MBR:
40 case IOC_OPAL_ERASE_LR:
41 case IOC_OPAL_SECURE_ERASE_LR:
David Brazdil0f672f62019-12-10 10:32:29 +000042 case IOC_OPAL_PSID_REVERT_TPR:
43 case IOC_OPAL_MBR_DONE:
44 case IOC_OPAL_WRITE_SHADOW_MBR:
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000045 return true;
46 }
47 return false;
48}
49#else
50static inline void free_opal_dev(struct opal_dev *dev)
51{
52}
53
54static inline bool is_sed_ioctl(unsigned int cmd)
55{
56 return false;
57}
58
59static inline int sed_ioctl(struct opal_dev *dev, unsigned int cmd,
60 void __user *ioctl_ptr)
61{
62 return 0;
63}
64static inline bool opal_unlock_from_suspend(struct opal_dev *dev)
65{
66 return false;
67}
68#define init_opal_dev(data, send_recv) NULL
69#endif /* CONFIG_BLK_SED_OPAL */
70#endif /* LINUX_OPAL_H */