static void generate_eeprom_spd(uint8_t *eeprom, ram_addr_t ram_size)

{

    enum { SDR = 0x4, DDR2 = 0x8 } type;

    uint8_t *spd = spd_eeprom.contents;

    uint8_t nbanks = 0;

    uint16_t density = 0;

    int i;



    /* work in terms of MB */

    ram_size >>= 20;



    while ((ram_size >= 4) && (nbanks <= 2)) {

        int sz_log2 = MIN(31 - clz32(ram_size), 14);

        nbanks++;

        density |= 1 << (sz_log2 - 2);

        ram_size -= 1 << sz_log2;

    }



    /* split to 2 banks if possible */

    if ((nbanks == 1) && (density > 1)) {

        nbanks++;

        density >>= 1;

    }



    if (density & 0xff00) {

        density = (density & 0xe0) | ((density >> 8) & 0x1f);

        type = DDR2;

    } else if (!(density & 0x1f)) {

        type = DDR2;

    } else {

        type = SDR;

    }



    if (ram_size) {

        fprintf(stderr, "Warning: SPD cannot represent final %dMB"

                " of SDRAM\n", (int)ram_size);

    }



    /* fill in SPD memory information */

    spd[2] = type;

    spd[5] = nbanks;

    spd[31] = density;



    /* checksum */

    spd[63] = 0;

    for (i = 0; i < 63; i++) {

        spd[63] += spd[i];

    }



    /* copy for SMBUS */

    memcpy(eeprom, spd, sizeof(spd_eeprom.contents));

}

static void generate_eeprom_spd(uint8_t *eeprom, ram_addr_t ram_size)

{

    enum { SDR = 0x4, DDR2 = 0x8 } type;

    uint8_t *spd = spd_eeprom.contents;

    uint8_t nbanks = 0;

    uint16_t density = 0;

    int i;



    

    ram_size >>= 20;



    while ((ram_size >= 4) && (nbanks <= 2)) {

        int sz_log2 = MIN(31 - clz32(ram_size), 14);

        nbanks++;

        density |= 1 << (sz_log2 - 2);

        ram_size -= 1 << sz_log2;

    }



    

    if ((nbanks == 1) && (density > 1)) {

        nbanks++;

        density >>= 1;

    }



    if (density & 0xff00) {

        density = (density & 0xe0) | ((density >> 8) & 0x1f);

        type = DDR2;

    } else if (!(density & 0x1f)) {

        type = DDR2;

    } else {

        type = SDR;

    }



    if (ram_size) {

        fprintf(stderr, "Warning: SPD cannot represent final %dMB"

                " of SDRAM\n", (int)ram_size);

    }



    

    spd[2] = type;

    spd[5] = nbanks;

    spd[31] = density;



    

    spd[63] = 0;

    for (i = 0; i < 63; i++) {

        spd[63] += spd[i];

    }



    

    memcpy(eeprom, spd, sizeof(spd_eeprom.contents));

}

static void FUNC_0(uint8_t *VAR_0, ram_addr_t VAR_1)

{

    enum { SDR = 0x4, DDR2 = 0x8 } VAR_2;

    uint8_t *spd = spd_eeprom.contents;

    uint8_t nbanks = 0;

    uint16_t density = 0;

    int VAR_3;



    

    VAR_1 >>= 20;



    while ((VAR_1 >= 4) && (nbanks <= 2)) {

        int VAR_4 = MIN(31 - clz32(VAR_1), 14);

        nbanks++;

        density |= 1 << (VAR_4 - 2);

        VAR_1 -= 1 << VAR_4;

    }



    

    if ((nbanks == 1) && (density > 1)) {

        nbanks++;

        density >>= 1;

    }



    if (density & 0xff00) {

        density = (density & 0xe0) | ((density >> 8) & 0x1f);

        VAR_2 = DDR2;

    } else if (!(density & 0x1f)) {

        VAR_2 = DDR2;

    } else {

        VAR_2 = SDR;

    }



    if (VAR_1) {

        fprintf(stderr, "Warning: SPD cannot represent final %dMB"

                " of SDRAM\n", (int)VAR_1);

    }



    

    spd[2] = VAR_2;

    spd[5] = nbanks;

    spd[31] = density;



    

    spd[63] = 0;

    for (VAR_3 = 0; VAR_3 < 63; VAR_3++) {

        spd[63] += spd[VAR_3];

    }



    

    memcpy(VAR_0, spd, sizeof(spd_eeprom.contents));

}

static void FUNC_0(uint8_t *VAR_0, ram_addr_t VAR_1)
{ enum { SDR = 0x4, DDR2 = 0x8 } VAR_2; uint8_t *spd = spd_eeprom.contents; uint8_t nbanks = 0; uint16_t density = 0; int VAR_3; VAR_1 >>= 20; while ((VAR_1 >= 4) && (nbanks <= 2)) { int VAR_4 = MIN(31 - clz32(VAR_1), 14); nbanks++; density |= 1 << (VAR_4 - 2); VAR_1 -= 1 << VAR_4; } if ((nbanks == 1) && (density > 1)) { nbanks++; density >>= 1; } if (density & 0xff00) { density = (density & 0xe0) | ((density >> 8) & 0x1f); VAR_2 = DDR2; } else if (!(density & 0x1f)) { VAR_2 = DDR2; } else { VAR_2 = SDR; } if (VAR_1) { fprintf(stderr, "Warning: SPD cannot represent final %dMB"
" of SDRAM\n", (int)VAR_1); } spd[2] = VAR_2; spd[5] = nbanks; spd[31] = density; spd[63] = 0; for (VAR_3 = 0; VAR_3 < 63; VAR_3++) { spd[63] += spd[VAR_3]; } memcpy(VAR_0, spd, sizeof(spd_eeprom.contents)); }