xref: /openbmc/phosphor-mboxd/Documentation/mbox_protocol.md (revision acdbdd141ece313f259ad6231e132f0a4bc3e062)
1*acdbdd14SAndrew JefferyCopyright 2017,2018 IBM
204e8ffdaSSuraj Jitindar Singh
304e8ffdaSSuraj Jitindar SinghLicensed under the Apache License, Version 2.0 (the "License");
404e8ffdaSSuraj Jitindar Singhyou may not use this file except in compliance with the License.
504e8ffdaSSuraj Jitindar SinghYou may obtain a copy of the License at
604e8ffdaSSuraj Jitindar Singh
704e8ffdaSSuraj Jitindar Singh  http://www.apache.org/licenses/LICENSE-2.0
804e8ffdaSSuraj Jitindar Singh
904e8ffdaSSuraj Jitindar SinghUnless required by applicable law or agreed to in writing, software
1004e8ffdaSSuraj Jitindar Singhdistributed under the License is distributed on an "AS IS" BASIS,
1104e8ffdaSSuraj Jitindar SinghWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1204e8ffdaSSuraj Jitindar SinghSee the License for the specific language governing permissions and
1304e8ffdaSSuraj Jitindar Singhlimitations under the License.
1404e8ffdaSSuraj Jitindar Singh
1504e8ffdaSSuraj Jitindar Singh## Intro
1604e8ffdaSSuraj Jitindar Singh
1704e8ffdaSSuraj Jitindar SinghThis document describes a protocol for host to BMC communication via the
1804e8ffdaSSuraj Jitindar Singhmailbox registers present on the Aspeed 2400 and 2500 chips.
1904e8ffdaSSuraj Jitindar SinghThis protocol is specifically designed to allow a host to request and manage
206577ef34SSuraj Jitindar Singhaccess to a flash device(s) with the specifics of how the host is required to
216577ef34SSuraj Jitindar Singhcontrol this described below.
2204e8ffdaSSuraj Jitindar Singh
2304e8ffdaSSuraj Jitindar Singh## Version
2404e8ffdaSSuraj Jitindar Singh
256577ef34SSuraj Jitindar SinghVersion specific protocol functionalities are represented by the version number
266577ef34SSuraj Jitindar Singhin brackets next to the definition of the functionality. (e.g. (V2) for version
276577ef34SSuraj Jitindar Singh2 specific funtionality). All version specific functionality must also be
286577ef34SSuraj Jitindar Singhimplemented by proceeding versions up to and not including the version a command
296577ef34SSuraj Jitindar Singhwas removed.
3004e8ffdaSSuraj Jitindar Singh
3104e8ffdaSSuraj Jitindar Singh## Problem Overview
3204e8ffdaSSuraj Jitindar Singh
3304e8ffdaSSuraj Jitindar Singh"mbox" is the name we use to represent a protocol we have established between
3404e8ffdaSSuraj Jitindar Singhthe host and the BMC via the Aspeed mailbox registers. This protocol is used
356577ef34SSuraj Jitindar Singhfor the host to control access to the flash device(s).
3604e8ffdaSSuraj Jitindar Singh
3704e8ffdaSSuraj Jitindar SinghPrior to the mbox protocol, the host uses a backdoor into the BMC address space
3804e8ffdaSSuraj Jitindar Singh(the iLPC-to-AHB bridge) to directly manipulate the BMCs own flash controller.
3904e8ffdaSSuraj Jitindar Singh
4004e8ffdaSSuraj Jitindar SinghThis is not sustainable for a number of reasons. The main ones are:
4104e8ffdaSSuraj Jitindar Singh
4204e8ffdaSSuraj Jitindar Singh1. Every piece of the host software stack that needs flash access (HostBoot,
4304e8ffdaSSuraj Jitindar Singh   OCC, OPAL, ...) has to have a complete driver for the flash controller,
4404e8ffdaSSuraj Jitindar Singh   update it on each BMC generation, have all the quirks for all the flash
4504e8ffdaSSuraj Jitindar Singh   chips supported etc... We have 3 copies on the host already in addition to
4604e8ffdaSSuraj Jitindar Singh   the one in the BMC itself.
4704e8ffdaSSuraj Jitindar Singh
4804e8ffdaSSuraj Jitindar Singh2. There are serious issues of access conflicts to that controller between the
4904e8ffdaSSuraj Jitindar Singh   host and the BMC.
5004e8ffdaSSuraj Jitindar Singh
5104e8ffdaSSuraj Jitindar Singh3. It's very hard to support "BMC reboots" when doing that
5204e8ffdaSSuraj Jitindar Singh
5304e8ffdaSSuraj Jitindar Singh4. It's slow
5404e8ffdaSSuraj Jitindar Singh
5504e8ffdaSSuraj Jitindar Singh5. Last but probably most important, having that backdoor open is a security
5604e8ffdaSSuraj Jitindar Singh   risk. It means the host can access any address on the BMC internal bus and
5704e8ffdaSSuraj Jitindar Singh   implant malware in the BMC itself. So if the host is a "bare metal" shared
5804e8ffdaSSuraj Jitindar Singh   system in some kind of data center, not only the host flash needs to be
5904e8ffdaSSuraj Jitindar Singh   reflashed when switching from one customer to another, but the entire BMC
6004e8ffdaSSuraj Jitindar Singh   flash too as nothing can be trusted. So we want to disable it.
6104e8ffdaSSuraj Jitindar Singh
6204e8ffdaSSuraj Jitindar SinghTo address all these, we have implemented a new mechanism that we call mbox.
6304e8ffdaSSuraj Jitindar Singh
6404e8ffdaSSuraj Jitindar SinghWhen using this mechanism, the BMC is solely responsible for directly accessing
6504e8ffdaSSuraj Jitindar Singhthe flash controller. All flash erase and write operations are performed by the
6604e8ffdaSSuraj Jitindar SinghBMC and the BMC only. (We can allow direct reads from flash under some
6704e8ffdaSSuraj Jitindar Singhcircumstances but we tend to prefer going via memory).
6804e8ffdaSSuraj Jitindar Singh
6904e8ffdaSSuraj Jitindar SinghThe host uses the mailbox registers to send "commands" to the BMC, which
7004e8ffdaSSuraj Jitindar Singhresponds via the same mechanism. Those commands allow the host to control a
7104e8ffdaSSuraj Jitindar Singh"window" (which is the LPC -> AHB FW space mapping) that is either a read
7204e8ffdaSSuraj Jitindar Singhwindow or a write window onto the flash.
7304e8ffdaSSuraj Jitindar Singh
7404e8ffdaSSuraj Jitindar SinghWhen set for writing, the BMC makes the window point to a chunk of RAM instead.
7504e8ffdaSSuraj Jitindar SinghWhen the host "commits" a change (via MBOX), then the BMC can perform the
7604e8ffdaSSuraj Jitindar Singhactual flashing from the data in the RAM window.
7704e8ffdaSSuraj Jitindar Singh
7804e8ffdaSSuraj Jitindar SinghThe idea is to have the LPC FW space be routed to an active "window".  That
7904e8ffdaSSuraj Jitindar Singhwindow can be a read or a write window. The commands allow to control which
8004e8ffdaSSuraj Jitindar Singhwindow and which offset into the flash it maps.
8104e8ffdaSSuraj Jitindar Singh
8204e8ffdaSSuraj Jitindar Singh* A read window can be a direct window to the flash controller space (ie.
8304e8ffdaSSuraj Jitindar Singh  0x3000\_0000) or it can be a window to a RAM image of a flash. It doesn't have
844bcf02bfSGunnar Mills  to be the full size of the flash per protocol (commands can be used to "slide"
854bcf02bfSGunnar Mills  it to various parts of the flash) but if it's set to map the actual flash
8604e8ffdaSSuraj Jitindar Singh  controller space at 0x3000\_0000, it's probably simpler to make it the full
8704e8ffdaSSuraj Jitindar Singh  flash. The host makes no assumption, it's your choice what to provide. The
8804e8ffdaSSuraj Jitindar Singh  simplest implementation is to just route to the flash read/only.
8904e8ffdaSSuraj Jitindar Singh
9004e8ffdaSSuraj Jitindar Singh* A write window has to be a chunk of BMC memory. The minimum size is not
9104e8ffdaSSuraj Jitindar Singh  defined in the spec, but it should be at least one block (4k for now but it
9204e8ffdaSSuraj Jitindar Singh  should support larger block sizes in the future). When the BMC receive the
9304e8ffdaSSuraj Jitindar Singh  command to map the write window at a given offset of the flash, the BMC should
9404e8ffdaSSuraj Jitindar Singh  copy that portion of the flash into a reserved memory buffer, and modify the
9504e8ffdaSSuraj Jitindar Singh  LPC mapping to point to that buffer.
9604e8ffdaSSuraj Jitindar Singh
9704e8ffdaSSuraj Jitindar SinghThe host can then write to that window directly (updating the BMC memory) and
9804e8ffdaSSuraj Jitindar Singhsend a command to "commit" those updates to flash.
9904e8ffdaSSuraj Jitindar Singh
1004bcf02bfSGunnar MillsFinally, there is a `RESET_STATE`. It's the state in which the bootloader in the
10104e8ffdaSSuraj Jitindar SinghSEEPROM of the POWER9 chip will find what it needs to load HostBoot. The
10204e8ffdaSSuraj Jitindar Singhdetails are still being ironed out: either mapping the full flash read only or
10304e8ffdaSSuraj Jitindar Singhreset to a "window" that is either at the bottom or top of the flash. The
10404e8ffdaSSuraj Jitindar Singhcurrent implementation resets to point to the full flash.
10504e8ffdaSSuraj Jitindar Singh
10604e8ffdaSSuraj Jitindar Singh## Where is the code?
10704e8ffdaSSuraj Jitindar Singh
10804e8ffdaSSuraj Jitindar SinghThe mbox userspace is available [on GitHub](https://github.com/openbmc/mboxbridge)
10904e8ffdaSSuraj Jitindar SinghThis is Apache licensed but we are keen to see any enhancements you may have.
11004e8ffdaSSuraj Jitindar Singh
11104e8ffdaSSuraj Jitindar SinghThe kernel driver is still in the process of being upstreamed but can be found
11204e8ffdaSSuraj Jitindar Singhin the OpenBMC Linux kernel staging tree:
11304e8ffdaSSuraj Jitindar Singh
11404e8ffdaSSuraj Jitindar Singhhttps://github.com/openbmc/linux/commit/85770a7d1caa6a1fa1a291c33dfe46e05755a2ef
11504e8ffdaSSuraj Jitindar Singh
11604e8ffdaSSuraj Jitindar Singh## Building
11704e8ffdaSSuraj Jitindar Singh
1184bcf02bfSGunnar MillsThe Autotools of this requires the autoconf-archive package for your
11904e8ffdaSSuraj Jitindar Singhsystem
12004e8ffdaSSuraj Jitindar Singh
12104e8ffdaSSuraj Jitindar Singh## The Hardware
12204e8ffdaSSuraj Jitindar Singh
12304e8ffdaSSuraj Jitindar SinghThe Aspeed mailbox consists of 16 (8 bit) data registers see Layout for their
12404e8ffdaSSuraj Jitindar Singhuse. Mailbox interrupt enabling, masking and triggering is done using a pair
12504e8ffdaSSuraj Jitindar Singhof control registers, one accessible by the host the other by the BMC.
12604e8ffdaSSuraj Jitindar SinghInterrupts can also be raised per write to each data register, for BMC and
1274bcf02bfSGunnar Millshost. Write triggered interrupts are configured using two 8 bit registers where
12804e8ffdaSSuraj Jitindar Singheach bit represents a data register and if an interrupt should fire on write.
12904e8ffdaSSuraj Jitindar SinghTwo 8 bit registers are present to act as a mask for write triggered
13004e8ffdaSSuraj Jitindar Singhinterrupts.
13104e8ffdaSSuraj Jitindar Singh
13204e8ffdaSSuraj Jitindar Singh### Layout
13304e8ffdaSSuraj Jitindar Singh
13404e8ffdaSSuraj Jitindar Singh```
13504e8ffdaSSuraj Jitindar SinghByte 0: COMMAND
13604e8ffdaSSuraj Jitindar SinghByte 1: Sequence
13704e8ffdaSSuraj Jitindar SinghByte 2-12: Arguments
13804e8ffdaSSuraj Jitindar SinghByte 13: Response code
13904e8ffdaSSuraj Jitindar SinghByte 14: Host controlled status reg
14004e8ffdaSSuraj Jitindar SinghByte 15: BMC controlled status reg
14104e8ffdaSSuraj Jitindar Singh```
14204e8ffdaSSuraj Jitindar Singh
143a92f1752SSuraj Jitindar SinghNote: when the BMC is writing a response to the mbox registers (as described
144a92f1752SSuraj Jitindar Singhabove), the "Response Code" (Register 13) must be the last register written to.
145a92f1752SSuraj Jitindar SinghWriting register 13 will trigger an interrupt to the host indicating a complete
146a92f1752SSuraj Jitindar Singhresponse has been written. Triggering the interrupt by writing register 13
1474bcf02bfSGunnar Millsprior to completing the response may lead to a data race, and must, therefore,
148a92f1752SSuraj Jitindar Singhbe avoided.
149a92f1752SSuraj Jitindar Singh
15004e8ffdaSSuraj Jitindar Singh## Low Level Protocol Flow
15104e8ffdaSSuraj Jitindar Singh
15204e8ffdaSSuraj Jitindar SinghWhat we essentially have is a set of registers which either the host or BMC can
15304e8ffdaSSuraj Jitindar Singhwrite to in order to communicate to the other which will respond in some way.
15404e8ffdaSSuraj Jitindar SinghThere are 3 basic types of communication.
15504e8ffdaSSuraj Jitindar Singh
15604e8ffdaSSuraj Jitindar Singh1. Commands sent from the Host to the BMC
15704e8ffdaSSuraj Jitindar Singh2. Responses sent from the BMC to the Host in response to commands
1584bcf02bfSGunnar Mills3. Asynchronous events raised by the BMC
15904e8ffdaSSuraj Jitindar Singh
16004e8ffdaSSuraj Jitindar Singh### General Use
16104e8ffdaSSuraj Jitindar Singh
16204e8ffdaSSuraj Jitindar SinghMessages usually originate from the host to the BMC. There are special
16304e8ffdaSSuraj Jitindar Singhcases for a back channel for the BMC to pass new information to the
16404e8ffdaSSuraj Jitindar Singhhost which will be discussed later.
16504e8ffdaSSuraj Jitindar Singh
16655dede6bSAndrew JefferyTo initiate a request the host must set a command code (see Commands) into
16755dede6bSAndrew Jefferymailbox data register 0, and generate a sequence number (see Sequence Numbers)
16855dede6bSAndrew Jefferyto write to mailbox register data 1. After these two values, any
16955dede6bSAndrew Jefferycommand-specific data should be written (see Layout). The host must then
17055dede6bSAndrew Jefferygenerate an interrupt to the BMC by using bit 0 of its control register and
17155dede6bSAndrew Jefferywait for an interrupt on the response register.  Generating an interrupt
17255dede6bSAndrew Jefferyautomatically sets bit 7 of the corresponding control register. This bit can be
17355dede6bSAndrew Jefferyused to poll for messages.
17404e8ffdaSSuraj Jitindar Singh
17504e8ffdaSSuraj Jitindar SinghOn receiving an interrupt (or polling on bit 7 of its Control
17604e8ffdaSSuraj Jitindar SinghRegister) the BMC should read the message from the general registers
17704e8ffdaSSuraj Jitindar Singhof the mailbox and perform the necessary action before responding. On
17804e8ffdaSSuraj Jitindar Singhresponding the BMC must ensure that the sequence number is the same as
17904e8ffdaSSuraj Jitindar Singhthe one in the request from the host. The BMC must also ensure that
180591b817fSAndrew Jefferymailbox data register 13 is a valid response code (see Responses). The
18104e8ffdaSSuraj Jitindar SinghBMC should then use its control register to generate an interrupt for
18204e8ffdaSSuraj Jitindar Singhthe host to notify it of a response.
18304e8ffdaSSuraj Jitindar Singh
18404e8ffdaSSuraj Jitindar Singh### Asynchronous BMC to Host Events
18504e8ffdaSSuraj Jitindar Singh
18604e8ffdaSSuraj Jitindar SinghBMC to host communication is also possible for notification of events
18704e8ffdaSSuraj Jitindar Singhfrom the BMC. This requires that the host have interrupts enabled on
18804e8ffdaSSuraj Jitindar Singhmailbox data register 15 (or otherwise poll on bit 7 of mailbox status
18904e8ffdaSSuraj Jitindar Singhregister 1). On receiving such a notification the host should read
19004e8ffdaSSuraj Jitindar Singhmailbox data register 15 to determine the event code which was set by the
19104e8ffdaSSuraj Jitindar SinghBMC (see BMC Event notifications in Commands for detail). Events which are
19204e8ffdaSSuraj Jitindar Singhdefined as being able to be acknowledged by the host must be with a
19304e8ffdaSSuraj Jitindar SinghBMC_EVENT_ACK command.
19404e8ffdaSSuraj Jitindar Singh
19504e8ffdaSSuraj Jitindar Singh## High Level Protocol Flow
19604e8ffdaSSuraj Jitindar Singh
19704e8ffdaSSuraj Jitindar SinghWhen a host wants to communicate with the BMC via the mbox protocol the first
19804e8ffdaSSuraj Jitindar Singhthing it should do it call MBOX_GET_INFO in order to establish the protocol
1994bcf02bfSGunnar Millsversion which each understands. Before this, the only other commands which are
20004e8ffdaSSuraj Jitindar Singhallowed are RESET_STATE and BMC_EVENT_ACK.
20104e8ffdaSSuraj Jitindar Singh
2024bcf02bfSGunnar MillsAfter this, the host can open and close windows with the CREATE_READ_WINDOW,
20304e8ffdaSSuraj Jitindar SinghCREATE_WRITE_WINDOW and CLOSE_WINDOW commands. Creating a window is how the
20404e8ffdaSSuraj Jitindar Singhhost requests access to a section of flash. It is worth noting that the host
20504e8ffdaSSuraj Jitindar Singhcan only ever have one window that it is accessing at a time - hence forth
20604e8ffdaSSuraj Jitindar Singhreferred to as the active window.
20704e8ffdaSSuraj Jitindar Singh
20804e8ffdaSSuraj Jitindar SinghWhen the active window is a write window the host can perform MARK_WRITE_DIRTY,
20904e8ffdaSSuraj Jitindar SinghMARK_WRITE_ERASED and WRITE_FLUSH commands to identify changed blocks and
21004e8ffdaSSuraj Jitindar Singhcontrol when the changed blocks are written to flash.
21104e8ffdaSSuraj Jitindar Singh
21204e8ffdaSSuraj Jitindar SinghIndependently, and at any point not during an existing mbox command
2134bcf02bfSGunnar Millstransaction, the BMC may raise asynchronous events with the host to
21404e8ffdaSSuraj Jitindar Singhcommunicate a change in state.
21504e8ffdaSSuraj Jitindar Singh
21604e8ffdaSSuraj Jitindar Singh### Version Negotiation
21704e8ffdaSSuraj Jitindar Singh
21804e8ffdaSSuraj Jitindar SinghGiven that a majority of command and response arguments are specified as a
21904e8ffdaSSuraj Jitindar Singhmultiple of block size it is necessary for the host and BMC to agree on a
22004e8ffdaSSuraj Jitindar Singhprotocol version as this determines the block size. In V1 it is hard coded at
2216577ef34SSuraj Jitindar Singh4K, in V2 the BMC chooses and in V3 the host is allowed to request a specific
2226577ef34SSuraj Jitindar Singhblock size with the actual size chosen communicated back to the host as a
2236577ef34SSuraj Jitindar Singhresponse argument to `MBOX_GET_INFO`. Thus the host must always call
2246577ef34SSuraj Jitindar Singh`MBOX_GET_INFO` before any other command which specifies an argument in block
2256577ef34SSuraj Jitindar Singhsize.
22604e8ffdaSSuraj Jitindar Singh
227fb25aa77SAndrew JefferyWhen invoking `MBOX_GET_INFO` the host must provide the BMC its highest
228fb25aa77SAndrew Jefferysupported version of the protocol. The BMC must respond with a protocol version
229fb25aa77SAndrew Jefferyless than or equal to that requested by the host, or in the event that there is
230fb25aa77SAndrew Jefferyno such value, an error code. In the event that an error is returned the host
231fb25aa77SAndrew Jefferymust not continue to communicate with the BMC. Otherwise, the protocol version
232fb25aa77SAndrew Jefferyreturned by the BMC is the agreed protocol version for all further
233fb25aa77SAndrew Jefferycommunication. The host may at a future point request a change in protocol
234fb25aa77SAndrew Jefferyversion by issuing a subsequent `MBOX_GET_INFO` command.
23504e8ffdaSSuraj Jitindar Singh
23604e8ffdaSSuraj Jitindar Singh### Window Management
23704e8ffdaSSuraj Jitindar Singh
2384bcf02bfSGunnar MillsIn order to access flash contents, the host must request a window be opened at
2396577ef34SSuraj Jitindar Singhthe flash offset it would like to access with the CREATE_{READ,WRITE}_WINDOW
2406577ef34SSuraj Jitindar Singhcommands. The host may give a hint as to how much data it would like to access
2416577ef34SSuraj Jitindar Singhor otherwise set this argument to zero. The BMC must respond with the LPC bus
2426577ef34SSuraj Jitindar Singhaddress to access this window and the window size. The host must not access
2436577ef34SSuraj Jitindar Singhpast the end of the active window. On returning success to either of the create
2446577ef34SSuraj Jitindar Singhwindow commands the BMC must guarantee that the window provided contains data
2456577ef34SSuraj Jitindar Singhwhich correctly represents the state of flash at the time the response is given.
24604e8ffdaSSuraj Jitindar Singh
24704e8ffdaSSuraj Jitindar SinghThere is only ever one active window which is the window created by the most
24804e8ffdaSSuraj Jitindar Singhrecent CREATE_READ_WINDOW or CREATE_WRITE_WINDOW call which succeeded. Even
24904e8ffdaSSuraj Jitindar Singhthough there are two types of windows there can still only be one active window
25004e8ffdaSSuraj Jitindar Singhirrespective of type. A host must not write to a read window. A host may read
25104e8ffdaSSuraj Jitindar Singhfrom a write window and the BMC must guarantee that the window reflects what
25204e8ffdaSSuraj Jitindar Singhthe host has written there.
25304e8ffdaSSuraj Jitindar Singh
25404e8ffdaSSuraj Jitindar SinghA window can be closed by calling CLOSE_WINDOW in which case there is no active
25504e8ffdaSSuraj Jitindar Singhwindow and the host must not access the LPC window after it has been closed.
25604e8ffdaSSuraj Jitindar SinghIf the host closes an active write window then the BMC must perform an
25704e8ffdaSSuraj Jitindar Singhimplicit flush. If the host tries to open a new window with an already active
25804e8ffdaSSuraj Jitindar Singhwindow then the active window is closed (and implicitly flushed if it was a
25904e8ffdaSSuraj Jitindar Singhwrite window). If the new window is successfully opened then it is the new
26004e8ffdaSSuraj Jitindar Singhactive window, if the command fails then there is no active window and the
2614bcf02bfSGunnar Millspreviously active window must no longer be accessed.
26204e8ffdaSSuraj Jitindar Singh
2634bcf02bfSGunnar MillsThe host must not access an LPC address other than that which is contained by
26404e8ffdaSSuraj Jitindar Singhthe active window. The host must not use write management functions (see below)
26504e8ffdaSSuraj Jitindar Singhif the active window is a read window or if there is no active window.
26604e8ffdaSSuraj Jitindar Singh
26704e8ffdaSSuraj Jitindar Singh### Write Management
26804e8ffdaSSuraj Jitindar Singh
26904e8ffdaSSuraj Jitindar SinghThe BMC has no method for intercepting writes that occur over the LPC bus. Thus
27004e8ffdaSSuraj Jitindar Singhthe host must explicitly notify the BMC of where and when a write has
2714bcf02bfSGunnar Millsoccurred. The host must use the MARK_WRITE_DIRTY command to tell the BMC where
27204e8ffdaSSuraj Jitindar Singhwithin the write window it has modified. The host may also use the
27304e8ffdaSSuraj Jitindar SinghMARK_WRITE_ERASED command to erase large parts of the active window without the
27404e8ffdaSSuraj Jitindar Singhneed to write 0xFF. The BMC must ensure that if the host
27504e8ffdaSSuraj Jitindar Singhreads from an area it has erased that the read values are 0xFF. Any part of the
27604e8ffdaSSuraj Jitindar Singhactive window marked dirty/erased is only marked for the lifetime of the current
27704e8ffdaSSuraj Jitindar Singhactive write window and does not persist if the active window is closed either
27804e8ffdaSSuraj Jitindar Singhimplicitly or explicitly by the host or the BMC. The BMC may at any time
27904e8ffdaSSuraj Jitindar Singhor must on a call to WRITE_FLUSH flush the changes which it has been notified
28004e8ffdaSSuraj Jitindar Singhof back to the flash, at which point the dirty or erased marking is cleared
28104e8ffdaSSuraj Jitindar Singhfor the active window. The host must not assume that any changes have been
28204e8ffdaSSuraj Jitindar Singhwritten to flash unless an explicit flush call was successful, a close of an
28304e8ffdaSSuraj Jitindar Singhactive write window was successful or a create window command with an active
28404e8ffdaSSuraj Jitindar Singhwrite window was successful - otherwise consistency between the flash and memory
28504e8ffdaSSuraj Jitindar Singhcontents cannot be guaranteed.
28604e8ffdaSSuraj Jitindar Singh
28704e8ffdaSSuraj Jitindar SinghThe host is not required to perform an erase before a write command and the
28804e8ffdaSSuraj Jitindar SinghBMC must ensure that a write performs as expected - that is if an erase is
2896577ef34SSuraj Jitindar Singhrequired before a write then the BMC must perform this itself (unless the
2906577ef34SSuraj Jitindar Singhno_erase flag is set in the MARK_WRITE_DIRTY command in which case the BMC will
2916577ef34SSuraj Jitindar Singhblindly write without a prior erase (V3)).
2926577ef34SSuraj Jitindar Singh
2936577ef34SSuraj Jitindar SinghThe host may lock an area of flash using the MARK_LOCKED command. Any attempt
2946577ef34SSuraj Jitindar Singhto mark dirty or erased this area of flash must fail with the LOCKED_ERROR
2956577ef34SSuraj Jitindar Singhresponse code. The host may open a write window which contains a locked area
2966577ef34SSuraj Jitindar Singhof flash however changes to a locked area of flash must never be written back
2976577ef34SSuraj Jitindar Singhto the backing data source (i.e. that area of flash must be treated as read
2986577ef34SSuraj Jitindar Singhonly with respect to the backing store at all times). An attempt to lock an area
2996577ef34SSuraj Jitindar Singhof flash which is not clean in the current window must fail with PARAM_ERROR.
3006577ef34SSuraj Jitindar SinghLocked flash regions must persist across a BMC reboot or daemon restart. It is
3016577ef34SSuraj Jitindar Singhonly possible to clear the lock state through a clear_locked dbus command. (V3)
30204e8ffdaSSuraj Jitindar Singh
30304e8ffdaSSuraj Jitindar Singh### BMC Events
30404e8ffdaSSuraj Jitindar Singh
30504e8ffdaSSuraj Jitindar SinghThe BMC can raise events with the host asynchronously to communicate to the
30604e8ffdaSSuraj Jitindar Singhhost a change in state which it should take notice of. The host must (if
30704e8ffdaSSuraj Jitindar Singhpossible for the given event) acknowledge it to inform the BMC it has been
30804e8ffdaSSuraj Jitindar Singhreceived.
30904e8ffdaSSuraj Jitindar Singh
31004e8ffdaSSuraj Jitindar SinghIf the BMC raises a BMC Reboot event then the host must renegotiate the
31104e8ffdaSSuraj Jitindar Singhprotocol version so that both the BMC and the host agree on the block size.
31204e8ffdaSSuraj Jitindar SinghA BMC Reboot event implies a BMC Windows Reset event.
31304e8ffdaSSuraj Jitindar SinghIf the BMC raises a BMC Windows Reset event then the host must
31404e8ffdaSSuraj Jitindar Singhassume that there is no longer an active window - that is if there was an
31504e8ffdaSSuraj Jitindar Singhactive window it has been closed by the BMC and if it was a write window
31604e8ffdaSSuraj Jitindar Singhthen the host must not assume that it was flushed unless a previous explicit
31704e8ffdaSSuraj Jitindar Singhflush call was successful.
31804e8ffdaSSuraj Jitindar Singh
31904e8ffdaSSuraj Jitindar SinghThe BMC may at some points require access to the flash and the BMC daemon must
32004e8ffdaSSuraj Jitindar Singhset the BMC Flash Control Lost event when the BMC is accessing the flash behind
32104e8ffdaSSuraj Jitindar Singhthe BMC daemons back. When this event is set the host must assume that the
32204e8ffdaSSuraj Jitindar Singhcontents of the active window could be inconsistent with the contents of flash.
32304e8ffdaSSuraj Jitindar Singh
32404e8ffdaSSuraj Jitindar Singh## Protocol Definition
32504e8ffdaSSuraj Jitindar Singh
32604e8ffdaSSuraj Jitindar Singh### Commands
32704e8ffdaSSuraj Jitindar Singh
32804e8ffdaSSuraj Jitindar Singh```
32904e8ffdaSSuraj Jitindar SinghRESET_STATE          0x01
33004e8ffdaSSuraj Jitindar SinghGET_MBOX_INFO        0x02
33104e8ffdaSSuraj Jitindar SinghGET_FLASH_INFO       0x03
33204e8ffdaSSuraj Jitindar SinghCREATE_READ_WINDOW   0x04
33304e8ffdaSSuraj Jitindar SinghCLOSE_WINDOW         0x05
33404e8ffdaSSuraj Jitindar SinghCREATE_WRITE_WINDOW  0x06
33504e8ffdaSSuraj Jitindar SinghMARK_WRITE_DIRTY     0x07
33604e8ffdaSSuraj Jitindar SinghWRITE_FLUSH          0x08
33704e8ffdaSSuraj Jitindar SinghBMC_EVENT_ACK        0x09
33804e8ffdaSSuraj Jitindar SinghMARK_WRITE_ERASED    0x0a	(V2)
3396577ef34SSuraj Jitindar SinghGET_FLASH_NAME       0x0b	(V3)
3406577ef34SSuraj Jitindar SinghMARK_LOCKED          0x0c	(V3)
34104e8ffdaSSuraj Jitindar Singh```
34204e8ffdaSSuraj Jitindar Singh
34304e8ffdaSSuraj Jitindar Singh### Responses
34404e8ffdaSSuraj Jitindar Singh
34504e8ffdaSSuraj Jitindar Singh```
34604e8ffdaSSuraj Jitindar SinghSUCCESS		1
34704e8ffdaSSuraj Jitindar SinghPARAM_ERROR	2
34804e8ffdaSSuraj Jitindar SinghWRITE_ERROR	3
34904e8ffdaSSuraj Jitindar SinghSYSTEM_ERROR	4
35004e8ffdaSSuraj Jitindar SinghTIMEOUT		5
35104e8ffdaSSuraj Jitindar SinghBUSY		6	(V2)
35204e8ffdaSSuraj Jitindar SinghWINDOW_ERROR	7	(V2)
35355dede6bSAndrew JefferySEQ_ERROR	8	(V2)
3546577ef34SSuraj Jitindar SinghLOCKED_ERROR	9	(V3)
35504e8ffdaSSuraj Jitindar Singh```
35604e8ffdaSSuraj Jitindar Singh
35755dede6bSAndrew Jeffery### Sequence Numbers
35855dede6bSAndrew Jeffery
35955dede6bSAndrew JefferySequence numbers are included in messages for correlation of commands and
3606577ef34SSuraj Jitindar Singhresponses. V1, V2 and V3 of the protocol permit either zero or one commands to
3616577ef34SSuraj Jitindar Singhbe in progress (yet to receive a response).
36255dede6bSAndrew Jeffery
36355dede6bSAndrew JefferyFor generality, the host must generate a sequence number that is unique with
36455dede6bSAndrew Jefferyrespect to the previous command (one that has received a response) and any
36555dede6bSAndrew Jefferyin-progress commands. Sequence numbers meeting this requirement are considered
36655dede6bSAndrew Jefferyvalid. The BMC's response to a command must contain the same sequence number
36755dede6bSAndrew Jefferyissued by the host as found in the relevant command.
36855dede6bSAndrew Jeffery
36955dede6bSAndrew JefferySequence numbers may be reused in accordance with the constraints outlined
3704bcf02bfSGunnar Millsabove. However, it is not an error if the BMC receives a `GET_MBOX_INFO` with an
37155dede6bSAndrew Jefferyinvalid sequence number. For all other cases, the BMC must respond with
37255dede6bSAndrew Jeffery`SEQ_ERROR` if the constraints are violated. If the host receives a `SEQ_ERROR`
37355dede6bSAndrew Jefferyresponse it must consider any in-progress commands to have failed. The host may
37455dede6bSAndrew Jefferyretry the affected command(s) after generating a suitable sequence number.
37555dede6bSAndrew Jeffery
37604e8ffdaSSuraj Jitindar Singh#### Description:
37704e8ffdaSSuraj Jitindar Singh
37804e8ffdaSSuraj Jitindar SinghSUCCESS		- Command completed successfully
37904e8ffdaSSuraj Jitindar Singh
38004e8ffdaSSuraj Jitindar SinghPARAM_ERROR	- Error with parameters supplied or command invalid
38104e8ffdaSSuraj Jitindar Singh
38204e8ffdaSSuraj Jitindar SinghWRITE_ERROR	- Error writing to the backing file system
38304e8ffdaSSuraj Jitindar Singh
38404e8ffdaSSuraj Jitindar SinghSYSTEM_ERROR	- Error in BMC performing system action
38504e8ffdaSSuraj Jitindar Singh
38604e8ffdaSSuraj Jitindar SinghTIMEOUT		- Timeout in performing action
38704e8ffdaSSuraj Jitindar Singh
38804e8ffdaSSuraj Jitindar SinghBUSY		- Daemon in suspended state (currently unable to access flash)
38904e8ffdaSSuraj Jitindar Singh		- Retry again later
39004e8ffdaSSuraj Jitindar Singh
39104e8ffdaSSuraj Jitindar SinghWINDOW_ERROR	- Command not valid for active window or no active window
39204e8ffdaSSuraj Jitindar Singh		- Try opening an appropriate window and retrying the command
39304e8ffdaSSuraj Jitindar Singh
3946577ef34SSuraj Jitindar SinghSEQ_ERROR	- Invalid sequence number supplied with command
3956577ef34SSuraj Jitindar Singh
3966577ef34SSuraj Jitindar SinghLOCKED_ERROR	- Tried to mark dirty or erased locked area of flash
3976577ef34SSuraj Jitindar Singh
39804e8ffdaSSuraj Jitindar Singh### Information
39904e8ffdaSSuraj Jitindar Singh- All multibyte messages are LSB first (little endian)
40004e8ffdaSSuraj Jitindar Singh- All responses must have a valid return code in byte 13
40104e8ffdaSSuraj Jitindar Singh
40204e8ffdaSSuraj Jitindar Singh
40304e8ffdaSSuraj Jitindar Singh### Commands in detail
40404e8ffdaSSuraj Jitindar Singh
4055a26e025SSuraj Jitindar SinghBlock size refers to an agreed value which is used as a unit for the
4065a26e025SSuraj Jitindar Singharguments of various commands and responses. Having a block size multiplier
4075a26e025SSuraj Jitindar Singhallows us to specify larger values with fewer command and response fields.
4085a26e025SSuraj Jitindar Singh
4095a26e025SSuraj Jitindar SinghIn V1 block size is hard coded to 4K.
4105a26e025SSuraj Jitindar SinghIn V2 it is variable and must be queried with the GET_MBOX_INFO command.
4116577ef34SSuraj Jitindar SinghIn V3 the host can request a given block size however it is ultimately up to
4126577ef34SSuraj Jitindar Singhthe daemon to choose a block size which is returned as part of the GET_MBOX_INFO
4136577ef34SSuraj Jitindar Singhcommand response. The host must respect the daemons choice. The ability for the
4146577ef34SSuraj Jitindar Singhhost to request a block size is provided such that it can choose an appropriate
4156577ef34SSuraj Jitindar Singhsize to be able to utilise commands which only operate at the block level.
4166577ef34SSuraj Jitindar Singh
4175a26e025SSuraj Jitindar SinghNote that for simplicity block size must always be a power-of-2.
4185a26e025SSuraj Jitindar SinghBlock size must also be greater than or equal to 4K. This is due to the
4195a26e025SSuraj Jitindar Singhfact that we have a 28-bit LPC address space and commands which return an
4205a26e025SSuraj Jitindar SinghLPC address do so in 16 bits, thus we need at least a 12-bit unit to ensure
4215a26e025SSuraj Jitindar Singhthat we can specify the entire address space. This additionally allows us
4225a26e025SSuraj Jitindar Singhto specify flash addresses of at least 256MB.
4235a26e025SSuraj Jitindar Singh
42404e8ffdaSSuraj Jitindar SinghSizes and addresses are specified in either bytes - (bytes)
42504e8ffdaSSuraj Jitindar Singh					 or blocks - (blocks)
42604e8ffdaSSuraj Jitindar SinghSizes and addresses specified in blocks must be converted to bytes by
42704e8ffdaSSuraj Jitindar Singhmultiplying by the block size.
42804e8ffdaSSuraj Jitindar Singh```
42904e8ffdaSSuraj Jitindar SinghCommand:
43004e8ffdaSSuraj Jitindar Singh	RESET_STATE
4316577ef34SSuraj Jitindar Singh	Added in:	V1
43204e8ffdaSSuraj Jitindar Singh	Arguments:
43304e8ffdaSSuraj Jitindar Singh		-
43404e8ffdaSSuraj Jitindar Singh	Response:
43504e8ffdaSSuraj Jitindar Singh		-
43604e8ffdaSSuraj Jitindar Singh	Notes:
43704e8ffdaSSuraj Jitindar Singh		This command is designed to inform the BMC that it should put
43804e8ffdaSSuraj Jitindar Singh		host LPC mapping back in a state where the SBE will be able to
4394bcf02bfSGunnar Mills		use it. Currently, this means pointing back to BMC flash
4404bcf02bfSGunnar Mills		pre mailbox protocol. Final behavior is still TBD.
44104e8ffdaSSuraj Jitindar Singh
44204e8ffdaSSuraj Jitindar SinghCommand:
44304e8ffdaSSuraj Jitindar Singh	GET_MBOX_INFO
4446577ef34SSuraj Jitindar Singh	Added in:	V1
44504e8ffdaSSuraj Jitindar Singh	Arguments:
44604e8ffdaSSuraj Jitindar Singh		V1:
44704e8ffdaSSuraj Jitindar Singh		Args 0: API version
44804e8ffdaSSuraj Jitindar Singh
44904e8ffdaSSuraj Jitindar Singh		V2:
45004e8ffdaSSuraj Jitindar Singh		Args 0: API version
45104e8ffdaSSuraj Jitindar Singh
4526577ef34SSuraj Jitindar Singh		V3:
4536577ef34SSuraj Jitindar Singh		Args 0: API version
4546577ef34SSuraj Jitindar Singh		Args 1: Requested block size (shift)
4556577ef34SSuraj Jitindar Singh
45604e8ffdaSSuraj Jitindar Singh	Response:
45704e8ffdaSSuraj Jitindar Singh		V1:
45804e8ffdaSSuraj Jitindar Singh		Args 0: API version
45904e8ffdaSSuraj Jitindar Singh		Args 1-2: default read window size (blocks)
46004e8ffdaSSuraj Jitindar Singh		Args 3-4: default write window size (blocks)
46104e8ffdaSSuraj Jitindar Singh
46204e8ffdaSSuraj Jitindar Singh		V2:
46304e8ffdaSSuraj Jitindar Singh		Args 0: API version
46404e8ffdaSSuraj Jitindar Singh		Args 1-2: reserved
46504e8ffdaSSuraj Jitindar Singh		Args 3-4: reserved
46604e8ffdaSSuraj Jitindar Singh		Args 5: Block size as power of two (encoded as a shift)
4676479ed40SSuraj Jitindar Singh		Args 6-7: Suggested Timeout (seconds)
4686577ef34SSuraj Jitindar Singh
4696577ef34SSuraj Jitindar Singh		V3:
4706577ef34SSuraj Jitindar Singh		Args 0: API version
4716577ef34SSuraj Jitindar Singh		Args 1-2: reserved
4726577ef34SSuraj Jitindar Singh		Args 3-4: reserved
4736577ef34SSuraj Jitindar Singh		Args 5: Block size as power of two (encoded as a shift)
4746577ef34SSuraj Jitindar Singh		Args 6-7: Suggested Timeout (seconds)
4756577ef34SSuraj Jitindar Singh		Args 8: Num Allocated Flash IDs
4766479ed40SSuraj Jitindar Singh	Notes:
4776479ed40SSuraj Jitindar Singh		The suggested timeout is a hint to the host as to how long
4786479ed40SSuraj Jitindar Singh		it should wait after issuing a command to the BMC before it
4796479ed40SSuraj Jitindar Singh		times out waiting for a response. This is the maximum time
4806479ed40SSuraj Jitindar Singh		which the BMC thinks it could take to service any command which
4816479ed40SSuraj Jitindar Singh		the host could issue. This may be set to zero to indicate that
4826479ed40SSuraj Jitindar Singh		the BMC	does not wish to provide a hint in which case the host
4836479ed40SSuraj Jitindar Singh		must choose some reasonable value.
48404e8ffdaSSuraj Jitindar Singh
4856577ef34SSuraj Jitindar Singh		The host may desire a specific block size and thus can request
4866577ef34SSuraj Jitindar Singh		this by giving a hint to the daemon (may be zero). The daemon
4876577ef34SSuraj Jitindar Singh		may use this to select the block size which it will use however
4886577ef34SSuraj Jitindar Singh		is free to ignore it. The value in the response is the block
4896577ef34SSuraj Jitindar Singh		size which must be used for all further requests until a new
4906577ef34SSuraj Jitindar Singh		size is	negotiated by another call to GET_MBOX_INFO. (V3)
4916577ef34SSuraj Jitindar Singh
49204e8ffdaSSuraj Jitindar SinghCommand:
49304e8ffdaSSuraj Jitindar Singh	GET_FLASH_INFO
4946577ef34SSuraj Jitindar Singh	Added in:	V1
49504e8ffdaSSuraj Jitindar Singh	Arguments:
4966577ef34SSuraj Jitindar Singh		V1, V2:
49704e8ffdaSSuraj Jitindar Singh		-
4986577ef34SSuraj Jitindar Singh
4996577ef34SSuraj Jitindar Singh		V3:
5006577ef34SSuraj Jitindar Singh		Args 0: Flash ID
50104e8ffdaSSuraj Jitindar Singh	Response:
50204e8ffdaSSuraj Jitindar Singh		V1:
50304e8ffdaSSuraj Jitindar Singh		Args 0-3: Flash size (bytes)
50404e8ffdaSSuraj Jitindar Singh		Args 4-7: Erase granule (bytes)
50504e8ffdaSSuraj Jitindar Singh
5066577ef34SSuraj Jitindar Singh		V2, V3:
50704e8ffdaSSuraj Jitindar Singh		Args 0-1: Flash size (blocks)
50804e8ffdaSSuraj Jitindar Singh		Args 2-3: Erase granule (blocks)
50904e8ffdaSSuraj Jitindar Singh
51004e8ffdaSSuraj Jitindar SinghCommand:
51104e8ffdaSSuraj Jitindar Singh	CREATE_{READ/WRITE}_WINDOW
5126577ef34SSuraj Jitindar Singh	Added in:	V1
51304e8ffdaSSuraj Jitindar Singh	Arguments:
51404e8ffdaSSuraj Jitindar Singh		V1:
515faeb88c0SSuraj Jitindar Singh		Args 0-1: Requested flash offset (blocks)
51604e8ffdaSSuraj Jitindar Singh
51704e8ffdaSSuraj Jitindar Singh		V2:
518faeb88c0SSuraj Jitindar Singh		Args 0-1: Requested flash offset (blocks)
519faeb88c0SSuraj Jitindar Singh		Args 2-3: Requested flash size to access (blocks)
52004e8ffdaSSuraj Jitindar Singh
5216577ef34SSuraj Jitindar Singh		V3:
5226577ef34SSuraj Jitindar Singh		Args 0-1: Requested flash offset (blocks)
5236577ef34SSuraj Jitindar Singh		Args 2-3: Requested flash size to access (blocks)
5246577ef34SSuraj Jitindar Singh		Args 4: Flash ID
52504e8ffdaSSuraj Jitindar Singh	Response:
52604e8ffdaSSuraj Jitindar Singh		V1:
52704e8ffdaSSuraj Jitindar Singh		Args 0-1: LPC bus address of window (blocks)
52804e8ffdaSSuraj Jitindar Singh
5296577ef34SSuraj Jitindar Singh		V2, V3:
53004e8ffdaSSuraj Jitindar Singh		Args 0-1: LPC bus address of window (blocks)
531faeb88c0SSuraj Jitindar Singh		Args 2-3: Window size (blocks)
532faeb88c0SSuraj Jitindar Singh		Args 4-5: Flash offset mapped by window (blocks)
53304e8ffdaSSuraj Jitindar Singh	Notes:
534faeb88c0SSuraj Jitindar Singh		The flash offset which the host requests access to is always
53504e8ffdaSSuraj Jitindar Singh		taken from the start of flash - that is it is an absolute
536faeb88c0SSuraj Jitindar Singh		offset into flash.
53704e8ffdaSSuraj Jitindar Singh
53804e8ffdaSSuraj Jitindar Singh		LPC bus address is always given from the start of the LPC
53904e8ffdaSSuraj Jitindar Singh		address space - that is it is an absolute address.
54004e8ffdaSSuraj Jitindar Singh
541faeb88c0SSuraj Jitindar Singh		The requested access size is only a hint. The response
54204e8ffdaSSuraj Jitindar Singh		indicates the actual size of the window. The BMC may
54304e8ffdaSSuraj Jitindar Singh		want to use the requested size to pre-load the remainder
54404e8ffdaSSuraj Jitindar Singh		of the request. The host must not access past the end of the
54504e8ffdaSSuraj Jitindar Singh		active window.
54604e8ffdaSSuraj Jitindar Singh
547faeb88c0SSuraj Jitindar Singh		The flash offset mapped by the window is an absolute flash
548faeb88c0SSuraj Jitindar Singh		offset and must be less than or equal to the flash offset
549faeb88c0SSuraj Jitindar Singh		requested by the host. It is the responsibility of the host
550faeb88c0SSuraj Jitindar Singh		to use this information to access any offset which is required.
55104e8ffdaSSuraj Jitindar Singh
55204e8ffdaSSuraj Jitindar Singh		The requested window size may be zero. In this case the
55304e8ffdaSSuraj Jitindar Singh		BMC is free to create any sized window but it must contain
55404e8ffdaSSuraj Jitindar Singh		atleast the first block of data requested by the host. A large
55504e8ffdaSSuraj Jitindar Singh		window is of course preferred and should correspond to
55604e8ffdaSSuraj Jitindar Singh		the default size returned in the GET_MBOX_INFO command.
55704e8ffdaSSuraj Jitindar Singh
558faeb88c0SSuraj Jitindar Singh		If this command returns successfully then the created window
559faeb88c0SSuraj Jitindar Singh		is the active window. If it fails then there is no active
560faeb88c0SSuraj Jitindar Singh		window.
56104e8ffdaSSuraj Jitindar Singh
56204e8ffdaSSuraj Jitindar SinghCommand:
56304e8ffdaSSuraj Jitindar Singh	CLOSE_WINDOW
5646577ef34SSuraj Jitindar Singh	Added in:	V1
56504e8ffdaSSuraj Jitindar Singh	Arguments:
56604e8ffdaSSuraj Jitindar Singh		V1:
56704e8ffdaSSuraj Jitindar Singh		-
56804e8ffdaSSuraj Jitindar Singh
56904e8ffdaSSuraj Jitindar Singh		V2:
57004e8ffdaSSuraj Jitindar Singh		Args 0: Flags
57104e8ffdaSSuraj Jitindar Singh	Response:
57204e8ffdaSSuraj Jitindar Singh		-
57304e8ffdaSSuraj Jitindar Singh	Notes:
57404e8ffdaSSuraj Jitindar Singh		Closes the active window. Any further access to the LPC bus
57504e8ffdaSSuraj Jitindar Singh		address specified to address the previously active window will
57604e8ffdaSSuraj Jitindar Singh		have undefined effects. If the active window is a
57704e8ffdaSSuraj Jitindar Singh		write window then the BMC must perform an implicit flush.
57804e8ffdaSSuraj Jitindar Singh
57904e8ffdaSSuraj Jitindar Singh		The Flags argument allows the host to provide some
58004e8ffdaSSuraj Jitindar Singh		hints to the BMC. Defined Values:
58104e8ffdaSSuraj Jitindar Singh			0x01 - Short Lifetime:
58204e8ffdaSSuraj Jitindar Singh				The window is unlikely to be accessed
58304e8ffdaSSuraj Jitindar Singh				anytime again in the near future. The effect of
58404e8ffdaSSuraj Jitindar Singh				this will depend on BMC implementation. In
58504e8ffdaSSuraj Jitindar Singh				the event that the BMC performs some caching
58604e8ffdaSSuraj Jitindar Singh				the BMC daemon could mark data contained in a
58704e8ffdaSSuraj Jitindar Singh				window closed with this flag as first to be
58804e8ffdaSSuraj Jitindar Singh				evicted from the cache.
58904e8ffdaSSuraj Jitindar Singh
59004e8ffdaSSuraj Jitindar SinghCommand:
59104e8ffdaSSuraj Jitindar Singh	MARK_WRITE_DIRTY
5926577ef34SSuraj Jitindar Singh	Added in:	V1
59304e8ffdaSSuraj Jitindar Singh	Arguments:
59404e8ffdaSSuraj Jitindar Singh		V1:
59504e8ffdaSSuraj Jitindar Singh		Args 0-1: Flash offset to mark from base of flash (blocks)
59604e8ffdaSSuraj Jitindar Singh		Args 2-5: Number to mark dirty at offset (bytes)
59704e8ffdaSSuraj Jitindar Singh
59804e8ffdaSSuraj Jitindar Singh		V2:
59904e8ffdaSSuraj Jitindar Singh		Args 0-1: Window offset to mark (blocks)
60004e8ffdaSSuraj Jitindar Singh		Args 2-3: Number to mark dirty at offset (blocks)
6016577ef34SSuraj Jitindar Singh		Args 4  : Don't Erase Before Write (V3)
60204e8ffdaSSuraj Jitindar Singh
60304e8ffdaSSuraj Jitindar Singh	Response:
60404e8ffdaSSuraj Jitindar Singh		-
60504e8ffdaSSuraj Jitindar Singh	Notes:
60604e8ffdaSSuraj Jitindar Singh		The BMC has no method for intercepting writes that
60704e8ffdaSSuraj Jitindar Singh		occur over the LPC bus. The host must explicitly notify
6084bcf02bfSGunnar Mills		the daemon of where and when a write has occurred so it
60904e8ffdaSSuraj Jitindar Singh		can be flushed to backing storage.
61004e8ffdaSSuraj Jitindar Singh
61104e8ffdaSSuraj Jitindar Singh		Offsets are given as an absolute (either into flash (V1) or the
61204e8ffdaSSuraj Jitindar Singh		active window (V2)) and a zero offset refers to the first
61304e8ffdaSSuraj Jitindar Singh		block. If the offset + number exceeds the size of the active
61404e8ffdaSSuraj Jitindar Singh		window then the command must not succeed.
61504e8ffdaSSuraj Jitindar Singh
6166577ef34SSuraj Jitindar Singh		The host can give a hint to the daemon that is doesn't have to
6176577ef34SSuraj Jitindar Singh		erase a flash area before writing to it by setting ARG[4]. This
6186577ef34SSuraj Jitindar Singh		means that the daemon will blindly perform a write to that area
6196577ef34SSuraj Jitindar Singh		and will not try to erase it before hand. This can be used if
6206577ef34SSuraj Jitindar Singh		the host knows that a large area has already been erased for
6216577ef34SSuraj Jitindar Singh		example but then wants to perform many small writes.
6226577ef34SSuraj Jitindar Singh
62304e8ffdaSSuraj Jitindar SinghCommand
62404e8ffdaSSuraj Jitindar Singh	WRITE_FLUSH
6256577ef34SSuraj Jitindar Singh	Added in:	V1
62604e8ffdaSSuraj Jitindar Singh	Arguments:
62704e8ffdaSSuraj Jitindar Singh		V1:
62804e8ffdaSSuraj Jitindar Singh		Args 0-1: Flash offset to mark from base of flash (blocks)
62904e8ffdaSSuraj Jitindar Singh		Args 2-5: Number to mark dirty at offset (bytes)
63004e8ffdaSSuraj Jitindar Singh
63104e8ffdaSSuraj Jitindar Singh		V2:
63204e8ffdaSSuraj Jitindar Singh		-
63304e8ffdaSSuraj Jitindar Singh
63404e8ffdaSSuraj Jitindar Singh	Response:
63504e8ffdaSSuraj Jitindar Singh		-
63604e8ffdaSSuraj Jitindar Singh	Notes:
63704e8ffdaSSuraj Jitindar Singh		Flushes any dirty/erased blocks in the active window to
63804e8ffdaSSuraj Jitindar Singh		the backing storage.
63904e8ffdaSSuraj Jitindar Singh
64004e8ffdaSSuraj Jitindar Singh		In V1 this can also be used to mark parts of the flash
64104e8ffdaSSuraj Jitindar Singh		dirty and flush in a single command. In V2 the explicit
64204e8ffdaSSuraj Jitindar Singh		mark dirty command must be used before a call to flush
64304e8ffdaSSuraj Jitindar Singh		since there are no longer any arguments. If the offset + number
64404e8ffdaSSuraj Jitindar Singh		exceeds the size of the active window then the command must not
64504e8ffdaSSuraj Jitindar Singh		succeed.
64604e8ffdaSSuraj Jitindar Singh
64704e8ffdaSSuraj Jitindar Singh
64804e8ffdaSSuraj Jitindar SinghCommand:
64904e8ffdaSSuraj Jitindar Singh	BMC_EVENT_ACK
6506577ef34SSuraj Jitindar Singh	Added in:	V1
65104e8ffdaSSuraj Jitindar Singh	Arguments:
65204e8ffdaSSuraj Jitindar Singh		Args 0:	Bits in the BMC status byte (mailbox data
65304e8ffdaSSuraj Jitindar Singh			register 15) to ack
65404e8ffdaSSuraj Jitindar Singh	Response:
65504e8ffdaSSuraj Jitindar Singh		*clears the bits in mailbox data register 15*
65604e8ffdaSSuraj Jitindar Singh	Notes:
65704e8ffdaSSuraj Jitindar Singh		The host should use this command to acknowledge BMC events
65804e8ffdaSSuraj Jitindar Singh		supplied in mailbox register 15.
65904e8ffdaSSuraj Jitindar Singh
66004e8ffdaSSuraj Jitindar SinghCommand:
66104e8ffdaSSuraj Jitindar Singh	MARK_WRITE_ERASED
6626577ef34SSuraj Jitindar Singh	Added in:	V2
66304e8ffdaSSuraj Jitindar Singh	Arguments:
66404e8ffdaSSuraj Jitindar Singh		V2:
66504e8ffdaSSuraj Jitindar Singh		Args 0-1: Window offset to erase (blocks)
66604e8ffdaSSuraj Jitindar Singh		Args 2-3: Number to erase at offset (blocks)
66704e8ffdaSSuraj Jitindar Singh	Response:
66804e8ffdaSSuraj Jitindar Singh		-
66904e8ffdaSSuraj Jitindar Singh	Notes:
67004e8ffdaSSuraj Jitindar Singh		This command allows the host to erase a large area
67104e8ffdaSSuraj Jitindar Singh		without the need to individually write 0xFF
67204e8ffdaSSuraj Jitindar Singh		repetitively.
67304e8ffdaSSuraj Jitindar Singh
67404e8ffdaSSuraj Jitindar Singh		Offset is the offset within the active window to start erasing
67504e8ffdaSSuraj Jitindar Singh		from (zero refers to the first block of the active window) and
67604e8ffdaSSuraj Jitindar Singh		number is the number of blocks of the active window to erase
67704e8ffdaSSuraj Jitindar Singh		starting at offset. If the offset + number exceeds the size of
67804e8ffdaSSuraj Jitindar Singh		the active window then the command must not succeed.
6796577ef34SSuraj Jitindar Singh
6806577ef34SSuraj Jitindar SinghCommand:
6816577ef34SSuraj Jitindar Singh	GET_FLASH_NAME
6826577ef34SSuraj Jitindar Singh	Added in:	V3
6836577ef34SSuraj Jitindar Singh	Arguments:
6846577ef34SSuraj Jitindar Singh		Args 0: Flash ID
6856577ef34SSuraj Jitindar Singh	Response:
6866577ef34SSuraj Jitindar Singh		Args 0   : Flash Name Length (bytes)
6876577ef34SSuraj Jitindar Singh		Args 1-10: Flash Name / UID
6886577ef34SSuraj Jitindar Singh	Notes:
6896577ef34SSuraj Jitindar Singh		Describes a flash with some kind of identifier useful to the
6906577ef34SSuraj Jitindar Singh		host system. This is typically a null-padded string.
6916577ef34SSuraj Jitindar Singh
6926577ef34SSuraj Jitindar Singh		The length in the response is the number of response arguments
6936577ef34SSuraj Jitindar Singh		as part of the flash name field which the host should expect to
6946577ef34SSuraj Jitindar Singh		have been populated.
6956577ef34SSuraj Jitindar Singh
6966577ef34SSuraj Jitindar SinghCommand:
6976577ef34SSuraj Jitindar Singh	MARK_LOCKED
6986577ef34SSuraj Jitindar Singh	Added in:	V3
6996577ef34SSuraj Jitindar Singh	Arguments:
7006577ef34SSuraj Jitindar Singh		Args 0-1: Flash offset to lock (blocks)
7016577ef34SSuraj Jitindar Singh		Args 2-3: Number to lock at offset (blocks)
7026577ef34SSuraj Jitindar Singh		Args 4: Flash ID
7036577ef34SSuraj Jitindar Singh	Response:
7046577ef34SSuraj Jitindar Singh		-
7056577ef34SSuraj Jitindar Singh	Notes:
7066577ef34SSuraj Jitindar Singh		Lock an area of flash so that the host can't mark it dirty or
7076577ef34SSuraj Jitindar Singh		erased. If the requested area is within the current window and
7086577ef34SSuraj Jitindar Singh		that area is currently marked dirty or erased then this command
7096577ef34SSuraj Jitindar Singh		must fail with PARAM_ERROR.
7106577ef34SSuraj Jitindar Singh
71104e8ffdaSSuraj Jitindar Singh```
71204e8ffdaSSuraj Jitindar Singh
71304e8ffdaSSuraj Jitindar Singh### BMC Events in Detail:
71404e8ffdaSSuraj Jitindar Singh
71504e8ffdaSSuraj Jitindar SinghIf the BMC needs to tell the host something then it simply
71604e8ffdaSSuraj Jitindar Singhwrites to Byte 15. The host should have interrupts enabled
71704e8ffdaSSuraj Jitindar Singhon that register, or otherwise be polling it.
71804e8ffdaSSuraj Jitindar Singh
71904e8ffdaSSuraj Jitindar Singh#### Bit Definitions:
72004e8ffdaSSuraj Jitindar Singh
7216577ef34SSuraj Jitindar SinghEvents which must be ACKed:
72204e8ffdaSSuraj Jitindar Singh```
72304e8ffdaSSuraj Jitindar Singh0x01: BMC Reboot
72404e8ffdaSSuraj Jitindar Singh0x02: BMC Windows Reset (V2)
72504e8ffdaSSuraj Jitindar Singh```
72604e8ffdaSSuraj Jitindar Singh
72704e8ffdaSSuraj Jitindar SinghEvents which cannot be ACKed (BMC will clear when no longer
72804e8ffdaSSuraj Jitindar Singhapplicable):
72904e8ffdaSSuraj Jitindar Singh```
73004e8ffdaSSuraj Jitindar Singh0x40: BMC Flash Control Lost (V2)
73104e8ffdaSSuraj Jitindar Singh0x80: BMC MBOX Daemon Ready (V2)
73204e8ffdaSSuraj Jitindar Singh```
73304e8ffdaSSuraj Jitindar Singh
73404e8ffdaSSuraj Jitindar Singh#### Event Description:
73504e8ffdaSSuraj Jitindar Singh
73604e8ffdaSSuraj Jitindar SinghEvents which must be ACKed:
73704e8ffdaSSuraj Jitindar SinghThe host should acknowledge these events with BMC_EVENT_ACK to
73804e8ffdaSSuraj Jitindar Singhlet the BMC know that they have been received and understood.
73904e8ffdaSSuraj Jitindar Singh```
74004e8ffdaSSuraj Jitindar Singh0x01 - BMC Reboot:
7414bcf02bfSGunnar Mills	Used to inform the host that a BMC reboot has occurred.
7424bcf02bfSGunnar Mills	The host must perform protocol version negotiation again and
74304e8ffdaSSuraj Jitindar Singh	must assume it has no active window. The host must not assume
74404e8ffdaSSuraj Jitindar Singh	that any commands which didn't respond as such succeeded.
74504e8ffdaSSuraj Jitindar Singh0x02 - BMC Windows Reset: (V2)
74604e8ffdaSSuraj Jitindar Singh	The host must assume that its active window has been closed and
74704e8ffdaSSuraj Jitindar Singh	that it no longer has an active window. The host is not
74804e8ffdaSSuraj Jitindar Singh	required to perform protocol version negotiation again. The
74904e8ffdaSSuraj Jitindar Singh	host must not assume that any commands which didn't respond as such
75004e8ffdaSSuraj Jitindar Singh	succeeded.
75104e8ffdaSSuraj Jitindar Singh```
75204e8ffdaSSuraj Jitindar Singh
75304e8ffdaSSuraj Jitindar SinghEvents which cannot be ACKed:
75404e8ffdaSSuraj Jitindar SinghThese events cannot be acknowledged by the host and a call to
75504e8ffdaSSuraj Jitindar SinghBMC_EVENT_ACK with these bits set will have no effect. The BMC
75604e8ffdaSSuraj Jitindar Singhwill clear these bits when they are no longer applicable.
75704e8ffdaSSuraj Jitindar Singh```
75804e8ffdaSSuraj Jitindar Singh0x40 - BMC Flash Control Lost: (V2)
75904e8ffdaSSuraj Jitindar Singh	The BMC daemon has been suspended and thus no longer
76004e8ffdaSSuraj Jitindar Singh	controls access to the flash (most likely because some
76104e8ffdaSSuraj Jitindar Singh	other process on the BMC required direct access to the
76204e8ffdaSSuraj Jitindar Singh	flash and has suspended the BMC daemon to preclude
76304e8ffdaSSuraj Jitindar Singh	concurrent access).
76404e8ffdaSSuraj Jitindar Singh	The BMC daemon must clear this bit itself when it regains
76504e8ffdaSSuraj Jitindar Singh	control of the flash (the host isn't able to clear it
76604e8ffdaSSuraj Jitindar Singh	through an acknowledge command).
76704e8ffdaSSuraj Jitindar Singh	The host must not assume that the contents of the active window
76804e8ffdaSSuraj Jitindar Singh	correctly reflect the contents of flash while this bit is set.
76904e8ffdaSSuraj Jitindar Singh0x80 - BMC MBOX Daemon Ready: (V2)
77004e8ffdaSSuraj Jitindar Singh	Used to inform the host that the BMC daemon is ready to
77104e8ffdaSSuraj Jitindar Singh	accept command requests. The host isn't able to clear
77204e8ffdaSSuraj Jitindar Singh	this bit through an acknowledge command, the BMC daemon must
77304e8ffdaSSuraj Jitindar Singh	clear it before it terminates (assuming it didn't
77404e8ffdaSSuraj Jitindar Singh	terminate unexpectedly).
77504e8ffdaSSuraj Jitindar Singh	The host should not expect a response while this bit is
77604e8ffdaSSuraj Jitindar Singh	not set.
77704e8ffdaSSuraj Jitindar Singh	Note that this bit being set is not a guarantee that the BMC daemon
77804e8ffdaSSuraj Jitindar Singh	will respond as it or the BMC may have crashed without clearing
77904e8ffdaSSuraj Jitindar Singh	it.
78004e8ffdaSSuraj Jitindar Singh```
781