Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Staging: sep: tidy firmware load

Start by removing unused fields and then work this back to eliminate unused
chunks of the firmware loading ioctl (ie almost all of it)

Also fix the wrong handling of shared allocations and allocate the rar
region properly with dma_alloc_coherent not kmalloc, as it is device shared.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Cox and committed by
Greg Kroah-Hartman
6f13ea3d 51faa9d2

+48 -110
+1 -1
drivers/staging/sep/sep_dev.h
··· 54 54 unsigned long resident_size; 55 55 void *resident_addr; 56 56 57 - unsigned long rar_region_addr; 57 + void *rar_region_addr; 58 58 59 59 /* start address of the access to the SEP registers from driver */ 60 60 void __iomem *reg_addr;
+43 -87
drivers/staging/sep/sep_driver.c
··· 170 170 /* wait queue head (event) of the driver */ 171 171 static DECLARE_WAIT_QUEUE_HEAD(sep_event); 172 172 173 - /* 174 - This functions copies the cache and resident from their source location into 175 - destination memory, which is external to Linux VM and is given as 176 - bus address 177 - */ 178 - static int sep_copy_cache_resident_to_area(struct sep_device *sep, 179 - unsigned long src_cache_addr, 180 - unsigned long cache_size_in_bytes, 181 - unsigned long src_resident_addr, 182 - unsigned long resident_size_in_bytes, 183 - unsigned long *dst_new_cache_addr_ptr, 184 - unsigned long *dst_new_resident_addr_ptr) 185 - { 186 - void *resident_addr; 187 - void *cache_addr; 188 - const struct firmware *fw; 173 + /** 174 + * sep_load_firmware - copy firmware cache/resident 175 + * @sep: device we are loading 176 + * 177 + * This functions copies the cache and resident from their source 178 + * location into destination shared memory. 179 + */ 189 180 181 + static int sep_load_firmware(struct sep_device *sep) 182 + { 183 + const struct firmware *fw; 190 184 char *cache_name = "cache.image.bin"; 191 185 char *res_name = "resident.image.bin"; 192 - 193 - /* error */ 194 186 int error; 195 - 196 - /*-------------------------------- 197 - CODE 198 - -------------------------------------*/ 199 - error = 0; 200 187 201 188 edbg("SEP Driver:rar_virtual is %p\n", sep->rar_addr); 202 189 edbg("SEP Driver:rar_bus is %08llx\n", (unsigned long long)sep->rar_bus); 203 190 204 - sep->rar_region_addr = (unsigned long) sep->rar_addr; 205 - 191 + sep->rar_region_addr = sep->rar_addr; 206 192 sep->cache_bus = sep->rar_bus; 207 193 sep->cache_addr = sep->rar_addr; 208 194 ··· 196 210 error = request_firmware(&fw, cache_name, &sep->pdev->dev); 197 211 if (error) { 198 212 edbg("SEP Driver:cant request cache fw\n"); 199 - goto end_function; 213 + return error; 200 214 } 215 + edbg("SEP Driver:cache %08Zx@%p\n", fw->size, (void *) fw->data); 201 216 202 - edbg("SEP Driver:cache data loc is %p\n", (void *) fw->data); 203 - edbg("SEP Driver:cache data size is %08Zx\n", fw->size); 204 - 205 - memcpy(sep->cache_addr, (void *) fw->data, fw->size); 206 - 217 + memcpy(sep->cache_addr, (void *)fw->data, fw->size); 207 218 sep->cache_size = fw->size; 208 - 209 - cache_addr = sep->cache_addr; 210 - 211 219 release_firmware(fw); 212 220 213 221 sep->resident_bus = sep->cache_bus + sep->cache_size; ··· 211 231 error = request_firmware(&fw, res_name, &sep->pdev->dev); 212 232 if (error) { 213 233 edbg("SEP Driver:cant request res fw\n"); 214 - goto end_function; 234 + return error; 215 235 } 236 + edbg("sep: res %08Zx@%p\n", fw->size, (void *)fw->data); 216 237 217 - edbg("SEP Driver:res data loc is %p\n", (void *) fw->data); 218 - edbg("SEP Driver:res data size is %08Zx\n", fw->size); 219 - 220 - memcpy((void *) sep->resident_addr, (void *) fw->data, fw->size); 221 - 238 + memcpy(sep->resident_addr, (void *) fw->data, fw->size); 222 239 sep->resident_size = fw->size; 223 - 224 240 release_firmware(fw); 225 241 226 - resident_addr = sep->resident_addr; 227 - 228 - edbg("SEP Driver:resident_addr (bus)is %08llx\n", (unsigned long long)sep->resident_bus); 229 - edbg("SEP Driver:cache_addr (bus) is %08llx\n", (unsigned long long)sep->cache_bus); 230 - 231 - edbg("SEP Driver:resident_addr (virtual)is %p\n", resident_addr); 232 - edbg("SEP Driver:cache_addr (virtual) is %08llx\n", (unsigned long long)cache_addr); 233 - 234 - edbg("SEP Driver:resident_size is %08lx\n", sep->resident_size); 235 - edbg("SEP Driver:cache_size is %08llx\n", (unsigned long long)sep->cache_size); 236 - 237 - 238 - 239 - /* bus addresses */ 240 - *dst_new_cache_addr_ptr = sep->cache_bus; 241 - *dst_new_resident_addr_ptr = sep->resident_bus; 242 - end_function: 243 - return error; 242 + edbg("sep: resident v %p b %08llx cache v %p b %08llx\n", 243 + sep->resident_addr, (unsigned long long)sep->resident_bus, 244 + sep->cache_addr, (unsigned long long)sep->cache_bus); 245 + return 0; 244 246 } 245 247 246 248 /** ··· 2087 2125 static int sep_realloc_cache_resident_handler(struct sep_device *sep, 2088 2126 unsigned long arg) 2089 2127 { 2090 - int error; 2091 - unsigned long bus_cache_address; 2092 - unsigned long bus_resident_address; 2093 2128 struct sep_driver_realloc_cache_resident_t command_args; 2094 - 2095 - /* copy the data */ 2096 - error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_realloc_cache_resident_t)); 2097 - if (error) 2098 - goto end_function; 2129 + int error; 2099 2130 2100 2131 /* copy cache and resident to the their intended locations */ 2101 - error = sep_copy_cache_resident_to_area(sep, command_args.cache_addr, command_args.cache_size_in_bytes, command_args.resident_addr, command_args.resident_size_in_bytes, &bus_cache_address, &bus_resident_address); 2132 + error = sep_load_firmware(sep); 2102 2133 if (error) 2103 - goto end_function; 2134 + return error; 2104 2135 2105 2136 command_args.new_base_addr = sep->shared_area_bus; 2106 2137 2107 2138 /* find the new base address according to the lowest address between 2108 2139 cache, resident and shared area */ 2109 - if (bus_resident_address < command_args.new_base_addr) 2110 - command_args.new_base_addr = bus_resident_address; 2111 - if (bus_cache_address < command_args.new_base_addr) 2112 - command_args.new_base_addr = bus_cache_address; 2140 + if (sep->resident_bus < command_args.new_base_addr) 2141 + command_args.new_base_addr = sep->resident_bus; 2142 + if (sep->cache_bus < command_args.new_base_addr) 2143 + command_args.new_base_addr = sep->cache_bus; 2113 2144 2114 2145 /* set the return parameters */ 2115 - command_args.new_cache_addr = bus_cache_address; 2116 - command_args.new_resident_addr = bus_resident_address; 2146 + command_args.new_cache_addr = sep->cache_bus; 2147 + command_args.new_resident_addr = sep->resident_bus; 2117 2148 2118 2149 /* set the new shared area */ 2119 2150 command_args.new_shared_area_addr = sep->shared_area_bus; 2120 2151 2121 - edbg("SEP Driver:command_args.new_shared_area is %08lx\n", command_args.new_shared_area_addr); 2122 - edbg("SEP Driver:command_args.new_base_addr is %08lx\n", command_args.new_base_addr); 2123 - edbg("SEP Driver:command_args.new_resident_addr is %08lx\n", command_args.new_resident_addr); 2124 - edbg("SEP Driver:command_args.new_cache_addr is %08lx\n", command_args.new_cache_addr); 2152 + edbg("SEP Driver:command_args.new_shared_area is %08llx\n", command_args.new_shared_area_addr); 2153 + edbg("SEP Driver:command_args.new_base_addr is %08llx\n", command_args.new_base_addr); 2154 + edbg("SEP Driver:command_args.new_resident_addr is %08llx\n", command_args.new_resident_addr); 2155 + edbg("SEP Driver:command_args.new_cache_addr is %08llx\n", command_args.new_cache_addr); 2125 2156 2126 2157 /* return to user */ 2127 - error = copy_to_user((void *) arg, (void *) &command_args, sizeof(struct sep_driver_realloc_cache_resident_t)); 2128 - end_function: 2129 - return error; 2158 + if (copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_realloc_cache_resident_t))) 2159 + return -EFAULT; 2160 + return 0; 2130 2161 } 2131 2162 2132 2163 /* ··· 2528 2573 2529 2574 /* set up system base address and shared memory location */ 2530 2575 2531 - sep->rar_addr = kmalloc(2 * SEP_RAR_IO_MEM_REGION_SIZE, GFP_KERNEL); 2576 + sep->rar_addr = dma_alloc_coherent(&sep->pdev->dev, 2577 + 2 * SEP_RAR_IO_MEM_REGION_SIZE, 2578 + &sep->rar_bus, GFP_KERNEL); 2532 2579 2533 2580 if (!sep->rar_addr) { 2534 - edbg("SEP Driver:cant kmalloc rar\n"); 2581 + edbg("SEP Driver:can't allocate rar\n"); 2535 2582 goto end_function_uniomap; 2536 2583 } 2537 - /* FIXME */ 2538 - sep->rar_bus = __pa(sep->rar_addr); 2539 2584 2540 2585 edbg("SEP Driver:rar_bus is %08llx\n", (unsigned long long)sep->rar_bus); 2541 2586 edbg("SEP Driver:rar_virtual is %p\n", sep->rar_addr); ··· 2563 2608 sep_write_reg(sep, HW_HOST_IMR_REG_ADDR, (~(0x1 << 13))); 2564 2609 2565 2610 end_function_free_res: 2566 - kfree(sep->rar_addr); 2611 + dma_free_coherent(&sep->pdev->dev, 2 * SEP_RAR_IO_MEM_REGION_SIZE, 2612 + sep->rar_addr, sep->rar_bus); 2567 2613 #endif /* SEP_DRIVER_POLLING_MODE */ 2568 2614 end_function_uniomap: 2569 2615 iounmap(sep->io_addr);
+4 -22
drivers/staging/sep/sep_driver_api.h
··· 116 116 realloc cache resident command 117 117 */ 118 118 struct sep_driver_realloc_cache_resident_t { 119 - /* base address */ 120 - unsigned long base_addr; 121 - 122 - /* current cache address */ 123 - unsigned long cache_addr; 124 - 125 - /* cache size in bytes */ 126 - unsigned long cache_size_in_bytes; 127 - 128 - /* current resident address */ 129 - unsigned long resident_addr; 130 - 131 - /* resident size in bytes */ 132 - unsigned long resident_size_in_bytes; 133 - 134 119 /* new cache address */ 135 - unsigned long new_cache_addr; 136 - 120 + u64 new_cache_addr; 137 121 /* new resident address */ 138 - unsigned long new_resident_addr; 139 - 122 + u64 new_resident_addr; 140 123 /* new resident address */ 141 - unsigned long new_shared_area_addr; 142 - 124 + u64 new_shared_area_addr; 143 125 /* new base address */ 144 - unsigned long new_base_addr; 126 + u64 new_base_addr; 145 127 }; 146 128 147 129 struct sep_driver_alloc_t {