1907286d1SJiri Kosina.. SPDX-License-Identifier: GPL-2.0 2907286d1SJiri Kosina 3907286d1SJiri Kosina 4907286d1SJiri KosinaAMD Sensor Fusion Hub 5907286d1SJiri Kosina===================== 6*4acdc5e5SRandy DunlapAMD Sensor Fusion Hub (SFH) is part of an SOC starting from Ryzen-based platforms. 7907286d1SJiri KosinaThe solution is working well on several OEM products. AMD SFH uses HID over PCIe bus. 8907286d1SJiri KosinaIn terms of architecture it resembles ISH, however the major difference is all 9907286d1SJiri Kosinathe HID reports are generated as part of the kernel driver. 10907286d1SJiri Kosina 11*4acdc5e5SRandy DunlapBlock Diagram 12*4acdc5e5SRandy Dunlap------------- 13907286d1SJiri Kosina 14907286d1SJiri Kosina:: 15907286d1SJiri Kosina 16907286d1SJiri Kosina --------------------------------- 17907286d1SJiri Kosina | HID User Space Applications | 18907286d1SJiri Kosina - ------------------------------- 19907286d1SJiri Kosina 20907286d1SJiri Kosina --------------------------------------------- 21907286d1SJiri Kosina --------------------------------- 22907286d1SJiri Kosina | HID Core | 23907286d1SJiri Kosina --------------------------------- 24907286d1SJiri Kosina 25907286d1SJiri Kosina --------------------------------- 26907286d1SJiri Kosina | AMD HID Transport | 27907286d1SJiri Kosina --------------------------------- 28907286d1SJiri Kosina 29907286d1SJiri Kosina -------------------------------- 30907286d1SJiri Kosina | AMD HID Client | 31907286d1SJiri Kosina | with HID Report Generator| 32907286d1SJiri Kosina -------------------------------- 33907286d1SJiri Kosina 34907286d1SJiri Kosina -------------------------------- 35907286d1SJiri Kosina | AMD MP2 PCIe Driver | 36907286d1SJiri Kosina -------------------------------- 37907286d1SJiri Kosina OS 38907286d1SJiri Kosina --------------------------------------------- 39907286d1SJiri Kosina Hardware + Firmware 40907286d1SJiri Kosina -------------------------------- 41907286d1SJiri Kosina | SFH MP2 Processor | 42907286d1SJiri Kosina -------------------------------- 43907286d1SJiri Kosina 44907286d1SJiri Kosina 45907286d1SJiri KosinaAMD HID Transport Layer 46907286d1SJiri Kosina----------------------- 47907286d1SJiri KosinaAMD SFH transport is also implemented as a bus. Each client application executing in the AMD MP2 is 48*4acdc5e5SRandy Dunlapregistered as a device on this bus. Here, MP2 is an ARM core connected to x86 for processing 49907286d1SJiri Kosinasensor data. The layer, which binds each device (AMD SFH HID driver) identifies the device type and 50*4acdc5e5SRandy Dunlapregisters with the HID core. Transport layer attaches a constant "struct hid_ll_driver" object with 51907286d1SJiri Kosinaeach device. Once a device is registered with HID core, the callbacks provided via this struct are 52907286d1SJiri Kosinaused by HID core to communicate with the device. AMD HID Transport layer implements the synchronous calls. 53907286d1SJiri Kosina 54907286d1SJiri KosinaAMD HID Client Layer 55907286d1SJiri Kosina-------------------- 56*4acdc5e5SRandy DunlapThis layer is responsible to implement HID requests and descriptors. As firmware is OS agnostic, HID 57907286d1SJiri Kosinaclient layer fills the HID request structure and descriptors. HID client layer is complex as it is 58*4acdc5e5SRandy Dunlapinterface between MP2 PCIe layer and HID. HID client layer initializes the MP2 PCIe layer and holds 59*4acdc5e5SRandy Dunlapthe instance of MP2 layer. It identifies the number of sensors connected using MP2-PCIe layer. Based 60*4acdc5e5SRandy Dunlapon that allocates the DRAM address for each and every sensor and passes it to MP2-PCIe driver. On 61*4acdc5e5SRandy Dunlapenumeration of each sensor, client layer fills the HID Descriptor structure and HID input report 62907286d1SJiri Kosinastructure. HID Feature report structure is optional. The report descriptor structure varies from 63907286d1SJiri Kosinasensor to sensor. 64907286d1SJiri Kosina 65907286d1SJiri KosinaAMD MP2 PCIe layer 66907286d1SJiri Kosina------------------ 67907286d1SJiri KosinaMP2 PCIe Layer is responsible for making all transactions with the firmware over PCIe. 68907286d1SJiri KosinaThe connection establishment between firmware and PCIe happens here. 69907286d1SJiri Kosina 70907286d1SJiri KosinaThe communication between X86 and MP2 is split into three parts. 71907286d1SJiri Kosina1. Command transfer via the C2P mailbox registers. 72907286d1SJiri Kosina2. Data transfer via DRAM. 73907286d1SJiri Kosina3. Supported sensor info via P2C registers. 74907286d1SJiri Kosina 75*4acdc5e5SRandy DunlapCommands are sent to MP2 using C2P Mailbox registers. Writing into C2P Message registers generates 76907286d1SJiri Kosinainterrupt to MP2. The client layer allocates the physical memory and the same is sent to MP2 via 77907286d1SJiri Kosinathe PCI layer. MP2 firmware writes the command output to the access DRAM memory which the client 78907286d1SJiri Kosinalayer has allocated. Firmware always writes minimum of 32 bytes into DRAM. So as a protocol driver 79907286d1SJiri Kosinashall allocate minimum of 32 bytes DRAM space. 80907286d1SJiri Kosina 81907286d1SJiri KosinaEnumeration and Probing flow 82907286d1SJiri Kosina---------------------------- 83907286d1SJiri Kosina:: 84907286d1SJiri Kosina 85907286d1SJiri Kosina HID AMD AMD AMD -PCIe MP2 86907286d1SJiri Kosina Core Transport Client layer layer FW 87907286d1SJiri Kosina | | | | | 88907286d1SJiri Kosina | | | on Boot Driver Loaded | 89907286d1SJiri Kosina | | | | | 90907286d1SJiri Kosina | | | MP2-PCIe Int | 91907286d1SJiri Kosina | | | | | 92907286d1SJiri Kosina | | |---Get Number of sensors-> | | 93907286d1SJiri Kosina | | | Read P2C | 94907286d1SJiri Kosina | | | Register | 95907286d1SJiri Kosina | | | | | 96907286d1SJiri Kosina | | | Loop(for No of Sensors) | | 97907286d1SJiri Kosina | | |----------------------| | | 98907286d1SJiri Kosina | | | Create HID Descriptor| | | 99907286d1SJiri Kosina | | | Create Input report | | | 100907286d1SJiri Kosina | | | Descriptor Map | | | 101907286d1SJiri Kosina | | | the MP2 FW Index to | | | 102907286d1SJiri Kosina | | | HID Index | | | 103907286d1SJiri Kosina | | | Allocate the DRAM | Enable | 104907286d1SJiri Kosina | | | address | Sensors | 105907286d1SJiri Kosina | | |----------------------| | | 106907286d1SJiri Kosina | | HID transport| | Enable | 107907286d1SJiri Kosina | |<--Probe------| |---Sensor CMD--> | 108907286d1SJiri Kosina | | Create the | | | 109907286d1SJiri Kosina | | HID device | | | 110907286d1SJiri Kosina | | (MFD) | | | 111907286d1SJiri Kosina | | by Populating| | | 112907286d1SJiri Kosina | | the HID | | | 113907286d1SJiri Kosina | | ll_driver | | | 114907286d1SJiri Kosina | HID | | | | 115907286d1SJiri Kosina | add | | | | 116907286d1SJiri Kosina |Device | | | | 117907286d1SJiri Kosina |<------------- | | | | 118907286d1SJiri Kosina 119907286d1SJiri Kosina 120907286d1SJiri KosinaData Flow from Application to the AMD SFH Driver 121907286d1SJiri Kosina------------------------------------------------ 122907286d1SJiri Kosina 123907286d1SJiri Kosina:: 124907286d1SJiri Kosina 125907286d1SJiri Kosina | | | | | 126907286d1SJiri Kosina | | | | | 127907286d1SJiri Kosina | | | | | 128907286d1SJiri Kosina | | | | | 129907286d1SJiri Kosina | | | | | 130907286d1SJiri Kosina |HID_req | | | | 131907286d1SJiri Kosina |get_report | | | | 132907286d1SJiri Kosina |------------->| | | | 133907286d1SJiri Kosina | | HID_get_input| | | 134907286d1SJiri Kosina | | report | | | 135907286d1SJiri Kosina | |------------->|------------------------| | | 136907286d1SJiri Kosina | | | Read the DRAM data for| | | 137907286d1SJiri Kosina | | | requested sensor and | | | 138907286d1SJiri Kosina | | | create the HID input | | | 139907286d1SJiri Kosina | | | report | | | 140907286d1SJiri Kosina | | |------------------------| | | 141907286d1SJiri Kosina | |Data received | | | 142907286d1SJiri Kosina | | in HID report| | | 143907286d1SJiri Kosina To |<-------------|<-------------| | | 144907286d1SJiri Kosina Applications| | | | | 145907286d1SJiri Kosina <-------| | | | | 146