Skip to content

Commit

Permalink
habanalabs: add debugfs support
Browse files Browse the repository at this point in the history
This patch adds debugfs support to the driver. It allows the user-space to
display information that is contained in the internal structures of the
driver, such as:
- active command submissions
- active user virtual memory mappings
- number of allocated command buffers

It also enables the user to perform reads and writes through Goya's PCI
bars.

Reviewed-by: Mike Rapoport <[email protected]>
Signed-off-by: Oded Gabbay <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ogabbay authored and gregkh committed Feb 18, 2019
1 parent d8dd7b0 commit c216477
Show file tree
Hide file tree
Showing 11 changed files with 1,546 additions and 2 deletions.
126 changes: 126 additions & 0 deletions Documentation/ABI/testing/debugfs-driver-habanalabs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
What: /sys/kernel/debug/habanalabs/hl<n>/addr
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Sets the device address to be used for read or write through
PCI bar. The acceptable value is a string that starts with "0x"

What: /sys/kernel/debug/habanalabs/hl<n>/command_buffers
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Displays a list with information about the currently allocated
command buffers

What: /sys/kernel/debug/habanalabs/hl<n>/command_submission
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Displays a list with information about the currently active
command submissions

What: /sys/kernel/debug/habanalabs/hl<n>/command_submission_jobs
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Displays a list with detailed information about each JOB (CB) of
each active command submission

What: /sys/kernel/debug/habanalabs/hl<n>/data32
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Allows the root user to read or write directly through the
device's PCI bar. Writing to this file generates a write
transaction while reading from the file generates a read
transcation. This custom interface is needed (instead of using
the generic Linux user-space PCI mapping) because the DDR bar
is very small compared to the DDR memory and only the driver can
move the bar before and after the transaction

What: /sys/kernel/debug/habanalabs/hl<n>/device
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Enables the root user to set the device to specific state.
Valid values are "disable", "enable", "suspend", "resume".
User can read this property to see the valid values

What: /sys/kernel/debug/habanalabs/hl<n>/i2c_addr
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Sets I2C device address for I2C transaction that is generated
by the device's CPU

What: /sys/kernel/debug/habanalabs/hl<n>/i2c_bus
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Sets I2C bus address for I2C transaction that is generated by
the device's CPU

What: /sys/kernel/debug/habanalabs/hl<n>/i2c_data
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Triggers an I2C transaction that is generated by the device's
CPU. Writing to this file generates a write transaction while
reading from the file generates a read transcation

What: /sys/kernel/debug/habanalabs/hl<n>/i2c_reg
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Sets I2C register id for I2C transaction that is generated by
the device's CPU

What: /sys/kernel/debug/habanalabs/hl<n>/led0
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Sets the state of the first S/W led on the device

What: /sys/kernel/debug/habanalabs/hl<n>/led1
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Sets the state of the second S/W led on the device

What: /sys/kernel/debug/habanalabs/hl<n>/led2
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Sets the state of the third S/W led on the device

What: /sys/kernel/debug/habanalabs/hl<n>/mmu
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Displays the hop values and physical address for a given ASID
and virtual address. The user should write the ASID and VA into
the file and then read the file to get the result.
e.g. to display info about VA 0x1000 for ASID 1 you need to do:
echo "1 0x1000" > /sys/kernel/debug/habanalabs/hl0/mmu

What: /sys/kernel/debug/habanalabs/hl<n>/set_power_state
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Sets the PCI power state. Valid values are "1" for D0 and "2"
for D3Hot

What: /sys/kernel/debug/habanalabs/hl<n>/userptr
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Displays a list with information about the currently user
pointers (user virtual addresses) that are pinned and mapped
to DMA addresses

What: /sys/kernel/debug/habanalabs/hl<n>/vm
Date: Jan 2019
KernelVersion: 5.1
Contact: [email protected]
Description: Displays a list with information about all the active virtual
address mappings per ASID
2 changes: 2 additions & 0 deletions drivers/misc/habanalabs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \
command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o memory.o \
command_submission.o mmu.o

habanalabs-$(CONFIG_DEBUG_FS) += debugfs.o

include $(src)/goya/Makefile
habanalabs-y += $(HL_GOYA_FILES)
4 changes: 4 additions & 0 deletions drivers/misc/habanalabs/command_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static void cb_release(struct kref *ref)
cb = container_of(ref, struct hl_cb, refcount);
hdev = cb->hdev;

hl_debugfs_remove_cb(cb);

cb_do_release(hdev, cb);
}

Expand Down Expand Up @@ -163,6 +165,8 @@ int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr,
*handle = cb->id | HL_MMAP_CB_MASK;
*handle <<= PAGE_SHIFT;

hl_debugfs_add_cb(cb);

return 0;

release_cb:
Expand Down
12 changes: 12 additions & 0 deletions drivers/misc/habanalabs/command_submission.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ static void free_job(struct hl_device *hdev, struct hl_cs_job *job)
list_del(&job->cs_node);
spin_unlock(&cs->job_lock);

hl_debugfs_remove_job(hdev, job);

if (job->ext_queue)
cs_put(cs);

Expand Down Expand Up @@ -212,6 +214,12 @@ static void cs_do_release(struct kref *ref)
}
}

/*
* Must be called before hl_ctx_put because inside we use ctx to get
* the device
*/
hl_debugfs_remove_cs(cs);

hl_ctx_put(cs->ctx);

if (cs->timedout)
Expand Down Expand Up @@ -480,6 +488,8 @@ static int _hl_cs_ioctl(struct hl_fpriv *hpriv, void __user *chunks,

*cs_seq = cs->sequence;

hl_debugfs_add_cs(cs);

/* Validate ALL the CS chunks before submitting the CS */
for (i = 0, parse_cnt = 0 ; i < num_chunks ; i++, parse_cnt++) {
struct hl_cs_chunk *chunk = &cs_chunk_array[i];
Expand Down Expand Up @@ -528,6 +538,8 @@ static int _hl_cs_ioctl(struct hl_fpriv *hpriv, void __user *chunks,
if (job->ext_queue)
cs_get(cs);

hl_debugfs_add_job(hdev, job);

rc = cs_parser(hpriv, job);
if (rc) {
dev_err(hdev->dev,
Expand Down
Loading

0 comments on commit c216477

Please sign in to comment.