Lines Matching +full:buffer +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
14 * partition 1: 4K config file (sector size)
22 /* controller page size, in bytes */
24 #define EP_PAGE_MASK (EP_PAGE_SIZE - 1)
62 u32 buffer[EP_PAGE_DWORDS]; in read_length() local
75 * command address range. Note that '>' is correct below - the end in read_length()
79 return -EINVAL; in read_length()
88 read_page(dd, read_start, buffer); in read_length()
91 bytes = EP_PAGE_SIZE - start_offset; in read_length()
95 memcpy(dest, (u8 *)buffer + start_offset, len); in read_length()
99 memcpy(dest, (u8 *)buffer + start_offset, bytes); in read_length()
102 len -= bytes; in read_length()
109 read_page(dd, start, buffer); in read_length()
110 memcpy(dest, buffer, EP_PAGE_SIZE); in read_length()
113 len -= EP_PAGE_SIZE; in read_length()
119 read_page(dd, start, buffer); in read_length()
120 memcpy(dest, buffer, len); in read_length()
134 if (dd->pcidev->device != PCI_DEVICE_ID_INTEL0) in eprom_init()
160 dd->eprom_available = true; in eprom_init()
175 /* segment size - 128 KiB */
179 u32 oprom_size; /* size of the oprom, in bytes */
188 u32 size; /* file size, in bytes */ member
193 * buffer of size 'dir_size'.
196 (((dir_size) - sizeof(struct hfi1_eprom_footer)) / \
208 * the returned size if a trailing image magic is found.
211 u32 *size) in read_partition_platform_config() argument
213 void *buffer; in read_partition_platform_config() local
218 buffer = kmalloc(P1_SIZE, GFP_KERNEL); in read_partition_platform_config()
219 if (!buffer) in read_partition_platform_config()
220 return -ENOMEM; in read_partition_platform_config()
222 ret = read_length(dd, P1_START, P1_SIZE, buffer); in read_partition_platform_config()
224 kfree(buffer); in read_partition_platform_config()
229 if (memcmp(buffer, IMAGE_START_MAGIC, strlen(IMAGE_START_MAGIC))) { in read_partition_platform_config()
230 kfree(buffer); in read_partition_platform_config()
231 return -ENOENT; in read_partition_platform_config()
235 p = strnstr(buffer, IMAGE_TRAIL_MAGIC, P1_SIZE); in read_partition_platform_config()
237 length = p - buffer; in read_partition_platform_config()
241 *data = buffer; in read_partition_platform_config()
242 *size = length; in read_partition_platform_config()
250 * directory is a u32 aligned buffer of size EP_PAGE_SIZE.
253 void *directory, void **data, u32 *size) in read_segment_platform_config() argument
258 void *buffer = NULL; in read_segment_platform_config() local
267 (directory + EP_PAGE_SIZE - sizeof(*footer)); in read_segment_platform_config()
270 if (footer->version != FOOTER_VERSION) in read_segment_platform_config()
271 return -EINVAL; in read_segment_platform_config()
273 /* oprom size cannot be larger than a segment */ in read_segment_platform_config()
274 if (footer->oprom_size >= SEG_SIZE) in read_segment_platform_config()
275 return -EINVAL; in read_segment_platform_config()
278 if (footer->num_table_entries > in read_segment_platform_config()
279 MAX_TABLE_ENTRIES(SEG_SIZE - footer->oprom_size)) in read_segment_platform_config()
280 return -EINVAL; in read_segment_platform_config()
283 directory_size = DIRECTORY_SIZE(footer->num_table_entries); in read_segment_platform_config()
285 /* the file table fits into the directory buffer handed in */ in read_segment_platform_config()
287 (directory + EP_PAGE_SIZE - directory_size); in read_segment_platform_config()
292 return -ENOMEM; in read_segment_platform_config()
293 ret = read_length(dd, SEG_SIZE - directory_size, in read_segment_platform_config()
301 for (entry = NULL, i = 0; i < footer->num_table_entries; i++) { in read_segment_platform_config()
308 ret = -ENOENT; in read_segment_platform_config()
313 * Sanity check on the configuration file size - it should never in read_segment_platform_config()
316 if (entry->size > (4 * 1024)) { in read_segment_platform_config()
317 dd_dev_err(dd, "Bad configuration file size 0x%x\n", in read_segment_platform_config()
318 entry->size); in read_segment_platform_config()
319 ret = -EINVAL; in read_segment_platform_config()
323 /* check for bogus offset and size that wrap when added together */ in read_segment_platform_config()
324 if (entry->offset + entry->size < entry->offset) { in read_segment_platform_config()
326 "Bad configuration file start + size 0x%x+0x%x\n", in read_segment_platform_config()
327 entry->offset, entry->size); in read_segment_platform_config()
328 ret = -EINVAL; in read_segment_platform_config()
332 /* allocate the buffer to return */ in read_segment_platform_config()
333 buffer = kmalloc(entry->size, GFP_KERNEL); in read_segment_platform_config()
334 if (!buffer) { in read_segment_platform_config()
335 ret = -ENOMEM; in read_segment_platform_config()
342 seg_offset = entry->offset % SEG_SIZE; in read_segment_platform_config()
343 seg_base = entry->offset - seg_offset; in read_segment_platform_config()
345 while (ncopied < entry->size) { in read_segment_platform_config()
349 bytes_available = SEG_SIZE - seg_offset; in read_segment_platform_config()
358 "Bad configuration file - offset 0x%x within footer+table\n", in read_segment_platform_config()
359 entry->offset); in read_segment_platform_config()
360 ret = -EINVAL; in read_segment_platform_config()
363 bytes_available -= directory_size; in read_segment_platform_config()
367 to_copy = entry->size - ncopied; in read_segment_platform_config()
376 * The sanity check for entry->offset is done in read_length(). in read_segment_platform_config()
384 buffer + ncopied); in read_segment_platform_config()
391 seg_offset = footer->oprom_size; in read_segment_platform_config()
397 *data = buffer; in read_segment_platform_config()
398 *size = entry->size; in read_segment_platform_config()
403 kfree(buffer); in read_segment_platform_config()
410 * On success, an allocated buffer containing the data and its size are
411 * returned. It is up to the caller to free this buffer.
414 * 0 - success
415 * -ENXIO - no EPROM is available
416 * -EBUSY - not able to acquire access to the EPROM
417 * -ENOENT - no recognizable file written
418 * -ENOMEM - buffer could not be allocated
419 * -EINVAL - invalid EPROM contentents found
421 int eprom_read_platform_config(struct hfi1_devdata *dd, void **data, u32 *size) in eprom_read_platform_config() argument
423 u32 directory[EP_PAGE_DWORDS]; /* aligned buffer */ in eprom_read_platform_config()
426 if (!dd->eprom_available) in eprom_read_platform_config()
427 return -ENXIO; in eprom_read_platform_config()
431 return -EBUSY; in eprom_read_platform_config()
434 ret = read_length(dd, SEG_SIZE - EP_PAGE_SIZE, EP_PAGE_SIZE, directory); in eprom_read_platform_config()
439 if (directory[EP_PAGE_DWORDS - 1] == FOOTER_MAGIC) { in eprom_read_platform_config()
441 ret = read_segment_platform_config(dd, directory, data, size); in eprom_read_platform_config()
444 ret = read_partition_platform_config(dd, data, size); in eprom_read_platform_config()