aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorTimur Tabi <timur@freescale.com>2008-01-08 11:30:58 -0500
committerKumar Gala <galak@kernel.crashing.org>2008-01-23 20:34:06 -0500
commitbc556ba940085e46e0ab1b5ed7c31428dc86dd03 (patch)
tree68d8aada0531c5d5070c3e7327de606894584971 /arch
parenta21e282a124f4679c040087ab73aa5b147d4275f (diff)
[POWERPC] 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. Added description of a new QE firmware node to booting-without-of.txt. Signed-off-by: Timur Tabi <timur@freescale.com> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/platforms/Kconfig1
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe.c247
2 files changed, 248 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index ea22cad2cd0a..18f101bcca94 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -265,6 +265,7 @@ config TAU_AVERAGE
265config QUICC_ENGINE 265config QUICC_ENGINE
266 bool 266 bool
267 select PPC_LIB_RHEAP 267 select PPC_LIB_RHEAP
268 select CRC32
268 help 269 help
269 The QUICC Engine (QE) is a new generation of communications 270 The QUICC Engine (QE) is a new generation of communications
270 coprocessors on Freescale embedded CPUs (akin to CPM in older chips). 271 coprocessors on Freescale embedded CPUs (akin to CPM in older chips).
diff --git a/arch/powerpc/sysdev/qe_lib/qe.c b/arch/powerpc/sysdev/qe_lib/qe.c
index 21e01061aca9..3925eae9b0f5 100644
--- a/arch/powerpc/sysdev/qe_lib/qe.c
+++ b/arch/powerpc/sysdev/qe_lib/qe.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/ioport.h> 27#include <linux/ioport.h>
28#include <linux/crc32.h>
28#include <asm/irq.h> 29#include <asm/irq.h>
29#include <asm/page.h> 30#include <asm/page.h>
30#include <asm/pgtable.h> 31#include <asm/pgtable.h>
@@ -394,3 +395,249 @@ void *qe_muram_addr(unsigned long offset)
394 return (void *)&qe_immr->muram[offset]; 395 return (void *)&qe_immr->muram[offset];
395} 396}
396EXPORT_SYMBOL(qe_muram_addr); 397EXPORT_SYMBOL(qe_muram_addr);
398
399/* The maximum number of RISCs we support */
400#define MAX_QE_RISC 2
401
402/* Firmware information stored here for qe_get_firmware_info() */
403static struct qe_firmware_info qe_firmware_info;
404
405/*
406 * Set to 1 if QE firmware has been uploaded, and therefore
407 * qe_firmware_info contains valid data.
408 */
409static int qe_firmware_uploaded;
410
411/*
412 * Upload a QE microcode
413 *
414 * This function is a worker function for qe_upload_firmware(). It does
415 * the actual uploading of the microcode.
416 */
417static void qe_upload_microcode(const void *base,
418 const struct qe_microcode *ucode)
419{
420 const __be32 *code = base + be32_to_cpu(ucode->code_offset);
421 unsigned int i;
422
423 if (ucode->major || ucode->minor || ucode->revision)
424 printk(KERN_INFO "qe-firmware: "
425 "uploading microcode '%s' version %u.%u.%u\n",
426 ucode->id, ucode->major, ucode->minor, ucode->revision);
427 else
428 printk(KERN_INFO "qe-firmware: "
429 "uploading microcode '%s'\n", ucode->id);
430
431 /* Use auto-increment */
432 out_be32(&qe_immr->iram.iadd, be32_to_cpu(ucode->iram_offset) |
433 QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR);
434
435 for (i = 0; i < be32_to_cpu(ucode->count); i++)
436 out_be32(&qe_immr->iram.idata, be32_to_cpu(code[i]));
437}
438
439/*
440 * Upload a microcode to the I-RAM at a specific address.
441 *
442 * See Documentation/powerpc/qe-firmware.txt for information on QE microcode
443 * uploading.
444 *
445 * Currently, only version 1 is supported, so the 'version' field must be
446 * set to 1.
447 *
448 * The SOC model and revision are not validated, they are only displayed for
449 * informational purposes.
450 *
451 * 'calc_size' is the calculated size, in bytes, of the firmware structure and
452 * all of the microcode structures, minus the CRC.
453 *
454 * 'length' is the size that the structure says it is, including the CRC.
455 */
456int qe_upload_firmware(const struct qe_firmware *firmware)
457{
458 unsigned int i;
459 unsigned int j;
460 u32 crc;
461 size_t calc_size = sizeof(struct qe_firmware);
462 size_t length;
463 const struct qe_header *hdr;
464
465 if (!firmware) {
466 printk(KERN_ERR "qe-firmware: invalid pointer\n");
467 return -EINVAL;
468 }
469
470 hdr = &firmware->header;
471 length = be32_to_cpu(hdr->length);
472
473 /* Check the magic */
474 if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
475 (hdr->magic[2] != 'F')) {
476 printk(KERN_ERR "qe-firmware: not a microcode\n");
477 return -EPERM;
478 }
479
480 /* Check the version */
481 if (hdr->version != 1) {
482 printk(KERN_ERR "qe-firmware: unsupported version\n");
483 return -EPERM;
484 }
485
486 /* Validate some of the fields */
487 if ((firmware->count < 1) || (firmware->count >= MAX_QE_RISC)) {
488 printk(KERN_ERR "qe-firmware: invalid data\n");
489 return -EINVAL;
490 }
491
492 /* Validate the length and check if there's a CRC */
493 calc_size += (firmware->count - 1) * sizeof(struct qe_microcode);
494
495 for (i = 0; i < firmware->count; i++)
496 /*
497 * For situations where the second RISC uses the same microcode
498 * as the first, the 'code_offset' and 'count' fields will be
499 * zero, so it's okay to add those.
500 */
501 calc_size += sizeof(__be32) *
502 be32_to_cpu(firmware->microcode[i].count);
503
504 /* Validate the length */
505 if (length != calc_size + sizeof(__be32)) {
506 printk(KERN_ERR "qe-firmware: invalid length\n");
507 return -EPERM;
508 }
509
510 /* Validate the CRC */
511 crc = be32_to_cpu(*(__be32 *)((void *)firmware + calc_size));
512 if (crc != crc32(0, firmware, calc_size)) {
513 printk(KERN_ERR "qe-firmware: firmware CRC is invalid\n");
514 return -EIO;
515 }
516
517 /*
518 * If the microcode calls for it, split the I-RAM.
519 */
520 if (!firmware->split)
521 setbits16(&qe_immr->cp.cercr, QE_CP_CERCR_CIR);
522
523 if (firmware->soc.model)
524 printk(KERN_INFO
525 "qe-firmware: firmware '%s' for %u V%u.%u\n",
526 firmware->id, be16_to_cpu(firmware->soc.model),
527 firmware->soc.major, firmware->soc.minor);
528 else
529 printk(KERN_INFO "qe-firmware: firmware '%s'\n",
530 firmware->id);
531
532 /*
533 * The QE only supports one microcode per RISC, so clear out all the
534 * saved microcode information and put in the new.
535 */
536 memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
537 strcpy(qe_firmware_info.id, firmware->id);
538 qe_firmware_info.extended_modes = firmware->extended_modes;
539 memcpy(qe_firmware_info.vtraps, firmware->vtraps,
540 sizeof(firmware->vtraps));
541
542 /* Loop through each microcode. */
543 for (i = 0; i < firmware->count; i++) {
544 const struct qe_microcode *ucode = &firmware->microcode[i];
545
546 /* Upload a microcode if it's present */
547 if (ucode->code_offset)
548 qe_upload_microcode(firmware, ucode);
549
550 /* Program the traps for this processor */
551 for (j = 0; j < 16; j++) {
552 u32 trap = be32_to_cpu(ucode->traps[j]);
553
554 if (trap)
555 out_be32(&qe_immr->rsp[i].tibcr[j], trap);
556 }
557
558 /* Enable traps */
559 out_be32(&qe_immr->rsp[i].eccr, be32_to_cpu(ucode->eccr));
560 }
561
562 qe_firmware_uploaded = 1;
563
564 return 0;
565}
566EXPORT_SYMBOL(qe_upload_firmware);
567
568/*
569 * Get info on the currently-loaded firmware
570 *
571 * This function also checks the device tree to see if the boot loader has
572 * uploaded a firmware already.
573 */
574struct qe_firmware_info *qe_get_firmware_info(void)
575{
576 static int initialized;
577 struct property *prop;
578 struct device_node *qe;
579 struct device_node *fw = NULL;
580 const char *sprop;
581 unsigned int i;
582
583 /*
584 * If we haven't checked yet, and a driver hasn't uploaded a firmware
585 * yet, then check the device tree for information.
586 */
587 if (initialized || qe_firmware_uploaded)
588 return NULL;
589
590 initialized = 1;
591
592 /*
593 * Newer device trees have an "fsl,qe" compatible property for the QE
594 * node, but we still need to support older device trees.
595 */
596 qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
597 if (!qe) {
598 qe = of_find_node_by_type(NULL, "qe");
599 if (!qe)
600 return NULL;
601 }
602
603 /* Find the 'firmware' child node */
604 for_each_child_of_node(qe, fw) {
605 if (strcmp(fw->name, "firmware") == 0)
606 break;
607 }
608
609 of_node_put(qe);
610
611 /* Did we find the 'firmware' node? */
612 if (!fw)
613 return NULL;
614
615 qe_firmware_uploaded = 1;
616
617 /* Copy the data into qe_firmware_info*/
618 sprop = of_get_property(fw, "id", NULL);
619 if (sprop)
620 strncpy(qe_firmware_info.id, sprop,
621 sizeof(qe_firmware_info.id) - 1);
622
623 prop = of_find_property(fw, "extended-modes", NULL);
624 if (prop && (prop->length == sizeof(u64))) {
625 const u64 *iprop = prop->value;
626
627 qe_firmware_info.extended_modes = *iprop;
628 }
629
630 prop = of_find_property(fw, "virtual-traps", NULL);
631 if (prop && (prop->length == 32)) {
632 const u32 *iprop = prop->value;
633
634 for (i = 0; i < ARRAY_SIZE(qe_firmware_info.vtraps); i++)
635 qe_firmware_info.vtraps[i] = iprop[i];
636 }
637
638 of_node_put(fw);
639
640 return &qe_firmware_info;
641}
642EXPORT_SYMBOL(qe_get_firmware_info);
643