Commit eb96b740 authored by Nipun Gupta's avatar Nipun Gupta Committed by Greg Kroah-Hartman
Browse files

cdx: add MCDI protocol interface for firmware interaction



The MCDI (Management CPU Driver Interface) is used as a
protocol to communicate with the RPU firmware. It has
pre-defined set of messages for different message exchanges
between APU and RPU.

Signed-off-by: default avatarPuneet Gupta <puneet.gupta@amd.com>
Signed-off-by: default avatarNipun Gupta <nipun.gupta@amd.com>
Signed-off-by: default avatarTarak Reddy <tarak.reddy@amd.com>
Reviewed-by: default avatarPieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com>
Tested-by: default avatarNikhil Agarwal <nikhil.agarwal@amd.com>
Link: https://lore.kernel.org/r/20230313132636.31850-5-nipun.gupta@amd.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c47a88e1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,3 +15,5 @@ config CDX_BUS
	  of CDX devices. CDX devices are memory mapped on system bus
	  for embedded CPUs. CDX bus uses CDX controller and firmware
	  to scan these CDX devices.

source "drivers/cdx/controller/Kconfig"
+1 −1
Original line number Diff line number Diff line
@@ -5,4 +5,4 @@
# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
#

obj-$(CONFIG_CDX_BUS) += cdx.o
obj-$(CONFIG_CDX_BUS) += cdx.o controller/
+20 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only
#
# CDX controller configuration
#
# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
#

if CDX_BUS

config MCDI_LOGGING
	bool "MCDI Logging for the CDX controller"
	depends on CDX_CONTROLLER
	help
	  Enable MCDI Logging for
	  the CDX Controller for debug
	  purpose.

	  If unsure, say N.

endif
+9 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only
#
# Makefile for CDX controller drivers
#
# Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
#

obj-$(CONFIG_CDX_CONTROLLER) += cdx-controller.o
cdx-controller-objs := mcdi.o
+90 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0
 *
 * Copyright 2005-2006 Fen Systems Ltd.
 * Copyright 2006-2013 Solarflare Communications Inc.
 * Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
 */

#ifndef CDX_BITFIELD_H
#define CDX_BITFIELD_H

#include <linux/bitfield.h>

/* Lowest bit numbers and widths */
#define CDX_DWORD_LBN 0
#define CDX_DWORD_WIDTH 32

/* Specified attribute (e.g. LBN) of the specified field */
#define CDX_VAL(field, attribute) field ## _ ## attribute
/* Low bit number of the specified field */
#define CDX_LOW_BIT(field) CDX_VAL(field, LBN)
/* Bit width of the specified field */
#define CDX_WIDTH(field) CDX_VAL(field, WIDTH)
/* High bit number of the specified field */
#define CDX_HIGH_BIT(field) (CDX_LOW_BIT(field) + CDX_WIDTH(field) - 1)

/* A doubleword (i.e. 4 byte) datatype - little-endian in HW */
struct cdx_dword {
	__le32 cdx_u32;
};

/* Value expanders for printk */
#define CDX_DWORD_VAL(dword)				\
	((unsigned int)le32_to_cpu((dword).cdx_u32))

/*
 * Extract bit field portion [low,high) from the 32-bit little-endian
 * element which contains bits [min,max)
 */
#define CDX_DWORD_FIELD(dword, field)					\
	(FIELD_GET(GENMASK(CDX_HIGH_BIT(field), CDX_LOW_BIT(field)),	\
		   le32_to_cpu((dword).cdx_u32)))

/*
 * Creates the portion of the named bit field that lies within the
 * range [min,max).
 */
#define CDX_INSERT_FIELD(field, value)				\
	(FIELD_PREP(GENMASK(CDX_HIGH_BIT(field),		\
			    CDX_LOW_BIT(field)), value))

/*
 * Creates the portion of the named bit fields that lie within the
 * range [min,max).
 */
#define CDX_INSERT_FIELDS(field1, value1,		\
			  field2, value2,		\
			  field3, value3,		\
			  field4, value4,		\
			  field5, value5,		\
			  field6, value6,		\
			  field7, value7)		\
	(CDX_INSERT_FIELD(field1, (value1)) |		\
	 CDX_INSERT_FIELD(field2, (value2)) |		\
	 CDX_INSERT_FIELD(field3, (value3)) |		\
	 CDX_INSERT_FIELD(field4, (value4)) |		\
	 CDX_INSERT_FIELD(field5, (value5)) |		\
	 CDX_INSERT_FIELD(field6, (value6)) |		\
	 CDX_INSERT_FIELD(field7, (value7)))

#define CDX_POPULATE_DWORD(dword, ...)					\
	(dword).cdx_u32 = cpu_to_le32(CDX_INSERT_FIELDS(__VA_ARGS__))

/* Populate a dword field with various numbers of arguments */
#define CDX_POPULATE_DWORD_7 CDX_POPULATE_DWORD
#define CDX_POPULATE_DWORD_6(dword, ...) \
	CDX_POPULATE_DWORD_7(dword, CDX_DWORD, 0, __VA_ARGS__)
#define CDX_POPULATE_DWORD_5(dword, ...) \
	CDX_POPULATE_DWORD_6(dword, CDX_DWORD, 0, __VA_ARGS__)
#define CDX_POPULATE_DWORD_4(dword, ...) \
	CDX_POPULATE_DWORD_5(dword, CDX_DWORD, 0, __VA_ARGS__)
#define CDX_POPULATE_DWORD_3(dword, ...) \
	CDX_POPULATE_DWORD_4(dword, CDX_DWORD, 0, __VA_ARGS__)
#define CDX_POPULATE_DWORD_2(dword, ...) \
	CDX_POPULATE_DWORD_3(dword, CDX_DWORD, 0, __VA_ARGS__)
#define CDX_POPULATE_DWORD_1(dword, ...) \
	CDX_POPULATE_DWORD_2(dword, CDX_DWORD, 0, __VA_ARGS__)
#define CDX_SET_DWORD(dword) \
	CDX_POPULATE_DWORD_1(dword, CDX_DWORD, 0xffffffff)

#endif /* CDX_BITFIELD_H */
Loading