Пример #1
0
def writeMainIndex(enums, structs, regs):
    diff_list = []
    out = open("html/index.html", "w")
    writePageHeader(out, "Cavium Chip Information")
    out.write("<table class=\"layout_table\">\n")
    out.write("<tr><td>\n")
    out.write("<font size=-1>Updated: %s</font><br><br>\n" % time.asctime())
    out.write("<font size=+2>Chips</font><br>\n")
    out.write("<table class=\"chips_table\">\n")
    out.write("<tr>")
    out.write(TH("Chip"))
    out.write(TH("Pass", colspan=4))
    out.write("</tr>")
    by_model = {}
    for chip in chip_list.getChips():
        family, model, pass_num = chip_list.getChipNameParts(chip)
        if not model in by_model:
            by_model[model] = []
        by_model[model].append((chip, pass_num))
    models = by_model.keys()
    models.sort()
    for model in models:
        out.write("<tr>")
        out.write(TD(model))
        last_chip = None
        for chip, p in by_model[model]:
            link = "<a href=%s.html target=\"frame\">%.1f</a>" % (chip.lower(),
                                                                  p)
            out.write(TD(link))
            if last_chip:
                diff_list.append(
                    diffChip(last_chip, chip, enums, structs, regs))
            last_chip = chip
        out.write("</tr>\n")
    out.write("</table>\n")
    out.write("<font size=+2>Differences</font><br>\n")
    for diff in chip_list.DIFFS:
        diff_list.append(diffChip(diff[0], diff[1], enums, structs, regs))
    out.write("<table class=\"chips_table\">\n")
    out.write("<tr>")
    out.write(TH("Chip1"))
    out.write(TH("Chip2"))
    out.write(TH("Diff"))
    out.write("</tr>\n")
    for diff in diff_list:
        out.write("<tr>")
        out.write(TD(diff[0].replace("P", "&nbsp;").replace("_", ".")))
        out.write(TD(diff[1].replace("P", "&nbsp;").replace("_", ".")))
        link = "<a href=%s target=\"frame\">diff</a>" % diff[2]
        out.write(TD(link))
        out.write("</tr>\n")
    out.write("</table>\n")
    out.write("</td>\n")
    out.write("<td width=100%>")
    out.write("<iframe name=\"frame\" width=100%></iframe>\n")
    out.write("</td></tr>\n")
    out.write("</table>\n")
    writePageFooter(out)
    out.close()
def consolidateChips(by_chip, useArch=None):
    # Worker function to check that all "keys" are in "dict" and the same. If
    # they are, remove the keys and replace them with a single item "new_key".
    def check_all_same(keys, dict, new_key):
        ref = None
        ref_str = None
        for key in keys:
            if not key in by_chip:
                return False
            s = str(dict[key])
            if ref_str == None:
                ref = dict[key]
                ref_str = s
            elif s != ref_str:
                return False
        for key in keys:
            del dict[key]
        dict[new_key] = ref
        return True

    # If an architecture was supplied, all chips for said architecture must be
    # present for consolidation. Otherwise we just require the ones passed.
    if useArch:
        chips = []
        for chip in chip_list.getChips():
            if csr_utils.isChipArch(useArch, chip):
                chips.append(chip)
    else:
        chips = by_chip.keys()
    # Create a multi-level dictionary describing all the families, models,
    # major passes, and minor passes in use
    used_chips = {}
    for chip in chips:
        family, model, chip_pass = chip_list.getChipNameParts(chip)
        major = "%s_P%d" % (model, int(chip_pass))
        if not family in used_chips:
            used_chips[family] = {}
        if not model in used_chips[family]:
            used_chips[family][model] = {}
        if not major in used_chips[family][model]:
            used_chips[family][model][major] = []
        used_chips[family][model][major].append(chip)
    # Search for and consolidate duplicates
    family_all_same = True
    for family in used_chips:
        model_all_same = True
        for model in used_chips[family]:
            major_all_same = True
            for major in used_chips[family][model]:
                minor_all_same = check_all_same(
                    used_chips[family][model][major], by_chip, major)
                major_all_same &= minor_all_same
            if major_all_same:
                major_all_same = check_all_same(
                    used_chips[family][model].keys(), by_chip, model)
                model_all_same &= major_all_same
        if model_all_same:
            model_all_same = check_all_same(used_chips[family].keys(), by_chip,
                                            family)
            family_all_same &= model_all_same
    if family_all_same:
        check_all_same(used_chips.keys(), by_chip, "CN")
Пример #3
0
def writeStruct(out, arch, struct, title="Structure"):
    out.write("\n")
    out.write("/**\n")
    out.write(" * %s %s\n" % (title, struct["name"]))
    description = getAnyField(struct, "description", arch)
    if description:
        out.write(" *\n")
        description = description.replace("<", "\<")
        description = description.replace(">", "\>")
        for l in description.split("\n"):
            l = l.rstrip()
            if l:
                out.write(" * %s\n" % l)
            else:
                out.write(" *\n")
    out.write(" */\n")
    struct_name = (PREFIX + struct["name"]).replace("#", "X").lower()
    out.write("union %s\n" % struct_name)
    out.write("{\n")
    width = csr_utils.getSizeBits(struct, multipleOf=32)
    if width % 64 == 0:
        if width > 64:
            out.write("    uint64_t u[%d];\n" % (width / 64))
        else:
            out.write("    uint64_t u;\n")
    else:
        if width % 32 != 0:
            csr_utils.raiseException(
                struct, "Struct: Size expected to be a multiple of 32")
        if width > 32:
            out.write("    uint32_t u[%d];\n" % (width / 32))
        else:
            out.write("    uint32_t u;\n")
    # Create a dictionary of all per chip structures
    struct_items = {}
    for chip in struct["description"]:
        is_this_arch = csr_utils.isChipArch(arch, chip)
        if not is_this_arch:
            continue
        struct_items[chip] = buildStructMembers(chip, struct)
    # Consolidate all chips
    consolidateChips(struct_items)
    for chip in struct["description"]:
        is_this_arch = csr_utils.isChipArch(arch, chip)
        if not is_this_arch:
            continue
        chip_family, chip_model, chip_pass = chip_list.getChipNameParts(chip)
        if (not "CN" in struct_items) and (not chip_family in struct_items):
            struct[chip_family] = csr_utils.createSubset(
                arch, chip_family, struct)
            struct_items[chip_family] = buildStructMembers(
                chip_family, struct[chip_family])
    # Start writing structures with subset first
    written_structs = {}
    out.write("    struct %s_s\n" % struct_name)
    out.write("    {\n")
    subset = csr_utils.createSubset(arch, "s", struct)
    struct_chip = buildStructMembers("s", subset)
    written_structs[struct_chip] = struct_name + "_s"
    out.write(struct_chip)
    out.write("    } s;\n")
    for chip in csr_data.iterChipOrder(struct_items):
        struct_chip = struct_items[chip]
        chip_member = chip_list.chipToStructName(chip)
        if struct_chip in written_structs:
            # Chip duplicates one we have already written
            out.write("    /* struct %s %s; */\n" %
                      (written_structs[struct_chip], chip_member))
        else:
            # New structure
            name = "%s_%s" % (struct_name, chip_member)
            written_structs[struct_chip] = name
            out.write("    struct %s\n" % name)
            out.write("    {\n")
            out.write(struct_chip)
            out.write("    } %s;\n" % chip_member)
    out.write("};\n")
    if title.startswith("Reg"):
        out.write("typedef union %s %s_t;\n" % (struct_name, struct_name))
Пример #4
0
def createSubset(arch, family, struct_reg):
    isReg = isinstance(struct_reg, csr_data.Register)
    bit_size = getSizeBits(struct_reg, multipleOf=0)
    if bit_size & 63:
        multipleOf = 32
    else:
        multipleOf = 64
    if isReg:
        subset = csr_data.Register(struct_reg["name"])
    else:
        subset = csr_data.Struct(struct_reg["name"])
    # Go through all the fields, skipping reserved bits
    subset["description"][family] = "Common subset"
    subset_fields = subset["fields"]
    for name in struct_reg["fields"]:
        if isReserved(name):
            continue
        start_bit_changed = False
        start_bit = None
        stop_bit = None
        description = ""
        access = ""
        f = struct_reg["fields"][name]
        # Go through all the chips for this field and expand it so that
        # start_bit and stop_bit encompass the largest version of the field.
        # Remember if the start_bit changed as we can't handle that in C code.
        for chip in f["bits"].iterChip():
            # Skip other architecture as we don't care about conflicts
            if not isChipArch(arch, chip):
                continue
            if not family == "s":
                chip_family, chip_model, chip_pass = chip_list.getChipNameParts(
                    chip)
                if not family == chip_family:
                    continue
            if start_bit == None:
                start_bit, stop_bit = f["bits"][chip]
                description = f["description"][chip]
                if isReg:
                    access = f["access"][chip]
            elif f["bits"][chip][0] < start_bit:
                start_bit = f["bits"][chip][0]
                start_bit_changed = True
            elif f["bits"][chip][0] > start_bit:
                start_bit_changed = True
            elif f["bits"][chip][1] > stop_bit:
                stop_bit = f["bits"][chip][1]
        if start_bit == None:
            continue
        # Add this field to the subset
        if isReg:
            subset_fields[name] = csr_data.RegisterField(name)
            subset_fields[name]["access"][family] = access
        else:
            subset_fields[name] = csr_data.StructField(name)
        subset_fields[name]["bits"][family] = (start_bit, stop_bit)
        subset_fields[name]["description"][family] = description
        # Remember if the start_bit changed, causing this field to be a conflict
        subset_fields[name]["conflict_bits"] = start_bit_changed
    # Loop through all the fields in the subset looking for overlaps
    for name in subset_fields:
        start_bit, stop_bit = subset_fields[name]["bits"][family]
        # Check against all fields except myself
        for n in subset_fields:
            if n == name:
                continue
            # Mark both fields as conflicts if they overlap
            if start_bit <= subset_fields[n]["bits"][family][
                    1] and stop_bit >= subset_fields[n]["bits"][family][0]:
                subset_fields[name]["conflict_bits"] = True
                subset_fields[n]["conflict_bits"] = True
    # Loop through the subset fields deleting the ones we flagged as conflicts
    names = subset_fields.keys()
    for name in names:
        if subset_fields[name]["conflict_bits"]:
            # Delete the conflict
            del subset_fields[name]
        else:
            # Delete the false conflict marker
            del subset_fields[name]["conflict_bits"]
    # Fields should only be a valid subset. Now fill in the holes
    holes = findBitHoles(subset, multipleOf)
    subset_size = getSizeBits(subset, multipleOf=0)
    while subset_size < bit_size:
        start_bit = subset_size
        stop_bit = bit_size - 1
        max_step = (start_bit & -multipleOf) + multipleOf - 1
        if stop_bit > max_step:
            stop_bit = max_step
        subset_size = stop_bit + 1
        if not family in holes:
            holes[family] = []
        if (len(holes[family]) > 0) and holes[family][-1][1] == stop_bit:
            pass  # Already in holes list
        else:
            holes[family].append((start_bit, stop_bit))
            #print "Padding for %s on subset: %d..%d" % (struct_reg["name"], start_bit, stop_bit)
    if holes:
        for hole in holes[family]:
            n = getReservedName(hole)
            #print "Filling hole in %s for subset: %s" % (struct_reg["name"], n)
            assert not n in subset_fields
            if isReg:
                subset_fields[n] = csr_data.RegisterField(n)
            else:
                subset_fields[n] = csr_data.StructField(n)
            subset_fields[n]["bits"][family] = hole
    subset_size = getSizeBits(subset, multipleOf)
    assert subset_size == bit_size, "%s subset %d, original %d" % (
        struct_reg["name"], subset_size, bit_size)
    return subset