Lines Matching refs:nvm
38 int (*read_version)(struct tb_nvm *nvm);
39 int (*validate)(struct tb_nvm *nvm);
40 int (*write_headers)(struct tb_nvm *nvm);
56 static int intel_switch_nvm_version(struct tb_nvm *nvm) in intel_switch_nvm_version() argument
58 struct tb_switch *sw = tb_to_switch(nvm->dev); in intel_switch_nvm_version()
82 nvm->major = (val >> 16) & 0xff; in intel_switch_nvm_version()
83 nvm->minor = (val >> 8) & 0xff; in intel_switch_nvm_version()
84 nvm->active_size = nvm_size; in intel_switch_nvm_version()
89 static int intel_switch_nvm_validate(struct tb_nvm *nvm) in intel_switch_nvm_validate() argument
91 struct tb_switch *sw = tb_to_switch(nvm->dev); in intel_switch_nvm_validate()
94 u8 *buf = nvm->buf; in intel_switch_nvm_validate()
96 image_size = nvm->buf_data_size; in intel_switch_nvm_validate()
130 nvm->buf_data_start = buf + hdr_size; in intel_switch_nvm_validate()
131 nvm->buf_data_size = image_size - hdr_size; in intel_switch_nvm_validate()
136 static int intel_switch_nvm_write_headers(struct tb_nvm *nvm) in intel_switch_nvm_write_headers() argument
138 struct tb_switch *sw = tb_to_switch(nvm->dev); in intel_switch_nvm_write_headers()
145 DMA_PORT_CSS_ADDRESS, nvm->buf + INTEL_NVM_CSS, in intel_switch_nvm_write_headers()
160 static int asmedia_switch_nvm_version(struct tb_nvm *nvm) in asmedia_switch_nvm_version() argument
162 struct tb_switch *sw = tb_to_switch(nvm->dev); in asmedia_switch_nvm_version()
170 nvm->major = (val << 16) & 0xff0000; in asmedia_switch_nvm_version()
171 nvm->major |= val & 0x00ff00; in asmedia_switch_nvm_version()
172 nvm->major |= (val >> 16) & 0x0000ff; in asmedia_switch_nvm_version()
178 nvm->minor = (val << 16) & 0xff0000; in asmedia_switch_nvm_version()
179 nvm->minor |= val & 0x00ff00; in asmedia_switch_nvm_version()
180 nvm->minor |= (val >> 16) & 0x0000ff; in asmedia_switch_nvm_version()
183 nvm->active_size = SZ_512K; in asmedia_switch_nvm_version()
199 static int intel_retimer_nvm_version(struct tb_nvm *nvm) in intel_retimer_nvm_version() argument
201 struct tb_retimer *rt = tb_to_retimer(nvm->dev); in intel_retimer_nvm_version()
209 nvm->major = (val >> 16) & 0xff; in intel_retimer_nvm_version()
210 nvm->minor = (val >> 8) & 0xff; in intel_retimer_nvm_version()
218 nvm->active_size = nvm_size; in intel_retimer_nvm_version()
223 static int intel_retimer_nvm_validate(struct tb_nvm *nvm) in intel_retimer_nvm_validate() argument
225 struct tb_retimer *rt = tb_to_retimer(nvm->dev); in intel_retimer_nvm_validate()
227 u8 *buf = nvm->buf; in intel_retimer_nvm_validate()
230 image_size = nvm->buf_data_size; in intel_retimer_nvm_validate()
261 nvm->buf_data_start = buf + hdr_size; in intel_retimer_nvm_validate()
262 nvm->buf_data_size = image_size - hdr_size; in intel_retimer_nvm_validate()
288 struct tb_nvm *nvm; in tb_nvm_alloc() local
329 nvm = kzalloc(sizeof(*nvm), GFP_KERNEL); in tb_nvm_alloc()
330 if (!nvm) in tb_nvm_alloc()
335 kfree(nvm); in tb_nvm_alloc()
339 nvm->id = ret; in tb_nvm_alloc()
340 nvm->dev = dev; in tb_nvm_alloc()
341 nvm->vops = vops; in tb_nvm_alloc()
343 return nvm; in tb_nvm_alloc()
354 int tb_nvm_read_version(struct tb_nvm *nvm) in tb_nvm_read_version() argument
356 const struct tb_nvm_vendor_ops *vops = nvm->vops; in tb_nvm_read_version()
359 return vops->read_version(nvm); in tb_nvm_read_version()
375 int tb_nvm_validate(struct tb_nvm *nvm) in tb_nvm_validate() argument
377 const struct tb_nvm_vendor_ops *vops = nvm->vops; in tb_nvm_validate()
379 u8 *buf = nvm->buf; in tb_nvm_validate()
387 image_size = nvm->buf_data_size; in tb_nvm_validate()
395 nvm->buf_data_start = buf; in tb_nvm_validate()
397 return vops->validate ? vops->validate(nvm) : 0; in tb_nvm_validate()
410 int tb_nvm_write_headers(struct tb_nvm *nvm) in tb_nvm_write_headers() argument
412 const struct tb_nvm_vendor_ops *vops = nvm->vops; in tb_nvm_write_headers()
414 return vops->write_headers ? vops->write_headers(nvm) : 0; in tb_nvm_write_headers()
428 int tb_nvm_add_active(struct tb_nvm *nvm, nvmem_reg_read_t reg_read) in tb_nvm_add_active() argument
438 config.id = nvm->id; in tb_nvm_add_active()
441 config.size = nvm->active_size; in tb_nvm_add_active()
442 config.dev = nvm->dev; in tb_nvm_add_active()
444 config.priv = nvm; in tb_nvm_add_active()
450 nvm->active = nvmem; in tb_nvm_add_active()
465 int tb_nvm_write_buf(struct tb_nvm *nvm, unsigned int offset, void *val, in tb_nvm_write_buf() argument
468 if (!nvm->buf) { in tb_nvm_write_buf()
469 nvm->buf = vmalloc(NVM_MAX_SIZE); in tb_nvm_write_buf()
470 if (!nvm->buf) in tb_nvm_write_buf()
474 nvm->flushed = false; in tb_nvm_write_buf()
475 nvm->buf_data_size = offset + bytes; in tb_nvm_write_buf()
476 memcpy(nvm->buf + offset, val, bytes); in tb_nvm_write_buf()
493 int tb_nvm_add_non_active(struct tb_nvm *nvm, nvmem_reg_write_t reg_write) in tb_nvm_add_non_active() argument
503 config.id = nvm->id; in tb_nvm_add_non_active()
507 config.dev = nvm->dev; in tb_nvm_add_non_active()
509 config.priv = nvm; in tb_nvm_add_non_active()
515 nvm->non_active = nvmem; in tb_nvm_add_non_active()
525 void tb_nvm_free(struct tb_nvm *nvm) in tb_nvm_free() argument
527 if (nvm) { in tb_nvm_free()
528 nvmem_unregister(nvm->non_active); in tb_nvm_free()
529 nvmem_unregister(nvm->active); in tb_nvm_free()
530 vfree(nvm->buf); in tb_nvm_free()
531 ida_free(&nvm_ida, nvm->id); in tb_nvm_free()
533 kfree(nvm); in tb_nvm_free()