qe: add ability to upload QE firmware
Subsystems (2)
PATCH v2 1/1 qe: add ability to upload QE firmware
Define the layout of a binary blob that contains a QE firmware and instructions on how to upload it. Add function qe_upload_firmware() to parse the blob and perform the actual upload. Fully define 'struct rsp' in immap_qe.h to include the actual RISC Special Registers.
---
Updated to add information on a new 'firmware' child node to the QE node, and added code to parse that node. This allows U-Boot to upload a firmware and pass the data to the kernel.
This patch is for Kumar's for-2.6.25 branch. This code is necessary for my QE UART driver.
Documentation/powerpc/00-INDEX | 3 + Documentation/powerpc/qe_firmware.txt | 295 +++++++++++++++++++++++++++++++++ arch/powerpc/platforms/Kconfig | 1 + arch/powerpc/sysdev/qe_lib/qe.c | 240 +++++++++++++++++++++++++++ include/asm-powerpc/immap_qe.h | 34 ++++- include/asm-powerpc/qe.h | 61 +++++++ 6 files changed, 632 insertions(+), 2 deletions(-) create mode 100644 Documentation/powerpc/qe_firmware.txt
Documentation/powerpc/00-INDEX +3 -0
@@ -28,3 +28,6 @@ sound.txt - info on sound support under Linux/PPC zImage_layout.txt - info on the kernel images for Linux/PPC +qe_firmware.txt + - describes the layout of firmware binaries for the Freescale QUICC + Engine and the code that parses and uploads the microcode therein.
Documentation/powerpc/qe_firmware.txt new file +295 -0
295 lines not on this page · raw message
arch/powerpc/platforms/Kconfig +1 -0
@@ -265,6 +265,7 @@ config TAU_AVERAGE config QUICC_ENGINE bool select PPC_LIB_RHEAP + select CRC32 help The QUICC Engine (QE) is a new generation of communications coprocessors on Freescale embedded CPUs (akin to CPM in older chips).
arch/powerpc/sysdev/qe_lib/qe.c +240 -0
249 lines not on this page · raw message
include/asm-powerpc/immap_qe.h +32 -2
@@ -393,9 +393,39 @@ struct dbg {u8 res2[0x48 ]; } __attribute__ ((packed)); -/* RISC Special Registers (Trap and Breakpoint) */ +/* +* RISC Special Registers (Trap and Breakpoint). These are described in +* the QE Developer's Handbook. +*/ struct rsp { -u32 reg[0x40 ];/* 64 32-bit registers */ +__be32 tibcr[16 ];/* Trap/instruction breakpoint control regs */ +u8 res0[64 ]; +__be32 ibcr0; +__be32 ibs0; +__be32 ibcnr0; +u8 res1[4 ]; +__be32 ibcr1; +__be32 ibs1; +__be32 ibcnr1; +__be32 npcr; +__be32 dbcr; +__be32 dbar; +__be32 dbamr; +__be32 dbsr; +__be32 dbcnr; +u8 res2[12 ]; +__be32 dbdr_h; +__be32 dbdr_l; +__be32 dbdmr_h; +__be32 dbdmr_l; +__be32 bsr; +__be32 bor; +__be32 bior; +u8 res3[4 ]; +__be32 iatr[4 ]; +__be32 eccr;/* Exception control configuration register */ +__be32 eicr; +u8 res4[0x100 -0xf8 ]; } __attribute__ ((packed));struct qe_immap {
include/asm-powerpc/qe.h +61 -0
73 lines not on this page · raw message
Signature · 1 line
1.5.2.4
Quoted 1 line · Timur Tabi
Define the layout of a binary blob that contains a QE firmware and instru=
ctions
Quoted 1 line
on how to upload it. =A0Add function
qe_upload_firmware()to parse the bl=
ob
Quoted 1 line
and perform the actual upload. =A0Fully define 'struct rsp' in immap_qe.h=
to
Quoted 3 lines
include the actual RISC Special Registers.
=20Signed-off-by Timur Tabi <[email protected]>
The code looks entirely fine to me, but after looking at it, it occurred to me that you may want to think about having support for autoloading the firmware based on a property in the device tree. For the spidernet driver on the Cell blade, we first also did an implementation that called request_firmware to load the microcode into the spider chip, but we later added a property (24kb long in our case) that simply contained the whole blob in the the device tree.
This made it _much_ easier to support things like NFS root and distribution installers and avoided all licensing problems because the blob can now be shipped with the board instead of as part of the GPL software.
Of course, that approach does not help you if the blob is not GPL compatible and you are relying on the dts file to be linked into the kernel, but it may be good if your driver supports it anyway so you can pass it down from the system boot loader to the kernel. In your driver, it's just a few lines of extra code and you can of course still leave the request_firmware call in place for other scenarios.
Arnd <><
Quoted 2 lines · Arnd Bergmann
Of course, that approach does not help you if the blob is not GPL compatible and you are relying on the dts file to be linked into the kernel,
Well, the blobs will never be GPL compatible, which is why I created the firmware binary format. Previously, the firmware was shipped as header files with code like this:
#define MPC8323_R1_0_UC_PATCH \
{ \
0xb3ff0006 \
, 0xffffffff \
, 0xb3ff0009 \
, 0xffffffff \
, 0xb3ff000c \
, 0xffffffff \and so on.
To address the issue of loading the firmware before the kernel boots, I have ported qe_upload_firmware() to U-Boot, and provided a command-line command for uploading a firmware at an address in flash. The blob can be placed in flash, and then a boot script will load it. The U-Boot version of qe_upload_firmware() will also create the 'firmware' node in the device tree.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 3 lines · Timur Tabi
Arnd Bergmann wrote:
=20Quoted 1 line
Of course, that approach does not help you if the blob is not GPL compa=
tible
Quoted 3 lines
Quoted 1 line
and you are relying on the dts file to be linked into the kernel,=20
=20
Well, the blobs will never be GPL compatible, which is why I created the=
=20
Quoted 1 line
firmware binary format.
Well, you never know if someone might be willing to reverse-engineer them and provide free replacements ;-). But that wasn't my point.
Quoted 1 line
To address the issue of loading the firmware before the kernel boots, I h=
ave=20
Quoted 1 line
ported
qe_upload_firmware()to U-Boot, and provided a command-line comman=
d for=20
Quoted 1 line
uploading a firmware at an address in flash. =A0The blob can be placed in=
flash,=20
Quoted 1 line
and then a boot script will load it. =A0The U-Boot version of qe_upload_f=
irmware()=20
Quoted 1 line
will also create the 'firmware' node in the device tree.
What does the firmware node contain then? The way I read it, you only put metadata about the uploaded firmware in there, but not the blob itself, rig= ht?
Is there a case where you don't need the firmware in order to start the kernel, but still want to provide it in flash? In that case, I think it would really be better to just put the blob into the tree and only have the fw loading code in the kernel instead of duplicating it in the boot loader.
Regarding the question whether the firmware should be a device node or a property of another node, I'd prefer a simple property, because the firmware itself is not really a device you can access, but I don't care much about that.
Arnd <><
Quoted 2 lines · Arnd Bergmann
What does the firmware node contain then? The way I read it, you only put metadata about the uploaded firmware in there, but not the blob itself, right?
That's correct. The meta-data is only the information that a device driver would need to identify and interact with the microcode.
Quoted 2 lines
Is there a case where you don't need the firmware in order to start the kernel, but still want to provide it in flash?
I don't think you'll ever need the firmware to *start* the kernel.
Quoted 4 lines
In that case, I think it
would really be better to just put the blob into the tree and only have the fw loading code in the kernel instead of duplicating it in the boot loader.
That would require the firmware to present in RAM for all time, since the device tree cannot be unloaded. Besides, you might need to have the firmware loaded in U-Boot anyway. If your console is connected to the QE, then you'll need the UART firmware loaded before you can see anything. That's why U-Boot needs its own version.
Quoted 4 lines
Regarding the question whether the firmware should be a device node or a property of another node, I'd prefer a simple property, because the firmware itself is not really a device you can access, but I don't care much about that.
Technically, the firmware could be considered a device on the QE, because it's loaded into I-RAM and it can significantly alter the behavior of the device. Having it its own node also lets me compartmentalize it. If I want to expand the node and add more properties, it's cleaner.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 3 lines · Timur Tabi
Quoted 3 lines
In that case, I think it
would really be better to just put the blob into the tree and only have the fw loading code in the kernel instead of duplicating it in the=
boot
Quoted 3 lines
Quoted 1 line
loader.
=20
That would require the firmware to present in RAM for all time, since the=
device=20
Quoted 1 line
tree cannot be unloaded.
Yes, that's a backdraw of my approach, but in the case of spidernet, it was=
only
an insignificant amount of RAM. Don't know what sizes of RAM and QE firmware to expect typically on the machines you care about.
Quoted 2 lines
Besides, you might need to have the firmware loaded in =20 U-Boot anyway. =A0If your console is connected to the QE, then you'll nee=
d the=20
Quoted 1 line
UART firmware loaded before you can see anything. =A0That's why U-Boot ne=
eds its=20
Quoted 1 line
own version.
Right, so you can't really get around having it in some boot loaders at lea= st.
IIRC you said that the firmware is only needed for serial output on some ch= ips
but not on others. What about the case where you don't need it for serial b= ut
still want to provide it by the firmware, and perhaps use something other t= han
U-boot? Is that relevant?
I'm not trying to convince you of this if it's completely pointless for all your systems, just want to make sure you're aware of this option, because spending a few extra code lines on it now may save you some trouble if you need this later.
Quoted 6 lines
Quoted 4 lines
Regarding the question whether the firmware should be a device node or a property of another node, I'd prefer a simple property, because the firmware itself is not really a device you can access, but I don't care much about that.
=20
Technically, the firmware could be considered a device on the QE, because=
it's=20
Quoted 1 line
loaded into I-RAM and it can significantly alter the behavior of the devi=
ce.=20
Well, it doesn't have any of the standard properties like registers or inte= rrupts
though.
Quoted 1 line
Having it its own node also lets me compartmentalize it. =A0If I want to =
expand=20
Quoted 1 line
the node and add more properties, it's cleaner.
Yes, that makes a lot of sense.
Arnd <><
Quoted 10 lines · Arnd Bergmann
Quoted 5 lines · Timur Tabi
Quoted 4 lines
In that case, I think it
would really be better to just put the blob into the tree and only have the fw loading code in the kernel instead of duplicating it in the boot loader.That would require the firmware to present in RAM for all time, since the device tree cannot be unloaded.
Yes, that's a backdraw of my approach, but in the case of spidernet, it was only an insignificant amount of RAM. Don't know what sizes of RAM and QE firmware to expect typically on the machines you care about.
I'm only familiar with the UART microcode, which is relatively small. I'll add this feature to my to-do list.
Quoted 5 lines
Right, so you can't really get around having it in some boot loaders at least. IIRC you said that the firmware is only needed for serial output on some chips but not on others. What about the case where you don't need it for serial but still want to provide it by the firmware, and perhaps use something other than U-boot? Is that relevant?
In this particular case, the UART firmware is needed on some chips only because those chips are broken in silicon. AFAIK, only 8323 and 8360 are affected. None of the 85xx chips with QE have the broken UART silicon, so they don't need this firmware.
The whole point behind having binary firmware blobs is so that *any* OS, boot-loader, or even an application can upload firmware without worrying about licensing issues. The code to parse and process the blobs is open source.
There are other firmwares, such as firmware for TCP/IP interworking. Unfortunately, I don't have any direct experience with those firmwares, but in discussions with QE engineers who have, my approach works. My hope is that every OS that runs on our QE-enabled parts will contain a version of qe_upload_firmware().
Quoted 4 lines
I'm not trying to convince you of this if it's completely pointless for all your systems, just want to make sure you're aware of this option, because spending a few extra code lines on it now may save you some trouble if you need this later.
Um, I think I'm a little confused as to what your point is. My code is just a generic QE firmware uploader.
Quoted 4 lines
Quoted 1 line
Technically, the firmware could be considered a device on the QE, because it's loaded into I-RAM and it can significantly alter the behavior of the device.
Well, it doesn't have any of the standard properties like registers or interrupts though.
Well, there are registers for accessing I-RAM. It's not memory mapped - you have to write the I-RAM internal address to one register, and then write the data to another register, in order to actually write to I-RAM.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 3 lines · Timur Tabi
Quoted 3 lines
I'm not trying to convince you of this if it's completely pointless for all your systems, just want to make sure you're aware of this option, because spending a few extra code lines on it now may save you some tro=
uble
Quoted 3 lines
Quoted 1 line
if you need this later.
=20
Um, I think I'm a little confused as to what your point is. =A0My code is=
just a=20
Quoted 1 line
generic QE firmware uploader.
My point is that you could have some extra code that calls your qe_upload_firmware() when the device tree contains the blob but the boot loader did not already load it. This helps e.g. for the case where you want to be able to install a generic Linux distribution that is not able to ship with your firmware blob in the kernel or the root file system. Putting the blob in the device tree makes it easier to get to a running system then.
You can argue that the boot loader can always load the firmware in the first place, but then you wouldn't need an implementation of qe_upload_firmware in the kernel any more.
Arnd <><
Quoted 3 lines · Arnd Bergmann
My point is that you could have some extra code that calls your
qe_upload_firmware()when the device tree contains the blob but the boot loader did not already load it.
The current design of the 'firmware' node is such that if present, that means that the firmware has already been uploaded.
We can't use the device tree to tell the kernel which firmware to upload, because that is determined exclusively by the user's application. The drivers are ultimately responsible for deciding which firmware to use.
Quoted 5 lines
This helps e.g. for the case where you
want to be able to install a generic Linux distribution that is not able to ship with your firmware blob in the kernel or the root file system. Putting the blob in the device tree makes it easier to get to a running system then.
But where would the blob come from? Probably from flash or a TFTP server. In that case, the boot loader can still handle it.
Quoted 3 lines
You can argue that the boot loader can always load the firmware in the first place, but then you wouldn't need an implementation of
qe_upload_firmwarein the kernel any more.
You might want to do runtime swapping of firmwares. One of the drawbacks of the QE microcode design is that you can only have one microcode uploaded at a time.
If you need to have two different microcodes (e.g. Soft-UART and
interworking), then you need to merge the source code for those two into a new microcode and compile that.
You might need to do full reset of the QE, which would require re-uploading.
You might not know until after the kernel boots which firmware you want.
In reality, having the boot loader load the firmware will usually be the preferred approach, because that's simpler. Having it in both U-Boot and the kernel covers all situations, though. There would be no need for the bootloader to pass the firmware to the kernel.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 1 line · Timur Tabi
In reality, having the boot loader load the firmware will usually be the=
=20
Quoted 1 line
preferred approach, because that's simpler. =A0Having it in both U-Boot a=
nd the=20
Quoted 1 line
kernel covers all situations, though. =A0There would be no need for the b=
ootloader=20
Quoted 1 line
to pass the firmware to the kernel.
Ok, looks you were right from the start (again), thanks for your patience explaining this to me.
Arnd <><
Quoted 6 lines · Timur Tabi
Quoted 2 lines · Arnd Bergmann
Ok, looks you were right from the start (again), thanks for your patience explaining this to me.
No problem. No all I need is for Kumar to apply the patches!
When I wait you come up with a new version.. so I'm waiting to see if v3 comes out :)
- k
Quoted 5 lines · Timur Tabi
I think these patches are final:
[PATCH 1/2] qe: add function
qe_clock_source(dated 12/3)
[PATCH 2/2]ucc_geth: use rx-clock-name and tx-clock-name device tree properties (dated 12/3) [PATCH v2] qe: add ability to upload QE firmware
I lied. This last patch is missing a file. v3 is coming soon. Sorry.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 2 lines · Arnd Bergmann
Ok, looks you were right from the start (again), thanks for your patience explaining this to me.
No problem. No all I need is for Kumar to apply the patches!
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 1 line · Kumar Gala
When I wait you come up with a new version.. so I'm waiting to see if v3 comes out :)
Well, I guess I can't blame you for that. :-)
I think these patches are final:
[PATCH 1/2] qe: add function qe_clock_source (dated 12/3)
[PATCH 2/2] ucc_geth: use rx-clock-name and tx-clock-name device tree properties (dated 12/3) [PATCH v2] qe: add ability to upload QE firmware
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale