devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch v21 0/4] JTAG driver introduction
@ 2018-05-15 14:21 Oleksandr Shamray
  2018-05-15 14:21 ` [patch v21 1/4] drivers: jtag: Add JTAG core driver Oleksandr Shamray
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Oleksandr Shamray @ 2018-05-15 14:21 UTC (permalink / raw)
  To: gregkh, arnd
  Cc: linux-kernel, linux-arm-kernel, devicetree, openbmc, joel, jiri,
	tklauser, linux-serial, vadimp, system-sw-low-level, robh+dt,
	openocd-devel-owner, linux-api, davem, mchehab,
	Oleksandr Shamray

When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
    driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
    families     JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev                 |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt       |   22 +
 Documentation/ioctl/ioctl-number.txt               |    2 +
 Documentation/jtag/overview                        |   28 +
 Documentation/jtag/transactions                    |  109 +++
 MAINTAINERS                                        |   10 +
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    1 +
 drivers/jtag/Kconfig                               |   32 +
 drivers/jtag/Makefile                              |    2 +
 drivers/jtag/jtag-aspeed.c                         |  786 ++++++++++++++++++++
 drivers/jtag/jtag.c                                |  274 +++++++
 include/linux/jtag.h                               |   41 +
 include/uapi/linux/jtag.h                          |  105 +++
 14 files changed, 1441 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h

^ permalink raw reply	[flat|nested] 12+ messages in thread
* RE: [patch v21 1/4] drivers: jtag: Add JTAG core driver
@ 2018-05-22 13:08 Oleksandr Shamray
  0 siblings, 0 replies; 12+ messages in thread
From: Oleksandr Shamray @ 2018-05-22 13:08 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Greg Kroah-Hartman, Arnd Bergmann, Linux Kernel Mailing List,
	linux-arm Mailing List, devicetree, openbmc, Joel Stanley,
	Jiří Pírko, Tobias Klauser,
	open list:SERIAL DRIVERS, Vadim Pasternak, system-sw-low-level,
	Rob Herring, openocd-devel-owner, linux-api, David S. Miller

[-- Attachment #1: Type: text/plain, Size: 7740 bytes --]

Hi Andy.

Thanks for review.



Please read my answers inline.



> -----Original Message-----

> From: Andy Shevchenko [mailto:andy.shevchenko@gmail.com]

> Sent: 16 мая 2018 г. 0:22

> To: Oleksandr Shamray <oleksandrs@mellanox.com<mailto:oleksandrs@mellanox.com>>

> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org<mailto:gregkh@linuxfoundation.org>>; Arnd Bergmann

> <arnd@arndb.de<mailto:arnd@arndb.de>>; Linux Kernel Mailing List

> <linux-kernel@vger.kernel.org<mailto:linux-kernel@vger.kernel.org>>; linux-arm Mailing List

> <linux-arm-kernel@lists.infradead.org<mailto:linux-arm-kernel@lists.infradead.org>>; devicetree

> <devicetree@vger.kernel.org<mailto:devicetree@vger.kernel.org>>; openbmc@lists.ozlabs.org<mailto:openbmc@lists.ozlabs.org>; Joel Stanley

> <joel@jms.id.au<mailto:joel@jms.id.au>>; Jiří Pírko <jiri@resnulli.us<mailto:jiri@resnulli.us>>; Tobias Klauser

> <tklauser@distanz.ch<mailto:tklauser@distanz.ch>>; open list:SERIAL DRIVERS <linux-

> serial@vger.kernel.org<mailto:serial@vger.kernel.org>>; Vadim Pasternak <vadimp@mellanox.com<mailto:vadimp@mellanox.com>>;

> system-sw-low-level <system-sw-low-level@mellanox.com<mailto:system-sw-low-level@mellanox.com>>; Rob Herring

> <robh+dt@kernel.org<mailto:robh+dt@kernel.org>>; openocd-devel-owner@lists.sourceforge.net<mailto:openocd-devel-owner@lists.sourceforge.net>;

> linux- api@vger.kernel.org<mailto:api@vger.kernel.org>; David S. Miller <davem@davemloft.net<mailto:davem@davemloft.net>>;

> Mauro Carvalho Chehab <mchehab@kernel.org<mailto:mchehab@kernel.org>>; Jiri Pirko

> <jiri@mellanox.com<mailto:jiri@mellanox.com>>

> Subject: Re: [patch v21 1/4] drivers: jtag: Add JTAG core driver

>

> On Tue, May 15, 2018 at 5:21 PM, Oleksandr Shamray

> <oleksandrs@mellanox.com<mailto:oleksandrs@mellanox.com>> wrote:

> > Initial patch for JTAG driver

> > JTAG class driver provide infrastructure to support

> > hardware/software JTAG platform drivers. It provide user layer API

> > interface for flashing and debugging external devices which equipped

> > with JTAG interface using standard transactions.

> >

> > Driver exposes set of IOCTL to user space for:

> > - XFER:

> > - SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);

> > - SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);

> > - RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified

> >   number of clocks).

> > - SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

> >

> > Driver core provides set of internal APIs for allocation and

> > registration:

> > - jtag_register;

> > - jtag_unregister;

> > - jtag_alloc;

> > - jtag_free;

> >

> > Platform driver on registration with jtag-core creates the next

> > entry in dev folder:

> > /dev/jtagX

>

> >  0xB0   all     RATIO devices           in development:

> >                                         <mailto:vgo@ratio.de>

> >  0xB1   00-1F   PPPoX                   <mailto:mostrows@styx.uwaterloo.ca>

> > +0xB2   00-0f   linux/jtag.h            JTAG driver

> > +

> > +<mailto:oleksandrs@mellanox.com>

>

> Consider to preserve style (upper vs. lower).



JTAG in code is lower (jtag) cane but in descriptions and notes it  is upper (JTAG).

In all places which do not correspond to this I will fix.



>

> > +         This provides basic core functionality support for JTAG class devices.

> > +         Hardware that is equipped with a JTAG microcontroller can be

> > +         supported by using this driver's interfaces.

> > +         This driver exposes a set of IOCTLs to the user space for

> > +         the following commands:

> > +         SDR: (Scan Data Register) Performs an IEEE 1149.1 Data Register scan

> > +         SIR: (Scan Instruction Register) Performs an IEEE 1149.1 Instruction

> > +         Register scan.

> > +         RUNTEST: Forces the IEEE 1149.1 bus to a run state for a specified

> > +         number of clocks or a specified time period.

>

> Something feels wrong with formatting here.

>



Will fix



> > +#define MAX_JTAG_NAME_LEN (sizeof("jtag") + 5)

>

> Interesting definition. Why not to set to 10 explicitly? And why 10?

> (16 sounds better)

>

5 - is a max len of JTAG device id in device name. I will add define to it.



In general I don't see the case for the system with hundreds JTAG interfaces.

I will limit maximum jtag master to 255 devices and change  id len to 3



#define MAX_JTAG_ID_STR_LEN 5

#define MAX_JTAG_NAME_LEN (sizeof("jtag") + MAX_JTAG_ID_STR_LEN)



> > +struct jtag {

> > +       struct miscdevice miscdev;

>

> > +       struct device *dev;

>

> Doesn't miscdev parent contain exactly this one?



Yes.

Will fix.



>

> > +       const struct jtag_ops *ops;

> > +       int id;

> > +       bool opened;

> > +       struct mutex open_lock;

> > +       unsigned long priv[0];

> > +};

>

> > +               err = copy_to_user(u64_to_user_ptr(xfer.tdio),

> > +                                  (void *)(xfer_data), data_size);

>

> Redundant parens in one case. Check the rest similar places.

>



Yes.



> > +static int jtag_open(struct inode *inode, struct file *file) {

>

> > +       struct jtag *jtag = container_of(file->private_data, struct jtag,

> > +                                        miscdev);

>

> I would don't care about length and put it on one line.

>



But following to LINUX kernel style, it should be no longer than 80 symbols.

It will not pass by  ./scripts/checkpatch.pl



Will it be OK to send a patch which failed 80 symbols limitation check?



> > +       if (jtag->opened) {

> > +       jtag->opened = true;

> > +       jtag->opened = false;

>

> Can it be opened non exclusively several times? If so, this needs to

> be a ref counter instead.



It can be opened only once.



>

> > +       if (!ops->idle || !ops->mode_set || !ops->status_get || !ops->xfer)

> > +               return NULL;

>

> Are all of them mandatory?

>



Yes, except "mode_set"

Will remove mode_set from check



> > +int jtag_register(struct jtag *jtag)

>

> Perhaps devm_ variant.



Jtag driver uses miscdevice and related  misc_register and misc_deregister calls for creation and destruction. There is no device object prior to call to  misc_register, which could be used in devm_jtag_register.



>

> > +#define jtag_u64_to_ptr(arg) ((void *)(uintptr_t)arg)

>



Redundant. Removed.



> Where is this used or supposed to be used?

>

> > +#define JTAG_MAX_XFER_DATA_LEN 65535

>

> Is this limitation from some spec?

> Otherwise why not to allow 64K?

>



It not limited by specification.

But we enforce an upper bound for the length here, to prevent users from draining kernel memory with giant buffers.



> > +/**

> > + * struct jtag_ops - callbacks for jtag control functions:

> > + *

> > + * @freq_get: get frequency function. Filled by device driver

> > + * @freq_set: set frequency function. Filled by device driver

> > + * @status_get: set status function. Filled by device driver

> > + * @idle: set JTAG to idle state function. Filled by device driver

> > + * @xfer: send JTAG xfer function. Filled by device driver  */

>

> Perhaps you need to describe which of them are _really_ mandatory and

> which are optional.

>



Ok



> --

> With Best Regards,

> Andy Shevchenko


Best Regards,

Oleksandr Shamray


[-- Attachment #2: Type: text/html, Size: 25872 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-05-22 20:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-15 14:21 [patch v21 0/4] JTAG driver introduction Oleksandr Shamray
2018-05-15 14:21 ` [patch v21 1/4] drivers: jtag: Add JTAG core driver Oleksandr Shamray
2018-05-15 21:21   ` Andy Shevchenko
2018-05-22 15:00     ` Oleksandr Shamray
2018-05-15 14:21 ` [patch v21 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver Oleksandr Shamray
2018-05-15 21:00   ` Andy Shevchenko
2018-05-22 15:00     ` Oleksandr Shamray
2018-05-22 20:21       ` Andy Shevchenko
2018-05-15 14:21 ` [patch v21 3/4] Documentation: jtag: Add bindings for " Oleksandr Shamray
2018-05-15 14:21 ` [patch v21 4/4] Documentation: jtag: Add ABI documentation Oleksandr Shamray
2018-05-16 18:16   ` Randy Dunlap
2018-05-22 13:08 [patch v21 1/4] drivers: jtag: Add JTAG core driver Oleksandr Shamray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).