write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_READ_DATA(offset)); for (i = 0; i < EP_PAGE_DWORDS; i++)
result[i] = (u32)read_csr(dd, ASIC_EEP_DATA);
write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_NOP); /* close open page */
}
struct hfi1_eprom_footer {
u32 oprom_size; /* size of the oprom, in bytes */
u16 num_table_entries;
u16 version; /* version of this footer */
u32 magic; /* must be last */
};
struct hfi1_eprom_table_entry {
u32 type; /* file type */
u32 offset; /* file offset from start of EPROM */
u32 size; /* file size, in bytes */
};
buffer = kmalloc(P1_SIZE, GFP_KERNEL); if (!buffer) return -ENOMEM;
ret = read_length(dd, P1_START, P1_SIZE, buffer); if (ret) {
kfree(buffer); return ret;
}
/* config partition is valid only if it starts with IMAGE_START_MAGIC */ if (memcmp(buffer, IMAGE_START_MAGIC, strlen(IMAGE_START_MAGIC))) {
kfree(buffer); return -ENOENT;
}
/* scan for image magic that may trail the actual data */
p = strnstr(buffer, IMAGE_TRAIL_MAGIC, P1_SIZE); if (p)
length = p - buffer; else
length = P1_SIZE;
/* the footer is at the end of the directory */
footer = (struct hfi1_eprom_footer *)
(directory + EP_PAGE_SIZE - sizeof(*footer));
/* make sure the structure version is supported */ if (footer->version != FOOTER_VERSION) return -EINVAL;
/* oprom size cannot be larger than a segment */ if (footer->oprom_size >= SEG_SIZE) return -EINVAL;
/* the file table must fit in a segment with the oprom */ if (footer->num_table_entries >
MAX_TABLE_ENTRIES(SEG_SIZE - footer->oprom_size)) return -EINVAL;
/* find the file table start, which precedes the footer */
directory_size = DIRECTORY_SIZE(footer->num_table_entries); if (directory_size <= EP_PAGE_SIZE) { /* the file table fits into the directory buffer handed in */
table = (struct hfi1_eprom_table_entry *)
(directory + EP_PAGE_SIZE - directory_size);
} else { /* need to allocate and read more */
table_buffer = kmalloc(directory_size, GFP_KERNEL); if (!table_buffer) return -ENOMEM;
ret = read_length(dd, SEG_SIZE - directory_size,
directory_size, table_buffer); if (ret) goto done;
table = table_buffer;
}
/* look for the platform configuration file in the table */ for (entry = NULL, i = 0; i < footer->num_table_entries; i++) { if (table[i].type == HFI1_EFT_PLATFORM_CONFIG) {
entry = &table[i]; break;
}
} if (!entry) {
ret = -ENOENT; goto done;
}
/* check for bogus offset and size that wrap when added together */ if (entry->offset + entry->size < entry->offset) {
dd_dev_err(dd, "Bad configuration file start + size 0x%x+0x%x\n",
entry->offset, entry->size);
ret = -EINVAL; goto done;
}
/* allocate the buffer to return */
buffer = kmalloc(entry->size, GFP_KERNEL); if (!buffer) {
ret = -ENOMEM; goto done;
}
/* *Extractthefilebyloopingoversegmentsuntilitisfullyread.
*/
seg_offset = entry->offset % SEG_SIZE;
seg_base = entry->offset - seg_offset;
ncopied = 0; while (ncopied < entry->size) { /* calculate data bytes available in this segment */
/* start with the bytes from the current offset to the end */
bytes_available = SEG_SIZE - seg_offset; /* subtract off footer and table from segment 0 */ if (seg_base == 0) { /* *Sanitycheck:shouldnothaveastartingpoint *atorwithinthedirectory.
*/ if (bytes_available <= directory_size) {
dd_dev_err(dd, "Bad configuration file - offset 0x%x within footer+table\n",
entry->offset);
ret = -EINVAL; goto done;
}
bytes_available -= directory_size;
}
ret = acquire_chip_resource(dd, CR_EPROM, EPROM_TIMEOUT); if (ret) return -EBUSY;
/* read the last page of the segment for the EPROM format magic */
ret = read_length(dd, SEG_SIZE - EP_PAGE_SIZE, EP_PAGE_SIZE, directory); if (ret) goto done;
/* last dword of the segment contains a magic value */ if (directory[EP_PAGE_DWORDS - 1] == FOOTER_MAGIC) { /* segment format */
ret = read_segment_platform_config(dd, directory, data, size);
} else { /* partition format */
ret = read_partition_platform_config(dd, data, size);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.