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