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

Configure Feed

Select the types of activity you want to include in your feed.

drm/display: dp: implement new access helpers

Existing DPCD access functions return an error code or the number of
bytes being read / write in case of partial access. However a lot of
drivers either (incorrectly) ignore partial access or mishandle error
codes. In other cases this results in a boilerplate code which compares
returned value with the size.

Implement new set of DPCD access helpers, which ignore partial access,
always return 0 or an error code.

Suggested-by: Jani Nikula <jani.nikula@linux.intel.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20250324-drm-rework-dpcd-access-v4-1-e80ff89593df@oss.qualcomm.com
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>

authored by

Dmitry Baryshkov and committed by
Dmitry Baryshkov
d8343e11 1bb2864b

+94 -2
+4
drivers/gpu/drm/display/drm_dp_helper.c
··· 704 704 * function returns -EPROTO. Errors from the underlying AUX channel transfer 705 705 * function, with the exception of -EBUSY (which causes the transaction to 706 706 * be retried), are propagated to the caller. 707 + * 708 + * In most of the cases you want to use drm_dp_dpcd_read_data() instead. 707 709 */ 708 710 ssize_t drm_dp_dpcd_read(struct drm_dp_aux *aux, unsigned int offset, 709 711 void *buffer, size_t size) ··· 754 752 * function returns -EPROTO. Errors from the underlying AUX channel transfer 755 753 * function, with the exception of -EBUSY (which causes the transaction to 756 754 * be retried), are propagated to the caller. 755 + * 756 + * In most of the cases you want to use drm_dp_dpcd_write_data() instead. 757 757 */ 758 758 ssize_t drm_dp_dpcd_write(struct drm_dp_aux *aux, unsigned int offset, 759 759 void *buffer, size_t size)
+90 -2
include/drm/display/drm_dp_helper.h
··· 528 528 void *buffer, size_t size); 529 529 530 530 /** 531 + * drm_dp_dpcd_read_data() - read a series of bytes from the DPCD 532 + * @aux: DisplayPort AUX channel (SST or MST) 533 + * @offset: address of the (first) register to read 534 + * @buffer: buffer to store the register values 535 + * @size: number of bytes in @buffer 536 + * 537 + * Returns zero (0) on success, or a negative error 538 + * code on failure. -EIO is returned if the request was NAKed by the sink or 539 + * if the retry count was exceeded. If not all bytes were transferred, this 540 + * function returns -EPROTO. Errors from the underlying AUX channel transfer 541 + * function, with the exception of -EBUSY (which causes the transaction to 542 + * be retried), are propagated to the caller. 543 + */ 544 + static inline int drm_dp_dpcd_read_data(struct drm_dp_aux *aux, 545 + unsigned int offset, 546 + void *buffer, size_t size) 547 + { 548 + int ret; 549 + 550 + ret = drm_dp_dpcd_read(aux, offset, buffer, size); 551 + if (ret < 0) 552 + return ret; 553 + if (ret < size) 554 + return -EPROTO; 555 + 556 + return 0; 557 + } 558 + 559 + /** 560 + * drm_dp_dpcd_write_data() - write a series of bytes to the DPCD 561 + * @aux: DisplayPort AUX channel (SST or MST) 562 + * @offset: address of the (first) register to write 563 + * @buffer: buffer containing the values to write 564 + * @size: number of bytes in @buffer 565 + * 566 + * Returns zero (0) on success, or a negative error 567 + * code on failure. -EIO is returned if the request was NAKed by the sink or 568 + * if the retry count was exceeded. If not all bytes were transferred, this 569 + * function returns -EPROTO. Errors from the underlying AUX channel transfer 570 + * function, with the exception of -EBUSY (which causes the transaction to 571 + * be retried), are propagated to the caller. 572 + */ 573 + static inline int drm_dp_dpcd_write_data(struct drm_dp_aux *aux, 574 + unsigned int offset, 575 + void *buffer, size_t size) 576 + { 577 + int ret; 578 + 579 + ret = drm_dp_dpcd_write(aux, offset, buffer, size); 580 + if (ret < 0) 581 + return ret; 582 + if (ret < size) 583 + return -EPROTO; 584 + 585 + return 0; 586 + } 587 + 588 + /** 531 589 * drm_dp_dpcd_readb() - read a single byte from the DPCD 532 590 * @aux: DisplayPort AUX channel 533 591 * @offset: address of the register to read 534 592 * @valuep: location where the value of the register will be stored 535 593 * 536 594 * Returns the number of bytes transferred (1) on success, or a negative 537 - * error code on failure. 595 + * error code on failure. In most of the cases you should be using 596 + * drm_dp_dpcd_read_byte() instead. 538 597 */ 539 598 static inline ssize_t drm_dp_dpcd_readb(struct drm_dp_aux *aux, 540 599 unsigned int offset, u8 *valuep) ··· 608 549 * @value: value to write to the register 609 550 * 610 551 * Returns the number of bytes transferred (1) on success, or a negative 611 - * error code on failure. 552 + * error code on failure. In most of the cases you should be using 553 + * drm_dp_dpcd_write_byte() instead. 612 554 */ 613 555 static inline ssize_t drm_dp_dpcd_writeb(struct drm_dp_aux *aux, 614 556 unsigned int offset, u8 value) 615 557 { 616 558 return drm_dp_dpcd_write(aux, offset, &value, 1); 559 + } 560 + 561 + /** 562 + * drm_dp_dpcd_read_byte() - read a single byte from the DPCD 563 + * @aux: DisplayPort AUX channel 564 + * @offset: address of the register to read 565 + * @valuep: location where the value of the register will be stored 566 + * 567 + * Returns zero (0) on success, or a negative error code on failure. 568 + */ 569 + static inline int drm_dp_dpcd_read_byte(struct drm_dp_aux *aux, 570 + unsigned int offset, u8 *valuep) 571 + { 572 + return drm_dp_dpcd_read_data(aux, offset, valuep, 1); 573 + } 574 + 575 + /** 576 + * drm_dp_dpcd_write_byte() - write a single byte to the DPCD 577 + * @aux: DisplayPort AUX channel 578 + * @offset: address of the register to write 579 + * @value: value to write to the register 580 + * 581 + * Returns zero (0) on success, or a negative error code on failure. 582 + */ 583 + static inline int drm_dp_dpcd_write_byte(struct drm_dp_aux *aux, 584 + unsigned int offset, u8 value) 585 + { 586 + return drm_dp_dpcd_write_data(aux, offset, &value, 1); 617 587 } 618 588 619 589 int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux,