Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Siemens SIMATIC IPC drivers
0004  *
0005  * Copyright (c) Siemens AG, 2018-2021
0006  *
0007  * Authors:
0008  *  Henning Schild <henning.schild@siemens.com>
0009  *  Gerd Haeussler <gerd.haeussler.ext@siemens.com>
0010  */
0011 
0012 #ifndef __PLATFORM_DATA_X86_SIMATIC_IPC_H
0013 #define __PLATFORM_DATA_X86_SIMATIC_IPC_H
0014 
0015 #include <linux/dmi.h>
0016 #include <linux/platform_data/x86/simatic-ipc-base.h>
0017 
0018 #define SIMATIC_IPC_DMI_ENTRY_OEM   129
0019 /* binary type */
0020 #define SIMATIC_IPC_DMI_TYPE        0xff
0021 #define SIMATIC_IPC_DMI_GROUP       0x05
0022 #define SIMATIC_IPC_DMI_ENTRY       0x02
0023 #define SIMATIC_IPC_DMI_TID     0x02
0024 
0025 enum simatic_ipc_station_ids {
0026     SIMATIC_IPC_INVALID_STATION_ID = 0,
0027     SIMATIC_IPC_IPC227D = 0x00000501,
0028     SIMATIC_IPC_IPC427D = 0x00000701,
0029     SIMATIC_IPC_IPC227E = 0x00000901,
0030     SIMATIC_IPC_IPC277E = 0x00000902,
0031     SIMATIC_IPC_IPC427E = 0x00000A01,
0032     SIMATIC_IPC_IPC477E = 0x00000A02,
0033     SIMATIC_IPC_IPC127E = 0x00000D01,
0034 };
0035 
0036 static inline u32 simatic_ipc_get_station_id(u8 *data, int max_len)
0037 {
0038     struct {
0039         u8  type;       /* type (0xff = binary) */
0040         u8  len;        /* len of data entry */
0041         u8  group;
0042         u8  entry;
0043         u8  tid;
0044         __le32  station_id; /* station id (LE) */
0045     } __packed * data_entry = (void *)data + sizeof(struct dmi_header);
0046 
0047     while ((u8 *)data_entry < data + max_len) {
0048         if (data_entry->type == SIMATIC_IPC_DMI_TYPE &&
0049             data_entry->len == sizeof(*data_entry) &&
0050             data_entry->group == SIMATIC_IPC_DMI_GROUP &&
0051             data_entry->entry == SIMATIC_IPC_DMI_ENTRY &&
0052             data_entry->tid == SIMATIC_IPC_DMI_TID) {
0053             return le32_to_cpu(data_entry->station_id);
0054         }
0055         data_entry = (void *)((u8 *)(data_entry) + data_entry->len);
0056     }
0057 
0058     return SIMATIC_IPC_INVALID_STATION_ID;
0059 }
0060 
0061 static inline void
0062 simatic_ipc_find_dmi_entry_helper(const struct dmi_header *dh, void *_data)
0063 {
0064     u32 *id = _data;
0065 
0066     if (dh->type != SIMATIC_IPC_DMI_ENTRY_OEM)
0067         return;
0068 
0069     *id = simatic_ipc_get_station_id((u8 *)dh, dh->length);
0070 }
0071 
0072 #endif /* __PLATFORM_DATA_X86_SIMATIC_IPC_H */