1c442b710SCyril BurCopyright 2016 IBM 2c442b710SCyril Bur 3c442b710SCyril BurLicensed under the Apache License, Version 2.0 (the "License"); 4c442b710SCyril Buryou may not use this file except in compliance with the License. 5c442b710SCyril BurYou may obtain a copy of the License at 6c442b710SCyril Bur 7c442b710SCyril Bur http://www.apache.org/licenses/LICENSE-2.0 8c442b710SCyril Bur 9c442b710SCyril BurUnless required by applicable law or agreed to in writing, software 10c442b710SCyril Burdistributed under the License is distributed on an "AS IS" BASIS, 11c442b710SCyril BurWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c442b710SCyril BurSee the License for the specific language governing permissions and 13c442b710SCyril Burlimitations under the License. 14c442b710SCyril Bur 15*2dff340aSSuraj Jitindar Singh## Intro 1657b0bca4SAndrew Jeffery 17*2dff340aSSuraj Jitindar SinghThis document describes a protocol for host to BMC communication via the 18*2dff340aSSuraj Jitindar Singhmailbox registers present on the Aspeed 2400 and 2500 chips. 19*2dff340aSSuraj Jitindar SinghThis protocol is specifically designed to allow a host to request and manage 20*2dff340aSSuraj Jitindar Singhaccess to the flash with the specifics of how the host is required to control 21*2dff340aSSuraj Jitindar Singhthis described below. 22*2dff340aSSuraj Jitindar Singh 23*2dff340aSSuraj Jitindar Singh## Version 24*2dff340aSSuraj Jitindar Singh 25*2dff340aSSuraj Jitindar SinghBoth version 1 and version 2 of the protocol are described below with version 2 26*2dff340aSSuraj Jitindar Singhspecificities represented with V2 in brackets - (V2). 27*2dff340aSSuraj Jitindar Singh 28*2dff340aSSuraj Jitindar Singh## Problem Overview 2957b0bca4SAndrew Jeffery 3057b0bca4SAndrew Jeffery"mbox" is the name we use to represent a protocol we have established between 3157b0bca4SAndrew Jefferythe host and the BMC via the Aspeed mailbox registers. This protocol is used 3257b0bca4SAndrew Jefferyfor the host to control the flash. 3357b0bca4SAndrew Jeffery 3457b0bca4SAndrew JefferyPrior to the mbox protocol, the host uses a backdoor into the BMC address space 35*2dff340aSSuraj Jitindar Singh(the iLPC-to-AHB bridge) to directly manipulate the BMCs own flash controller. 3657b0bca4SAndrew Jeffery 3757b0bca4SAndrew JefferyThis is not sustainable for a number of reasons. The main ones are: 3857b0bca4SAndrew Jeffery 3957b0bca4SAndrew Jeffery1. Every piece of the host software stack that needs flash access (HostBoot, 4057b0bca4SAndrew Jeffery OCC, OPAL, ...) has to have a complete driver for the flash controller, 4157b0bca4SAndrew Jeffery update it on each BMC generation, have all the quirks for all the flash 4257b0bca4SAndrew Jeffery chips supported etc... We have 3 copies on the host already in addition to 4357b0bca4SAndrew Jeffery the one in the BMC itself. 4457b0bca4SAndrew Jeffery 4557b0bca4SAndrew Jeffery2. There are serious issues of access conflicts to that controller between the 4657b0bca4SAndrew Jeffery host and the BMC. 4757b0bca4SAndrew Jeffery 4857b0bca4SAndrew Jeffery3. It's very hard to support "BMC reboots" when doing that 4957b0bca4SAndrew Jeffery 5057b0bca4SAndrew Jeffery4. It's slow 5157b0bca4SAndrew Jeffery 5257b0bca4SAndrew Jeffery5. Last but probably most important, having that backdoor open is a security 5357b0bca4SAndrew Jeffery risk. It means the host can access any address on the BMC internal bus and 5457b0bca4SAndrew Jeffery implant malware in the BMC itself. So if the host is a "bare metal" shared 5557b0bca4SAndrew Jeffery system in some kind of data center, not only the host flash needs to be 5657b0bca4SAndrew Jeffery reflashed when switching from one customer to another, but the entire BMC 5757b0bca4SAndrew Jeffery flash too as nothing can be trusted. So we want to disable it. 5857b0bca4SAndrew Jeffery 5957b0bca4SAndrew JefferyTo address all these, we have implemented a new mechanism that we call mbox. 6057b0bca4SAndrew Jeffery 61*2dff340aSSuraj Jitindar SinghWhen using this mechanism, the BMC is solely responsible for directly accessing 6257b0bca4SAndrew Jefferythe flash controller. All flash erase and write operations are performed by the 6357b0bca4SAndrew JefferyBMC and the BMC only. (We can allow direct reads from flash under some 6457b0bca4SAndrew Jefferycircumstances but we tend to prefer going via memory). 6557b0bca4SAndrew Jeffery 6657b0bca4SAndrew JefferyThe host uses the mailbox registers to send "commands" to the BMC, which 6757b0bca4SAndrew Jefferyresponds via the same mechanism. Those commands allow the host to control a 6857b0bca4SAndrew Jeffery"window" (which is the LPC -> AHB FW space mapping) that is either a read 6957b0bca4SAndrew Jefferywindow or a write window onto the flash. 7057b0bca4SAndrew Jeffery 7157b0bca4SAndrew JefferyWhen set for writing, the BMC makes the window point to a chunk of RAM instead. 7257b0bca4SAndrew JefferyWhen the host "commits" a change (via MBOX), then the BMC can perform the 7357b0bca4SAndrew Jefferyactual flashing from the data in the RAM window. 7457b0bca4SAndrew Jeffery 7557b0bca4SAndrew JefferyThe idea is to have the LPC FW space be routed to an active "window". That 7657b0bca4SAndrew Jefferywindow can be a read or a write window. The commands allow to control which 7757b0bca4SAndrew Jefferywindow and which offset into the flash it maps. 7857b0bca4SAndrew Jeffery 7957b0bca4SAndrew Jeffery* A read window can be a direct window to the flash controller space (ie. 8057b0bca4SAndrew Jeffery 0x3000\_0000) or it can be a window to a RAM image of a flash. It doesn't have 8157b0bca4SAndrew Jeffery to be the full size of the flash per protocol (commands can be use to "slide" 8257b0bca4SAndrew Jeffery it to various parts of the flash) but if its set to map the actual flash 8357b0bca4SAndrew Jeffery controller space at 0x3000\_0000, it's probably simpler to make it the full 8457b0bca4SAndrew Jeffery flash. The host makes no assumption, it's your choice what to provide. The 8557b0bca4SAndrew Jeffery simplest implementation is to just route to the flash read/only. 8657b0bca4SAndrew Jeffery 8757b0bca4SAndrew Jeffery* A write window has to be a chunk of BMC memory. The minimum size is not 8857b0bca4SAndrew Jeffery defined in the spec, but it should be at least one block (4k for now but it 8957b0bca4SAndrew Jeffery should support larger block sizes in the future). When the BMC receive the 9057b0bca4SAndrew Jeffery command to map the write window at a given offset of the flash, the BMC should 9157b0bca4SAndrew Jeffery copy that portion of the flash into a reserved memory buffer, and modify the 9257b0bca4SAndrew Jeffery LPC mapping to point to that buffer. 9357b0bca4SAndrew Jeffery 9457b0bca4SAndrew JefferyThe host can then write to that window directly (updating the BMC memory) and 9557b0bca4SAndrew Jefferysend a command to "commit" those updates to flash. 9657b0bca4SAndrew Jeffery 9757b0bca4SAndrew JefferyFinally there is a `RESET_STATE`. It's the state in which the bootloader in the 9857b0bca4SAndrew JefferySEEPROM of the POWER9 chip will find what it needs to load HostBoot. The 9957b0bca4SAndrew Jefferydetails are still being ironed out: either mapping the full flash read only or 10057b0bca4SAndrew Jefferyreset to a "window" that is either at the bottom or top of the flash. The 10157b0bca4SAndrew Jefferycurrent implementation resets to point to the full flash. 10257b0bca4SAndrew Jeffery 103*2dff340aSSuraj Jitindar Singh## Where is the code? 10457b0bca4SAndrew Jeffery 10557b0bca4SAndrew JefferyThe mbox userspace is available [on GitHub](https://github.com/openbmc/mboxbridge) 10657b0bca4SAndrew JefferyThis is Apache licensed but we are keen to see any enhancements you may have. 10757b0bca4SAndrew Jeffery 10857b0bca4SAndrew JefferyThe kernel driver is still in the process of being upstreamed but can be found 10957b0bca4SAndrew Jefferyin the OpenBMC Linux kernel staging tree: 11057b0bca4SAndrew Jeffery 11157b0bca4SAndrew Jefferyhttps://github.com/openbmc/linux/commit/85770a7d1caa6a1fa1a291c33dfe46e05755a2ef 11257b0bca4SAndrew Jeffery 113*2dff340aSSuraj Jitindar Singh## Building 114*2dff340aSSuraj Jitindar Singh 115*2dff340aSSuraj Jitindar SinghThe autotools of this requires the autoconf-archive package for your 116*2dff340aSSuraj Jitindar Singhsystem 117*2dff340aSSuraj Jitindar Singh 118*2dff340aSSuraj Jitindar Singh## The Hardware 119*2dff340aSSuraj Jitindar Singh 12057b0bca4SAndrew JefferyThe Aspeed mailbox consists of 16 (8 bit) data registers see Layout for their 12157b0bca4SAndrew Jefferyuse. Mailbox interrupt enabling, masking and triggering is done using a pair 12257b0bca4SAndrew Jefferyof control registers, one accessible by the host the other by the BMC. 12357b0bca4SAndrew JefferyInterrupts can also be raised per write to each data register, for BMC and 12457b0bca4SAndrew Jefferyhost. Write tiggered interrupts are configured using two 8 bit registers where 12557b0bca4SAndrew Jefferyeach bit represents a data register and if an interrupt should fire on write. 12657b0bca4SAndrew JefferyTwo 8 bit registers are present to act as a mask for write triggered 12757b0bca4SAndrew Jefferyinterrupts. 128c442b710SCyril Bur 129*2dff340aSSuraj Jitindar Singh### Layout 130*2dff340aSSuraj Jitindar Singh 131*2dff340aSSuraj Jitindar Singh``` 132*2dff340aSSuraj Jitindar SinghByte 0: COMMAND 133*2dff340aSSuraj Jitindar SinghByte 1: Sequence 134*2dff340aSSuraj Jitindar SinghByte 2-12: Arguments 135*2dff340aSSuraj Jitindar SinghByte 13: Response code 136*2dff340aSSuraj Jitindar SinghByte 14: Host controlled status reg 137*2dff340aSSuraj Jitindar SinghByte 15: BMC controlled status reg 138*2dff340aSSuraj Jitindar Singh``` 139*2dff340aSSuraj Jitindar Singh 140*2dff340aSSuraj Jitindar Singh## Low Level Protocol Flow 141*2dff340aSSuraj Jitindar Singh 142*2dff340aSSuraj Jitindar SinghWhat we essentially have is a set of registers which either the host or BMC can 143*2dff340aSSuraj Jitindar Singhwrite to in order to communicate to the other which will respond in some way. 144*2dff340aSSuraj Jitindar SinghThere are 3 basic types of communication. 145*2dff340aSSuraj Jitindar Singh 146*2dff340aSSuraj Jitindar Singh1. Commands sent from the Host to the BMC 147*2dff340aSSuraj Jitindar Singh2. Responses sent from the BMC to the Host in response to commands 148*2dff340aSSuraj Jitindar Singh3. Asyncronous events raised by the BMC 149*2dff340aSSuraj Jitindar Singh 150*2dff340aSSuraj Jitindar Singh### General Use 151*2dff340aSSuraj Jitindar Singh 1529dd93cfaSCyril BurMessages usually originate from the host to the BMC. There are special 1539dd93cfaSCyril Burcases for a back channel for the BMC to pass new information to the 1549dd93cfaSCyril Burhost which will be discussed later. 1559dd93cfaSCyril Bur 1569dd93cfaSCyril BurTo initiate a request the host must set a command code (see 1579dd93cfaSCyril BurCommands) into mailbox data register 0. It is also the hosts 1589dd93cfaSCyril Burresponsibility to generate a unique sequence number into mailbox 1599dd93cfaSCyril Burregister 1. After this any command specific data should be written 1609dd93cfaSCyril Bur(see Layout). The host must then generate an interrupt to the BMC by 161*2dff340aSSuraj Jitindar Singhusing bit 0 of its control register and wait for an interrupt on the 162*2dff340aSSuraj Jitindar Singhresponse register. Generating an interrupt automatically sets bit 7 of the 1639dd93cfaSCyril Burcorresponding control register. This bit can be used to poll for 1649dd93cfaSCyril Burmessages. 1659dd93cfaSCyril Bur 1669dd93cfaSCyril BurOn receiving an interrupt (or polling on bit 7 of its Control 1679dd93cfaSCyril BurRegister) the BMC should read the message from the general registers 1689dd93cfaSCyril Burof the mailbox and perform the necessary action before responding. On 1699dd93cfaSCyril Burresponding the BMC must ensure that the sequence number is the same as 1709dd93cfaSCyril Burthe one in the request from the host. The BMC must also ensure that 1719dd93cfaSCyril Burmailbox data regsiter 13 is a valid response code (see Responses). The 1729dd93cfaSCyril BurBMC should then use its control register to generate an interrupt for 1739dd93cfaSCyril Burthe host to notify it of a response. 1749dd93cfaSCyril Bur 175*2dff340aSSuraj Jitindar Singh### Asynchronous BMC to Host Events 1769dd93cfaSCyril Bur 1779dd93cfaSCyril BurBMC to host communication is also possible for notification of events 1789dd93cfaSCyril Burfrom the BMC. This requires that the host have interrupts enabled on 1799dd93cfaSCyril Burmailbox data register 15 (or otherwise poll on bit 7 of mailbox status 1809dd93cfaSCyril Burregister 1). On receiving such a notification the host should read 181*2dff340aSSuraj Jitindar Singhmailbox data register 15 to determine the event code which was set by the 182*2dff340aSSuraj Jitindar SinghBMC (see BMC Event notifications in Commands for detail). Events which are 183*2dff340aSSuraj Jitindar Singhdefined as being able to be acknowledged by the host must be with a 184*2dff340aSSuraj Jitindar SinghBMC_EVENT_ACK command. 1859dd93cfaSCyril Bur 186*2dff340aSSuraj Jitindar Singh## High Level Protocol Flow 18723042906SAndrew Jeffery 188*2dff340aSSuraj Jitindar SinghWhen a host wants to communicate with the BMC via the mbox protocol the first 189*2dff340aSSuraj Jitindar Singhthing it should do it call MBOX_GET_INFO in order to establish the protocol 190*2dff340aSSuraj Jitindar Singhversion which each understands. Before this the only other commands which are 191*2dff340aSSuraj Jitindar Singhallowed are RESET_STATE and BMC_EVENT_ACK. 192c442b710SCyril Bur 193*2dff340aSSuraj Jitindar SinghAfter this the host can open and close windows with the CREATE_READ_WINDOW, 194*2dff340aSSuraj Jitindar SinghCREATE_WRITE_WINDOW and CLOSE_WINDOW commands. Creating a window is how the 195*2dff340aSSuraj Jitindar Singhhost requests access to a section of flash. It is worth noting that the host 196*2dff340aSSuraj Jitindar Singhcan only ever have one window that it is accessing at a time - hence forth 197*2dff340aSSuraj Jitindar Singhreferred to as the active window. 198*2dff340aSSuraj Jitindar Singh 199*2dff340aSSuraj Jitindar SinghWhen the active window is a write window the host can perform MARK_WRITE_DIRTY, 200*2dff340aSSuraj Jitindar SinghMARK_WRITE_ERASED and WRITE_FLUSH commands to identify changed blocks and 201*2dff340aSSuraj Jitindar Singhcontrol when the changed blocks are written to flash. 202*2dff340aSSuraj Jitindar Singh 203*2dff340aSSuraj Jitindar SinghIndependently, and at any point not during an existing mbox command 204*2dff340aSSuraj Jitindar Singhtransaction, the BMC may raise raise asynchronous events with the host to 205*2dff340aSSuraj Jitindar Singhcommunicate a change in state. 206*2dff340aSSuraj Jitindar Singh 207*2dff340aSSuraj Jitindar Singh### Version Negotiation 208*2dff340aSSuraj Jitindar Singh 209*2dff340aSSuraj Jitindar SinghGiven that a majority of command and response arguments are specified as a 210*2dff340aSSuraj Jitindar Singhmultiple of block size it is necessary for the host and BMC to agree on a 211*2dff340aSSuraj Jitindar Singhprotocol version as this determines the block size. In V1 it is hard coded at 212*2dff340aSSuraj Jitindar Singh4K and in V2 the BMC chooses and specifies this to the host as a response 213*2dff340aSSuraj Jitindar Singhargument to MBOX_GET_INFO. Thus the host must always call MBOX_GET_INFO before 214*2dff340aSSuraj Jitindar Singhany other command which specifies an argument in block size. 215*2dff340aSSuraj Jitindar Singh 216*2dff340aSSuraj Jitindar SinghThe host must tell the BMC the highest protocol level which it supports. The 217*2dff340aSSuraj Jitindar SinghBMC will then respond with a protocol level. If the host doesn't understand 218*2dff340aSSuraj Jitindar Singhthe protocol level specified by the BMC then it must not continue to 219*2dff340aSSuraj Jitindar Singhcommunicate with the BMC. Otherwise the protocol level specified by the 220*2dff340aSSuraj Jitindar SinghBMC is taken to be the protocol level used for further communication and can 221*2dff340aSSuraj Jitindar Singhonly be changed by another call to MBOX_GET_INFO. The BMC should use the 222*2dff340aSSuraj Jitindar Singhrequest from the host to influence its protocol version choice. 223*2dff340aSSuraj Jitindar Singh 224*2dff340aSSuraj Jitindar Singh### Window Management 225*2dff340aSSuraj Jitindar Singh 226*2dff340aSSuraj Jitindar SinghIn order to access flash contents the host must request a window be opened at 227*2dff340aSSuraj Jitindar Singhthe flash offset it would like to access. The host may give a hint as to how 228*2dff340aSSuraj Jitindar Singhmuch data it would like to access or otherwise set this argument to zero. The 229*2dff340aSSuraj Jitindar SinghBMC must respond with the lpc bus address to access this window and the 230*2dff340aSSuraj Jitindar Singhwindow size. The host must not access past the end of the active window. 231*2dff340aSSuraj Jitindar Singh 232*2dff340aSSuraj Jitindar SinghThere is only ever one active window which is the window created by the most 233*2dff340aSSuraj Jitindar Singhrecent CREATE_READ_WINDOW or CREATE_WRITE_WINDOW call which succeeded. Even 234*2dff340aSSuraj Jitindar Singhthough there are two types of windows there can still only be one active window 235*2dff340aSSuraj Jitindar Singhirrespective of type. A host must not write to a read window. A host may read 236*2dff340aSSuraj Jitindar Singhfrom a write window and the BMC must guarantee that the window reflects what 237*2dff340aSSuraj Jitindar Singhthe host has written there. 238*2dff340aSSuraj Jitindar Singh 239*2dff340aSSuraj Jitindar SinghA window can be closed by calling CLOSE_WINDOW in which case there is no active 240*2dff340aSSuraj Jitindar Singhwindow and the host must not access the LPC window after it has been closed. 241*2dff340aSSuraj Jitindar SinghIf the host closes an active write window then the BMC must perform an 242*2dff340aSSuraj Jitindar Singhimplicit flush. If the host tries to open a new window with an already active 243*2dff340aSSuraj Jitindar Singhwindow then the active window is closed (and implicitly flushed if it was a 244*2dff340aSSuraj Jitindar Singhwrite window). If the new window is successfully opened then it is the new 245*2dff340aSSuraj Jitindar Singhactive window, if the command fails then there is no active window and the 246*2dff340aSSuraj Jitindar Singhprevious active window must no longer be accessed. 247*2dff340aSSuraj Jitindar Singh 248*2dff340aSSuraj Jitindar SinghThe host must not access an lpc address other than that which is contained by 249*2dff340aSSuraj Jitindar Singhthe active window. The host must not use write management functions (see below) 250*2dff340aSSuraj Jitindar Singhif the active window is a read window or if there is no active window. 251*2dff340aSSuraj Jitindar Singh 252*2dff340aSSuraj Jitindar Singh### Write Management 253*2dff340aSSuraj Jitindar Singh 254*2dff340aSSuraj Jitindar SinghThe BMC has no method for intercepting writes that occur over the LPC bus. Thus 255*2dff340aSSuraj Jitindar Singhthe host must explicitly notify the BMC of where and when a write has 256*2dff340aSSuraj Jitindar Singhoccured. The host must use the MARK_WRITE_DIRTY command to tell the BMC where 257*2dff340aSSuraj Jitindar Singhwithin the write window it has modified. The host may also use the 258*2dff340aSSuraj Jitindar SinghMARK_WRITE_ERASED command to erase large parts of the active window without the 259*2dff340aSSuraj Jitindar Singhneed to write 0xFF. The BMC must ensure that if the host 260*2dff340aSSuraj Jitindar Singhreads from an area it has erased that the read values are 0xFF. Any part of the 261*2dff340aSSuraj Jitindar Singhactive window marked dirty/erased is only marked for the lifetime of the current 262*2dff340aSSuraj Jitindar Singhactive write window and does not persist if the active window is closed either 263*2dff340aSSuraj Jitindar Singhimplicitly or explicitly by the host or the BMC. The BMC may at any time 264*2dff340aSSuraj Jitindar Singhor must on a call to WRITE_FLUSH flush the changes which it has been notified 265*2dff340aSSuraj Jitindar Singhof back to the flash, at which point the dirty or erased marking is cleared 266*2dff340aSSuraj Jitindar Singhfor the active window. The host must not assume that any changes have been 267*2dff340aSSuraj Jitindar Singhwritten to flash unless an explicit flush call was successful, a close of an 268*2dff340aSSuraj Jitindar Singhactive write window was successful or a create window command with an active 269*2dff340aSSuraj Jitindar Singhwrite window was successful - otherwise consistency between the flash and memory 270*2dff340aSSuraj Jitindar Singhcontents cannot be guaranteed. 271*2dff340aSSuraj Jitindar Singh 272*2dff340aSSuraj Jitindar SinghThe host is not required to perform an erase before a write command and the 273*2dff340aSSuraj Jitindar SinghBMC must ensure that a write performs as expected - that is if an erase is 274*2dff340aSSuraj Jitindar Singhrequired before a write then the BMC must perform this itself. 275*2dff340aSSuraj Jitindar Singh 276*2dff340aSSuraj Jitindar Singh### BMC Events 277*2dff340aSSuraj Jitindar Singh 278*2dff340aSSuraj Jitindar SinghThe BMC can raise events with the host asynchronously to communicate to the 279*2dff340aSSuraj Jitindar Singhhost a change in state which it should take notice of. The host must (if 280*2dff340aSSuraj Jitindar Singhpossible for the given event) acknowledge it to inform the BMC it has been 281*2dff340aSSuraj Jitindar Singhreceived. 282*2dff340aSSuraj Jitindar Singh 283*2dff340aSSuraj Jitindar SinghIf the BMC raises a BMC Reboot event then the host must renegotiate the 284*2dff340aSSuraj Jitindar Singhprotocol version so that both the BMC and the host agree on the block size. 285*2dff340aSSuraj Jitindar SinghA BMC Reboot event implies a BMC Windows Reset event. 286*2dff340aSSuraj Jitindar SinghIf the BMC raises a BMC Windows Reset event then the host must 287*2dff340aSSuraj Jitindar Singhassume that there is no longer an active window - that is if there was an 288*2dff340aSSuraj Jitindar Singhactive window it has been closed by the BMC and if it was a write window 289*2dff340aSSuraj Jitindar Singhthen the host must not assume that it was flushed unless a previous explicit 290*2dff340aSSuraj Jitindar Singhflush call was successful. 291*2dff340aSSuraj Jitindar Singh 292*2dff340aSSuraj Jitindar SinghThe BMC may at some points require access to the flash and the BMC daemon must 293*2dff340aSSuraj Jitindar Singhset the BMC Flash Control Lost event when the BMC is accessing the flash behind 294*2dff340aSSuraj Jitindar Singhthe BMC daemons back. When this event is set the host must assume that the 295*2dff340aSSuraj Jitindar Singhcontents of the active window could be inconsistent with the contents of flash. 296*2dff340aSSuraj Jitindar Singh 297*2dff340aSSuraj Jitindar Singh## Protocol Definition 298*2dff340aSSuraj Jitindar Singh 299*2dff340aSSuraj Jitindar Singh### Commands 300*2dff340aSSuraj Jitindar Singh 301c442b710SCyril Bur``` 302*2dff340aSSuraj Jitindar SinghRESET_STATE 0x01 303*2dff340aSSuraj Jitindar SinghGET_MBOX_INFO 0x02 304*2dff340aSSuraj Jitindar SinghGET_FLASH_INFO 0x03 305*2dff340aSSuraj Jitindar SinghCREATE_READ_WINDOW 0x04 306*2dff340aSSuraj Jitindar SinghCLOSE_WINDOW 0x05 307*2dff340aSSuraj Jitindar SinghCREATE_WRITE_WINDOW 0x06 308*2dff340aSSuraj Jitindar SinghMARK_WRITE_DIRTY 0x07 309*2dff340aSSuraj Jitindar SinghWRITE_FLUSH 0x08 310*2dff340aSSuraj Jitindar SinghBMC_EVENT_ACK 0x09 311*2dff340aSSuraj Jitindar SinghMARK_WRITE_ERASED 0x0a (V2) 312c442b710SCyril Bur``` 313*2dff340aSSuraj Jitindar Singh 314*2dff340aSSuraj Jitindar Singh### Sequence 315*2dff340aSSuraj Jitindar Singh 316*2dff340aSSuraj Jitindar SinghThe host must ensure a unique sequence number at the start of a 317*2dff340aSSuraj Jitindar Singhcommand/response pair. The BMC must ensure the responses to 3189dd93cfaSCyril Bura particular message contain the same sequence number that was in the 319*2dff340aSSuraj Jitindar Singhcommand request from the host. 320c442b710SCyril Bur 321*2dff340aSSuraj Jitindar Singh### Responses 322*2dff340aSSuraj Jitindar Singh 323c442b710SCyril Bur``` 3249dd93cfaSCyril BurSUCCESS 1 3259dd93cfaSCyril BurPARAM_ERROR 2 3269dd93cfaSCyril BurWRITE_ERROR 3 3279dd93cfaSCyril BurSYSTEM_ERROR 4 3289dd93cfaSCyril BurTIMEOUT 5 329*2dff340aSSuraj Jitindar SinghBUSY 6 (V2) 330*2dff340aSSuraj Jitindar SinghWINDOW_ERROR 7 (V2) 331c442b710SCyril Bur``` 332c442b710SCyril Bur 333*2dff340aSSuraj Jitindar Singh#### Description: 334*2dff340aSSuraj Jitindar Singh 335*2dff340aSSuraj Jitindar SinghSUCCESS - Command completed successfully 336*2dff340aSSuraj Jitindar Singh 337*2dff340aSSuraj Jitindar SinghPARAM_ERROR - Error with parameters supplied or command invalid 338*2dff340aSSuraj Jitindar Singh 339*2dff340aSSuraj Jitindar SinghWRITE_ERROR - Error writing to the backing file system 340*2dff340aSSuraj Jitindar Singh 341*2dff340aSSuraj Jitindar SinghSYSTEM_ERROR - Error in BMC performing system action 342*2dff340aSSuraj Jitindar Singh 343*2dff340aSSuraj Jitindar SinghTIMEOUT - Timeout in performing action 344*2dff340aSSuraj Jitindar Singh 345*2dff340aSSuraj Jitindar SinghBUSY - Daemon in suspended state (currently unable to access flash) 346*2dff340aSSuraj Jitindar Singh - Retry again later 347*2dff340aSSuraj Jitindar Singh 348*2dff340aSSuraj Jitindar SinghWINDOW_ERROR - Command not valid for active window or no active window 349*2dff340aSSuraj Jitindar Singh - Try opening an appropriate window and retrying the command 350*2dff340aSSuraj Jitindar Singh 351*2dff340aSSuraj Jitindar Singh### Information 3529dd93cfaSCyril Bur- All multibyte messages are LSB first (little endian) 3539dd93cfaSCyril Bur- All responses must have a valid return code in byte 13 3549dd93cfaSCyril Bur 355c442b710SCyril Bur 356c442b710SCyril Bur### Commands in detail 357*2dff340aSSuraj Jitindar Singh 358*2dff340aSSuraj Jitindar SinghNote in V1 block size is hard coded to 4K, in V2 it is variable and must be 359*2dff340aSSuraj Jitindar Singhqueried with GET_MBOX_INFO. 360*2dff340aSSuraj Jitindar SinghSizes and addresses are specified in either bytes - (bytes) 361*2dff340aSSuraj Jitindar Singh or blocks - (blocks) 362*2dff340aSSuraj Jitindar SinghSizes and addresses specified in blocks must be converted to bytes by 363*2dff340aSSuraj Jitindar Singhmultiplying by the block size. 364c442b710SCyril Bur``` 365c442b710SCyril BurCommand: 366c442b710SCyril Bur RESET_STATE 367*2dff340aSSuraj Jitindar Singh Implemented in Versions: 368*2dff340aSSuraj Jitindar Singh V1, V2 369*2dff340aSSuraj Jitindar Singh Arguments: 370c442b710SCyril Bur - 371c442b710SCyril Bur Response: 372c442b710SCyril Bur - 3739dd93cfaSCyril Bur Notes: 3749dd93cfaSCyril Bur This command is designed to inform the BMC that it should put 3759dd93cfaSCyril Bur host LPC mapping back in a state where the SBE will be able to 3769dd93cfaSCyril Bur use it. Currently this means pointing back to BMC flash 3779dd93cfaSCyril Bur pre mailbox protocol. Final behavour is still TBD. 3789dd93cfaSCyril Bur 379c442b710SCyril BurCommand: 380c442b710SCyril Bur GET_MBOX_INFO 381*2dff340aSSuraj Jitindar Singh Implemented in Versions: 382*2dff340aSSuraj Jitindar Singh V1, V2 3839dd93cfaSCyril Bur Arguments: 384*2dff340aSSuraj Jitindar Singh V1: 385*2dff340aSSuraj Jitindar Singh Args 0: API version 3869dd93cfaSCyril Bur 387*2dff340aSSuraj Jitindar Singh V2: 388*2dff340aSSuraj Jitindar Singh Args 0: API version 389*2dff340aSSuraj Jitindar Singh 390*2dff340aSSuraj Jitindar Singh Response: 391*2dff340aSSuraj Jitindar Singh V1: 392*2dff340aSSuraj Jitindar Singh Args 0: API version 393*2dff340aSSuraj Jitindar Singh Args 1-2: default read window size (blocks) 394*2dff340aSSuraj Jitindar Singh Args 3-4: default write window size (blocks) 395*2dff340aSSuraj Jitindar Singh 396*2dff340aSSuraj Jitindar Singh V2: 397*2dff340aSSuraj Jitindar Singh Args 0: API version 398*2dff340aSSuraj Jitindar Singh Args 1-2: default read window size (blocks) 399*2dff340aSSuraj Jitindar Singh Args 3-4: default write window size (blocks) 400*2dff340aSSuraj Jitindar Singh Args 5: Block size as power of two (encoded as a shift) 4019dd93cfaSCyril Bur 402c442b710SCyril BurCommand: 403c442b710SCyril Bur GET_FLASH_INFO 404*2dff340aSSuraj Jitindar Singh Implemented in Versions: 405*2dff340aSSuraj Jitindar Singh V1, V2 4069dd93cfaSCyril Bur Arguments: 407c442b710SCyril Bur - 408c442b710SCyril Bur Response: 409*2dff340aSSuraj Jitindar Singh V1: 410*2dff340aSSuraj Jitindar Singh Args 0-3: Flash size (bytes) 411*2dff340aSSuraj Jitindar Singh Args 4-7: Erase granule (bytes) 4129dd93cfaSCyril Bur 413*2dff340aSSuraj Jitindar Singh V2: 414*2dff340aSSuraj Jitindar Singh Args 0-1: Flash size (blocks) 415*2dff340aSSuraj Jitindar Singh Args 2-3: Erase granule (blocks) 416c442b710SCyril Bur 417c442b710SCyril BurCommand: 418*2dff340aSSuraj Jitindar Singh CREATE_{READ/WRITE}_WINDOW 419*2dff340aSSuraj Jitindar Singh Implemented in Versions: 420*2dff340aSSuraj Jitindar Singh V1, V2 4219dd93cfaSCyril Bur Arguments: 422*2dff340aSSuraj Jitindar Singh V1: 423*2dff340aSSuraj Jitindar Singh Args 0-1: Window location as offset into flash (blocks) 4249dd93cfaSCyril Bur 425*2dff340aSSuraj Jitindar Singh V2: 426*2dff340aSSuraj Jitindar Singh Args 0-1: Window location as offset into flash (blocks) 427*2dff340aSSuraj Jitindar Singh Args 2-3: Requested window size (blocks) 428*2dff340aSSuraj Jitindar Singh 429*2dff340aSSuraj Jitindar Singh Response: 430*2dff340aSSuraj Jitindar Singh V1: 431*2dff340aSSuraj Jitindar Singh Args 0-1: LPC bus address of window (blocks) 432*2dff340aSSuraj Jitindar Singh 433*2dff340aSSuraj Jitindar Singh V2: 434*2dff340aSSuraj Jitindar Singh Args 0-1: LPC bus address of window (blocks) 435*2dff340aSSuraj Jitindar Singh Args 2-3: Actual window size (blocks) 436*2dff340aSSuraj Jitindar Singh Notes: 437*2dff340aSSuraj Jitindar Singh Window location is always given as an offset into flash as 438*2dff340aSSuraj Jitindar Singh taken from the start of flash - that is it is an absolute 439*2dff340aSSuraj Jitindar Singh address. 440*2dff340aSSuraj Jitindar Singh 441*2dff340aSSuraj Jitindar Singh LPC bus address is always given from the start of the LPC 442*2dff340aSSuraj Jitindar Singh address space - that is it is an absolute address. 443*2dff340aSSuraj Jitindar Singh 444*2dff340aSSuraj Jitindar Singh The requested window size is only a hint. The response 445*2dff340aSSuraj Jitindar Singh indicates the actual size of the window. The BMC may 446*2dff340aSSuraj Jitindar Singh want to use the requested size to pre-load the remainder 447*2dff340aSSuraj Jitindar Singh of the request. The host must not access past the end of the 448*2dff340aSSuraj Jitindar Singh active window. 449*2dff340aSSuraj Jitindar Singh 450*2dff340aSSuraj Jitindar Singh The requested window size may be zero. In this case the 451*2dff340aSSuraj Jitindar Singh BMC is free to create any sized window but it must contain 452*2dff340aSSuraj Jitindar Singh atleast the first block of data requested by the host. A large 453*2dff340aSSuraj Jitindar Singh window is of course preferred and should correspond to 454*2dff340aSSuraj Jitindar Singh the default size returned in the GET_MBOX_INFO command. 455*2dff340aSSuraj Jitindar Singh 456*2dff340aSSuraj Jitindar Singh If this command returns successfully then the window which the 457*2dff340aSSuraj Jitindar Singh host requested is the active window. If it fails then there is 458*2dff340aSSuraj Jitindar Singh no active window. 4599dd93cfaSCyril Bur 4609dd93cfaSCyril BurCommand: 461*2dff340aSSuraj Jitindar Singh CLOSE_WINDOW 462*2dff340aSSuraj Jitindar Singh Implemented in Versions: 463*2dff340aSSuraj Jitindar Singh V1, V2 464*2dff340aSSuraj Jitindar Singh Arguments: 465*2dff340aSSuraj Jitindar Singh V1: 466*2dff340aSSuraj Jitindar Singh - 4679dd93cfaSCyril Bur 468*2dff340aSSuraj Jitindar Singh V2: 469*2dff340aSSuraj Jitindar Singh Args 0: Flags 470*2dff340aSSuraj Jitindar Singh Response: 471*2dff340aSSuraj Jitindar Singh - 472*2dff340aSSuraj Jitindar Singh Notes: 473*2dff340aSSuraj Jitindar Singh Closes the active window. Any further access to the LPC bus 474*2dff340aSSuraj Jitindar Singh address specified to address the previously active window will 475*2dff340aSSuraj Jitindar Singh have undefined effects. If the active window is a 476*2dff340aSSuraj Jitindar Singh write window then the BMC must perform an implicit flush. 477*2dff340aSSuraj Jitindar Singh 478*2dff340aSSuraj Jitindar Singh The Flags argument allows the host to provide some 479*2dff340aSSuraj Jitindar Singh hints to the BMC. Defined Values: 480*2dff340aSSuraj Jitindar Singh 0x01 - Short Lifetime: 481*2dff340aSSuraj Jitindar Singh The window is unlikely to be accessed 482*2dff340aSSuraj Jitindar Singh anytime again in the near future. The effect of 483*2dff340aSSuraj Jitindar Singh this will depend on BMC implementation. In 484*2dff340aSSuraj Jitindar Singh the event that the BMC performs some caching 485*2dff340aSSuraj Jitindar Singh the BMC daemon could mark data contained in a 486*2dff340aSSuraj Jitindar Singh window closed with this flag as first to be 487*2dff340aSSuraj Jitindar Singh evicted from the cache. 488c442b710SCyril Bur 489c442b710SCyril BurCommand: 4909dd93cfaSCyril Bur MARK_WRITE_DIRTY 491*2dff340aSSuraj Jitindar Singh Implemented in Versions: 492*2dff340aSSuraj Jitindar Singh V1, V2 493*2dff340aSSuraj Jitindar Singh Arguments: 494*2dff340aSSuraj Jitindar Singh V1: 495*2dff340aSSuraj Jitindar Singh Args 0-1: Flash offset to mark from base of flash (blocks) 496*2dff340aSSuraj Jitindar Singh Args 2-5: Number to mark dirty at offset (bytes) 497*2dff340aSSuraj Jitindar Singh 498*2dff340aSSuraj Jitindar Singh V2: 499*2dff340aSSuraj Jitindar Singh Args 0-1: Window offset to mark (blocks) 500*2dff340aSSuraj Jitindar Singh Args 2-3: Number to mark dirty at offset (blocks) 501*2dff340aSSuraj Jitindar Singh 502c442b710SCyril Bur Response: 503c442b710SCyril Bur - 5049dd93cfaSCyril Bur Notes: 505*2dff340aSSuraj Jitindar Singh The BMC has no method for intercepting writes that 506*2dff340aSSuraj Jitindar Singh occur over the LPC bus. The host must explicitly notify 507*2dff340aSSuraj Jitindar Singh the daemon of where and when a write has occured so it 508*2dff340aSSuraj Jitindar Singh can be flushed to backing storage. 5099dd93cfaSCyril Bur 510*2dff340aSSuraj Jitindar Singh Offsets are given as an absolute (either into flash (V1) or the 511*2dff340aSSuraj Jitindar Singh active window (V2)) and a zero offset refers to the first 512*2dff340aSSuraj Jitindar Singh block. If the offset + number exceeds the size of the active 513*2dff340aSSuraj Jitindar Singh window then the command must not succeed. 514c442b710SCyril Bur 515c442b710SCyril BurCommand 5169dd93cfaSCyril Bur WRITE_FLUSH 517*2dff340aSSuraj Jitindar Singh Implemented in Versions: 518*2dff340aSSuraj Jitindar Singh V1, V2 519*2dff340aSSuraj Jitindar Singh Arguments: 520*2dff340aSSuraj Jitindar Singh V1: 521*2dff340aSSuraj Jitindar Singh Args 0-1: Flash offset to mark from base of flash (blocks) 522*2dff340aSSuraj Jitindar Singh Args 2-5: Number to mark dirty at offset (bytes) 523*2dff340aSSuraj Jitindar Singh 524*2dff340aSSuraj Jitindar Singh V2: 525*2dff340aSSuraj Jitindar Singh - 526*2dff340aSSuraj Jitindar Singh 527c442b710SCyril Bur Response: 528c442b710SCyril Bur - 5299dd93cfaSCyril Bur Notes: 530*2dff340aSSuraj Jitindar Singh Flushes any dirty/erased blocks in the active window to 531*2dff340aSSuraj Jitindar Singh the backing storage. 532*2dff340aSSuraj Jitindar Singh 533*2dff340aSSuraj Jitindar Singh In V1 this can also be used to mark parts of the flash 534*2dff340aSSuraj Jitindar Singh dirty and flush in a single command. In V2 the explicit 535*2dff340aSSuraj Jitindar Singh mark dirty command must be used before a call to flush 536*2dff340aSSuraj Jitindar Singh since there are no longer any arguments. If the offset + number 537*2dff340aSSuraj Jitindar Singh exceeds the size of the active window then the command must not 538*2dff340aSSuraj Jitindar Singh succeed. 5399dd93cfaSCyril Bur 540c442b710SCyril Bur 541c442b710SCyril BurCommand: 5429dd93cfaSCyril Bur BMC_EVENT_ACK 543*2dff340aSSuraj Jitindar Singh Implemented in Versions: 544*2dff340aSSuraj Jitindar Singh V1, V2 545*2dff340aSSuraj Jitindar Singh Arguments: 546*2dff340aSSuraj Jitindar Singh Args 0: Bits in the BMC status byte (mailbox data 547*2dff340aSSuraj Jitindar Singh register 15) to ack 548c442b710SCyril Bur Response: 5499dd93cfaSCyril Bur *clears the bits in mailbox data register 15* 5509dd93cfaSCyril Bur Notes: 551*2dff340aSSuraj Jitindar Singh The host should use this command to acknowledge BMC events 5529dd93cfaSCyril Bur supplied in mailbox register 15. 553c442b710SCyril Bur 554*2dff340aSSuraj Jitindar SinghCommand: 555*2dff340aSSuraj Jitindar Singh MARK_WRITE_ERASED 556*2dff340aSSuraj Jitindar Singh Implemented in Versions: 557*2dff340aSSuraj Jitindar Singh V2 558*2dff340aSSuraj Jitindar Singh Arguments: 559*2dff340aSSuraj Jitindar Singh V2: 560*2dff340aSSuraj Jitindar Singh Args 0-1: Window offset to erase (blocks) 561*2dff340aSSuraj Jitindar Singh Args 2-3: Number to erase at offset (blocks) 562*2dff340aSSuraj Jitindar Singh Response: 563*2dff340aSSuraj Jitindar Singh - 564*2dff340aSSuraj Jitindar Singh Notes: 565*2dff340aSSuraj Jitindar Singh This command allows the host to erase a large area 566*2dff340aSSuraj Jitindar Singh without the need to individually write 0xFF 567*2dff340aSSuraj Jitindar Singh repetitively. 568c442b710SCyril Bur 569*2dff340aSSuraj Jitindar Singh Offset is the offset within the active window to start erasing 570*2dff340aSSuraj Jitindar Singh from (zero refers to the first block of the active window) and 571*2dff340aSSuraj Jitindar Singh number is the number of blocks of the active window to erase 572*2dff340aSSuraj Jitindar Singh starting at offset. If the offset + number exceeds the size of 573*2dff340aSSuraj Jitindar Singh the active window then the command must not succeed. 574*2dff340aSSuraj Jitindar Singh``` 575*2dff340aSSuraj Jitindar Singh 576*2dff340aSSuraj Jitindar Singh### BMC Events in Detail: 577*2dff340aSSuraj Jitindar Singh 578c442b710SCyril BurIf the BMC needs to tell the host something then it simply 579c442b710SCyril Burwrites to Byte 15. The host should have interrupts enabled 5809dd93cfaSCyril Buron that register, or otherwise be polling it. 581*2dff340aSSuraj Jitindar Singh 582*2dff340aSSuraj Jitindar Singh#### Bit Definitions: 583*2dff340aSSuraj Jitindar Singh 584*2dff340aSSuraj Jitindar SinghEvents which should be ACKed: 585*2dff340aSSuraj Jitindar Singh``` 586*2dff340aSSuraj Jitindar Singh0x01: BMC Reboot 587*2dff340aSSuraj Jitindar Singh0x02: BMC Windows Reset (V2) 588*2dff340aSSuraj Jitindar Singh``` 589*2dff340aSSuraj Jitindar Singh 590*2dff340aSSuraj Jitindar SinghEvents which cannot be ACKed (BMC will clear when no longer 591*2dff340aSSuraj Jitindar Singhapplicable): 592*2dff340aSSuraj Jitindar Singh``` 593*2dff340aSSuraj Jitindar Singh0x40: BMC Flash Control Lost (V2) 594*2dff340aSSuraj Jitindar Singh0x80: BMC MBOX Daemon Ready (V2) 595*2dff340aSSuraj Jitindar Singh``` 596*2dff340aSSuraj Jitindar Singh 597*2dff340aSSuraj Jitindar Singh#### Event Description: 598*2dff340aSSuraj Jitindar Singh 599*2dff340aSSuraj Jitindar SinghEvents which must be ACKed: 600*2dff340aSSuraj Jitindar SinghThe host should acknowledge these events with BMC_EVENT_ACK to 601*2dff340aSSuraj Jitindar Singhlet the BMC know that they have been received and understood. 602*2dff340aSSuraj Jitindar Singh``` 603*2dff340aSSuraj Jitindar Singh0x01 - BMC Reboot: 604*2dff340aSSuraj Jitindar Singh Used to inform the host that a BMC reboot has occured. 605*2dff340aSSuraj Jitindar Singh The host must perform protocol verison negotiation again and 606*2dff340aSSuraj Jitindar Singh must assume it has no active window. The host must not assume 607*2dff340aSSuraj Jitindar Singh that any commands which didn't respond as such succeeded. 608*2dff340aSSuraj Jitindar Singh0x02 - BMC Windows Reset: (V2) 609*2dff340aSSuraj Jitindar Singh The host must assume that its active window has been closed and 610*2dff340aSSuraj Jitindar Singh that it no longer has an active window. The host is not 611*2dff340aSSuraj Jitindar Singh required to perform protocol version negotiation again. The 612*2dff340aSSuraj Jitindar Singh host must not assume that any commands which didn't respond as such 613*2dff340aSSuraj Jitindar Singh succeeded. 614*2dff340aSSuraj Jitindar Singh``` 615*2dff340aSSuraj Jitindar Singh 616*2dff340aSSuraj Jitindar SinghEvents which cannot be ACKed: 617*2dff340aSSuraj Jitindar SinghThese events cannot be acknowledged by the host and a call to 618*2dff340aSSuraj Jitindar SinghBMC_EVENT_ACK with these bits set will have no effect. The BMC 619*2dff340aSSuraj Jitindar Singhwill clear these bits when they are no longer applicable. 620*2dff340aSSuraj Jitindar Singh``` 621*2dff340aSSuraj Jitindar Singh0x40 - BMC Flash Control Lost: (V2) 622*2dff340aSSuraj Jitindar Singh The BMC daemon has been suspended and thus no longer 623*2dff340aSSuraj Jitindar Singh controls access to the flash (most likely because some 624*2dff340aSSuraj Jitindar Singh other process on the BMC required direct access to the 625*2dff340aSSuraj Jitindar Singh flash and has suspended the BMC daemon to preclude 626*2dff340aSSuraj Jitindar Singh concurrent access). 627*2dff340aSSuraj Jitindar Singh The BMC daemon must clear this bit itself when it regains 628*2dff340aSSuraj Jitindar Singh control of the flash (the host isn't able to clear it 629*2dff340aSSuraj Jitindar Singh through an acknowledge command). 630*2dff340aSSuraj Jitindar Singh The host must not assume that the contents of the active window 631*2dff340aSSuraj Jitindar Singh correctly reflect the contents of flash while this bit is set. 632*2dff340aSSuraj Jitindar Singh0x80 - BMC MBOX Daemon Ready: (V2) 633*2dff340aSSuraj Jitindar Singh Used to inform the host that the BMC daemon is ready to 634*2dff340aSSuraj Jitindar Singh accept command requests. The host isn't able to clear 635*2dff340aSSuraj Jitindar Singh this bit through an acknowledge command, the BMC daemon must 636*2dff340aSSuraj Jitindar Singh clear it before it terminates (assuming it didn't 637*2dff340aSSuraj Jitindar Singh terminate unexpectedly). 638*2dff340aSSuraj Jitindar Singh The host should not expect a response while this bit is 639*2dff340aSSuraj Jitindar Singh not set. 640*2dff340aSSuraj Jitindar Singh Note that this bit being set is not a guarantee that the BMC daemon 641*2dff340aSSuraj Jitindar Singh will respond as it or the BMC may have crashed without clearing 642*2dff340aSSuraj Jitindar Singh it. 643c442b710SCyril Bur``` 644