Joseph Smith wrote:
int i, spd_byte_31, spd_byte_5; spd_byte_31 = smbus_read_byte(device, 31); //please rename device to dimm spd_byte_5 = smbus_read_byte(device, 5);
for (i = 8; i >= 0; i--) { /* Find the larger value. The larger side is always side1 */ if (spd_byte_31 & (1 << i) == (1 << i)) { sz.side1 = i; break; } }
/* Set to 0 in case it's single sided */ sz.side2 = 0;
/* Test if it's a dual-sided dimm */ if (spd_byte_5 > 1) { /* Test to see if there's a second value, if so it's asymmetrical */ if (spd_byte_31 != (1 << i)) { /* Find the second value, picking up where we left off */ /* i-- done initially to make sure we don't get the same value again */ for (i--; i >= 0; i--) { if (spd_byte_31 == (1 << i) { sz.side2 = i; break; } } } /* If not, it's symmetrical */ else { sz.side2 = sz.side1; } return sz; //sizes are now in units of 4mb, so 1 = 4mb, 2 = 8mb, etc. }
-Corey
Corey, I have been playing around with this a bit. I really like it! The only thing I do not understand is how you get ticks of 4mb out of it. Say we have a single sided 128mb dimm. i is going to end up being 7 correct? 4 * 7 is not 128, I'm confused..... Couldn't you just make the end result something like sz.side1 = (1 << i) after it breaks out of the for loop? This would give you the total without messing around with ticks of 4mb right?
Yep, you're right. I didn't read correctly and screwed it up royally. Setting sz.sideX = (1 << i) is the correct way to get units of 4mb out of it. I wish there was an easier way to write the code, but this seems like the easiest way to figure out if there are 2 sides or not and separate the values.
-Corey