1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* |
3 | * Intel Speed Select Interface: Drivers Internal defines |
4 | * Copyright (c) 2019, Intel Corporation. |
5 | * All rights reserved. |
6 | * |
7 | * Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> |
8 | */ |
9 | |
10 | #ifndef __ISST_IF_COMMON_H |
11 | #define __ISST_IF_COMMON_H |
12 | |
13 | #define PCI_DEVICE_ID_INTEL_RAPL_PRIO_DEVID_0 0x3451 |
14 | #define PCI_DEVICE_ID_INTEL_CFG_MBOX_DEVID_0 0x3459 |
15 | |
16 | #define PCI_DEVICE_ID_INTEL_RAPL_PRIO_DEVID_1 0x3251 |
17 | #define PCI_DEVICE_ID_INTEL_CFG_MBOX_DEVID_1 0x3259 |
18 | |
19 | /* |
20 | * Validate maximum commands in a single request. |
21 | * This is enough to handle command to every core in one ioctl, or all |
22 | * possible message id to one CPU. Limit is also helpful for resonse time |
23 | * per IOCTL request, as PUNIT may take different times to process each |
24 | * request and may hold for long for too many commands. |
25 | */ |
26 | #define ISST_IF_CMD_LIMIT 64 |
27 | |
28 | #define ISST_IF_API_VERSION 0x01 |
29 | #define ISST_IF_DRIVER_VERSION 0x01 |
30 | |
31 | #define ISST_IF_DEV_MBOX 0 |
32 | #define ISST_IF_DEV_MMIO 1 |
33 | #define ISST_IF_DEV_TPMI 2 |
34 | #define ISST_IF_DEV_MAX 3 |
35 | |
36 | /** |
37 | * struct isst_if_cmd_cb - Used to register a IOCTL handler |
38 | * @registered: Used by the common code to store registry. Caller don't |
39 | * to touch this field |
40 | * @cmd_size: The command size of the individual command in IOCTL |
41 | * @offset: Offset to the first valid member in command structure. |
42 | * This will be the offset of the start of the command |
43 | * after command count field |
44 | * @api_version: API version supported for this target. 0, if none. |
45 | * @owner: Registered module owner |
46 | * @cmd_callback: Callback function to handle IOCTL. The callback has the |
47 | * command pointer with data for command. There is a pointer |
48 | * called write_only, which when set, will not copy the |
49 | * response to user ioctl buffer. The "resume" argument |
50 | * can be used to avoid storing the command for replay |
51 | * during system resume |
52 | * @def_ioctl: Default IOCTL handler callback, if there is no match in |
53 | * the existing list of IOCTL handled by the common handler. |
54 | * |
55 | * This structure is used to register an handler for IOCTL. To avoid |
56 | * code duplication common code handles all the IOCTL command read/write |
57 | * including handling multiple command in single IOCTL. The caller just |
58 | * need to execute a command via the registered callback. |
59 | */ |
60 | struct isst_if_cmd_cb { |
61 | int registered; |
62 | int cmd_size; |
63 | int offset; |
64 | int api_version; |
65 | struct module *owner; |
66 | long (*cmd_callback)(u8 *ptr, int *write_only, int resume); |
67 | long (*def_ioctl)(struct file *file, unsigned int cmd, unsigned long arg); |
68 | }; |
69 | |
70 | /* Internal interface functions */ |
71 | int isst_if_cdev_register(int type, struct isst_if_cmd_cb *cb); |
72 | void isst_if_cdev_unregister(int type); |
73 | struct pci_dev *isst_if_get_pci_dev(int cpu, int bus, int dev, int fn); |
74 | bool isst_if_mbox_cmd_set_req(struct isst_if_mbox_cmd *mbox_cmd); |
75 | bool isst_if_mbox_cmd_invalid(struct isst_if_mbox_cmd *cmd); |
76 | int isst_store_cmd(int cmd, int sub_command, u32 cpu, int mbox_cmd, |
77 | u32 param, u64 data); |
78 | void isst_resume_common(void); |
79 | #endif |
80 | |