Skip to content

Commit fb528a6

Browse files
toolsmanhehebaiywt
authored andcommitted
RK3588: NPU: Update to 0.9.8 version
1 parent be3b8d0 commit fb528a6

File tree

10 files changed

+921
-139
lines changed

10 files changed

+921
-139
lines changed

drivers/rknpu/include/rknpu_drv.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
#define DRIVER_NAME "rknpu"
3131
#define DRIVER_DESC "RKNPU driver"
32-
#define DRIVER_DATE "20240322"
32+
#define DRIVER_DATE "20240828"
3333
#define DRIVER_MAJOR 0
3434
#define DRIVER_MINOR 9
35-
#define DRIVER_PATCHLEVEL 6
35+
#define DRIVER_PATCHLEVEL 8
3636

3737
#define LOG_TAG "RKNPU"
3838

@@ -54,6 +54,7 @@
5454
#define LOG_DEV_ERROR(dev, fmt, args...) dev_err(dev, LOG_TAG ": " fmt, ##args)
5555

5656
#define RKNPU_MAX_IOMMU_DOMAIN_NUM 16
57+
#define RKNPU_CACHE_SG_TABLE_NUM 2
5758

5859
struct rknpu_irqs_data {
5960
const char *name;
@@ -84,6 +85,8 @@ struct rknpu_config {
8485
__u32 core_mask;
8586
const struct rknpu_amount_data *amount_top;
8687
const struct rknpu_amount_data *amount_core;
88+
void (*state_init)(struct rknpu_device *rknpu_dev);
89+
int (*cache_sgt_init)(struct rknpu_device *rknpu_dev);
8790
};
8891

8992
struct rknpu_timer {
@@ -170,6 +173,8 @@ struct rknpu_device {
170173
int iommu_domain_num;
171174
int iommu_domain_id;
172175
struct iommu_domain *iommu_domains[RKNPU_MAX_IOMMU_DOMAIN_NUM];
176+
struct sg_table *cache_sgt[RKNPU_CACHE_SG_TABLE_NUM];
177+
atomic_t iommu_domain_refcount;
173178
};
174179

175180
struct rknpu_session {
@@ -179,5 +184,6 @@ struct rknpu_session {
179184

180185
int rknpu_power_get(struct rknpu_device *rknpu_dev);
181186
int rknpu_power_put(struct rknpu_device *rknpu_dev);
187+
int rknpu_power_put_delay(struct rknpu_device *rknpu_dev);
182188

183189
#endif /* __LINUX_RKNPU_DRV_H_ */

drivers/rknpu/include/rknpu_gem.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ struct rknpu_gem_object {
6161
struct sg_table *sgt;
6262
struct drm_mm_node mm_node;
6363
int iommu_domain_id;
64+
unsigned int core_mask;
65+
unsigned int cache_with_sgt;
6466
};
6567

6668
enum rknpu_cache_type {
@@ -69,11 +71,10 @@ enum rknpu_cache_type {
6971
};
7072

7173
/* create a new buffer with gem object */
72-
struct rknpu_gem_object *rknpu_gem_object_create(struct drm_device *dev,
73-
unsigned int flags,
74-
unsigned long size,
75-
unsigned long sram_size,
76-
int iommu_domain_id);
74+
struct rknpu_gem_object *
75+
rknpu_gem_object_create(struct drm_device *dev, unsigned int flags,
76+
unsigned long size, unsigned long sram_size,
77+
int iommu_domain_id, unsigned int core_mask);
7778

7879
/* destroy a buffer with gem object */
7980
void rknpu_gem_object_destroy(struct rknpu_gem_object *rknpu_obj);

drivers/rknpu/include/rknpu_ioctl.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939

4040
#define RKNPU_STR_HELPER(x) #x
4141

42-
#define RKNPU_GET_DRV_VERSION_STRING(MAJOR, MINOR, PATCHLEVEL) \
43-
RKNPU_STR_HELPER(MAJOR) \
42+
#define RKNPU_GET_DRV_VERSION_STRING(MAJOR, MINOR, PATCHLEVEL) \
43+
RKNPU_STR_HELPER(MAJOR) \
4444
"." RKNPU_STR_HELPER(MINOR) "." RKNPU_STR_HELPER(PATCHLEVEL)
45-
#define RKNPU_GET_DRV_VERSION_CODE(MAJOR, MINOR, PATCHLEVEL) \
45+
#define RKNPU_GET_DRV_VERSION_CODE(MAJOR, MINOR, PATCHLEVEL) \
4646
(MAJOR * 10000 + MINOR * 100 + PATCHLEVEL)
4747
#define RKNPU_GET_DRV_VERSION_MAJOR(CODE) (CODE / 10000)
4848
#define RKNPU_GET_DRV_VERSION_MINOR(CODE) ((CODE % 10000) / 100)
@@ -62,7 +62,7 @@ enum e_rknpu_mem_type {
6262
RKNPU_MEM_WRITE_COMBINE = 1 << 2,
6363
/* dma attr kernel mapping */
6464
RKNPU_MEM_KERNEL_MAPPING = 1 << 3,
65-
/* iommu mapping */
65+
/* IOMMU mapping */
6666
RKNPU_MEM_IOMMU = 1 << 4,
6767
/* zero mapping */
6868
RKNPU_MEM_ZEROING = 1 << 5,
@@ -74,19 +74,22 @@ enum e_rknpu_mem_type {
7474
RKNPU_MEM_TRY_ALLOC_SRAM = 1 << 8,
7575
/* request NBUF */
7676
RKNPU_MEM_TRY_ALLOC_NBUF = 1 << 9,
77+
/* IOMMU limiting IOVA alignment */
78+
RKNPU_MEM_IOMMU_LIMIT_IOVA_ALIGNMENT = 1 << 10,
7779
RKNPU_MEM_MASK = RKNPU_MEM_NON_CONTIGUOUS | RKNPU_MEM_CACHEABLE |
7880
RKNPU_MEM_WRITE_COMBINE | RKNPU_MEM_KERNEL_MAPPING |
7981
RKNPU_MEM_IOMMU | RKNPU_MEM_ZEROING |
8082
RKNPU_MEM_SECURE | RKNPU_MEM_DMA32 |
81-
RKNPU_MEM_TRY_ALLOC_SRAM | RKNPU_MEM_TRY_ALLOC_NBUF
83+
RKNPU_MEM_TRY_ALLOC_SRAM | RKNPU_MEM_TRY_ALLOC_NBUF |
84+
RKNPU_MEM_IOMMU_LIMIT_IOVA_ALIGNMENT
8285
};
8386

8487
/* sync mode definitions. */
8588
enum e_rknpu_mem_sync_mode {
8689
RKNPU_MEM_SYNC_TO_DEVICE = 1 << 0,
8790
RKNPU_MEM_SYNC_FROM_DEVICE = 1 << 1,
88-
RKNPU_MEM_SYNC_MASK =
89-
RKNPU_MEM_SYNC_TO_DEVICE | RKNPU_MEM_SYNC_FROM_DEVICE
91+
RKNPU_MEM_SYNC_MASK = RKNPU_MEM_SYNC_TO_DEVICE |
92+
RKNPU_MEM_SYNC_FROM_DEVICE
9093
};
9194

9295
/* job mode definitions. */
@@ -155,7 +158,7 @@ struct rknpu_mem_create {
155158
__u64 dma_addr;
156159
__u64 sram_size;
157160
__s32 iommu_domain_id;
158-
__u32 reserved;
161+
__u32 core_mask;
159162
};
160163

161164
/**
@@ -302,25 +305,25 @@ struct rknpu_action {
302305

303306
#include <drm/drm.h>
304307

305-
#define DRM_IOCTL_RKNPU_ACTION \
308+
#define DRM_IOCTL_RKNPU_ACTION \
306309
DRM_IOWR(DRM_COMMAND_BASE + RKNPU_ACTION, struct rknpu_action)
307-
#define DRM_IOCTL_RKNPU_SUBMIT \
310+
#define DRM_IOCTL_RKNPU_SUBMIT \
308311
DRM_IOWR(DRM_COMMAND_BASE + RKNPU_SUBMIT, struct rknpu_submit)
309-
#define DRM_IOCTL_RKNPU_MEM_CREATE \
312+
#define DRM_IOCTL_RKNPU_MEM_CREATE \
310313
DRM_IOWR(DRM_COMMAND_BASE + RKNPU_MEM_CREATE, struct rknpu_mem_create)
311-
#define DRM_IOCTL_RKNPU_MEM_MAP \
314+
#define DRM_IOCTL_RKNPU_MEM_MAP \
312315
DRM_IOWR(DRM_COMMAND_BASE + RKNPU_MEM_MAP, struct rknpu_mem_map)
313-
#define DRM_IOCTL_RKNPU_MEM_DESTROY \
316+
#define DRM_IOCTL_RKNPU_MEM_DESTROY \
314317
DRM_IOWR(DRM_COMMAND_BASE + RKNPU_MEM_DESTROY, struct rknpu_mem_destroy)
315-
#define DRM_IOCTL_RKNPU_MEM_SYNC \
318+
#define DRM_IOCTL_RKNPU_MEM_SYNC \
316319
DRM_IOWR(DRM_COMMAND_BASE + RKNPU_MEM_SYNC, struct rknpu_mem_sync)
317320

318321
#define IOCTL_RKNPU_ACTION RKNPU_IOWR(RKNPU_ACTION, struct rknpu_action)
319322
#define IOCTL_RKNPU_SUBMIT RKNPU_IOWR(RKNPU_SUBMIT, struct rknpu_submit)
320-
#define IOCTL_RKNPU_MEM_CREATE \
323+
#define IOCTL_RKNPU_MEM_CREATE \
321324
RKNPU_IOWR(RKNPU_MEM_CREATE, struct rknpu_mem_create)
322325
#define IOCTL_RKNPU_MEM_MAP RKNPU_IOWR(RKNPU_MEM_MAP, struct rknpu_mem_map)
323-
#define IOCTL_RKNPU_MEM_DESTROY \
326+
#define IOCTL_RKNPU_MEM_DESTROY \
324327
RKNPU_IOWR(RKNPU_MEM_DESTROY, struct rknpu_mem_destroy)
325328
#define IOCTL_RKNPU_MEM_SYNC RKNPU_IOWR(RKNPU_MEM_SYNC, struct rknpu_mem_sync)
326329

drivers/rknpu/include/rknpu_iommu.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,26 @@ struct rknpu_iommu_dma_cookie {
3232
};
3333

3434
dma_addr_t rknpu_iommu_dma_alloc_iova(struct iommu_domain *domain, size_t size,
35-
u64 dma_limit, struct device *dev);
35+
u64 dma_limit, struct device *dev,
36+
bool size_aligned);
3637

3738
void rknpu_iommu_dma_free_iova(struct rknpu_iommu_dma_cookie *cookie,
38-
dma_addr_t iova, size_t size);
39+
dma_addr_t iova, size_t size, bool size_aligned);
40+
41+
int rknpu_iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
42+
int nents, enum dma_data_direction dir,
43+
bool iova_aligned);
44+
45+
void rknpu_iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
46+
int nents, enum dma_data_direction dir,
47+
bool iova_aligned);
3948

4049
int rknpu_iommu_init_domain(struct rknpu_device *rknpu_dev);
4150
int rknpu_iommu_switch_domain(struct rknpu_device *rknpu_dev, int domain_id);
4251
void rknpu_iommu_free_domains(struct rknpu_device *rknpu_dev);
52+
int rknpu_iommu_domain_get_and_switch(struct rknpu_device *rknpu_dev,
53+
int domain_id);
54+
int rknpu_iommu_domain_put(struct rknpu_device *rknpu_dev);
4355

4456
#if KERNEL_VERSION(5, 10, 0) < LINUX_VERSION_CODE
4557
int iommu_get_dma_cookie(struct iommu_domain *domain);

drivers/rknpu/rknpu_devfreq.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ static int npu_opp_config_clks(struct device *dev, struct opp_table *opp_table,
234234

235235
static const struct rockchip_opp_data rk3576_npu_opp_data = {
236236
.set_read_margin = rk3576_npu_set_read_margin,
237+
// .set_soc_info = rockchip_opp_set_low_length,
237238
#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE
238239
.config_regulators = npu_opp_config_regulators,
239240
.config_clks = npu_opp_config_clks,
@@ -395,7 +396,11 @@ int rknpu_devfreq_init(struct rknpu_device *rknpu_dev)
395396
err_remove_governor:
396397
devfreq_remove_governor(&devfreq_rknpu_ondemand);
397398
err_uinit_table:
399+
#if KERNEL_VERSION(5, 10, 198) <= LINUX_VERSION_CODE
398400
rockchip_uninit_opp_table(dev, info);
401+
#else
402+
dev_pm_opp_of_remove_table(dev);
403+
#endif
399404

400405
return ret;
401406
}
@@ -729,7 +734,11 @@ int rknpu_devfreq_init(struct rknpu_device *rknpu_dev)
729734
err_remove_governor:
730735
devfreq_remove_governor(&devfreq_rknpu_ondemand);
731736
err_remove_table:
737+
#if KERNEL_VERSION(5, 10, 198) <= LINUX_VERSION_CODE
732738
rockchip_uninit_opp_table(dev, &rknpu_dev->opp_info);
739+
#else
740+
dev_pm_opp_of_remove_table(dev);
741+
#endif
733742

734743
rknpu_dev->devfreq = NULL;
735744

@@ -790,6 +799,10 @@ void rknpu_devfreq_remove(struct rknpu_device *rknpu_dev)
790799
}
791800
if (rknpu_dev->devfreq)
792801
devfreq_remove_governor(&devfreq_rknpu_ondemand);
802+
#if KERNEL_VERSION(5, 10, 198) <= LINUX_VERSION_CODE
793803
rockchip_uninit_opp_table(rknpu_dev->dev, &rknpu_dev->opp_info);
804+
#else
805+
dev_pm_opp_of_remove_table(rknpu_dev->dev);
806+
#endif
794807
}
795808
EXPORT_SYMBOL(rknpu_devfreq_remove);

0 commit comments

Comments
 (0)