Skip to content

Commit 5278cc5

Browse files
committed
Crypto : wrap dma test in a function
Run dma test command: devmem 0xfebf1003 b 2 devmem 0xfebf1002 b 5
1 parent 4d6690d commit 5278cc5

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

x86/crypto/crypto-drv.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
#include <linux/pci.h>
1010

1111
#define DMA_TEST_DEMO
12+
#ifdef DMA_TEST_DEMO
13+
struct aaaa {
14+
int a;
15+
char name[10];
16+
};
17+
#endif
18+
1219
/* refcode: linux/drivers/net/ethernet/intel/e1000/e1000_main.c */
1320
#define BAR_0 0
1421
char e1000_driver_name[] = "mycrypto";
@@ -196,7 +203,12 @@ static irqreturn_t crypto_irq_handler(int irq, void *data)
196203
printk("ErrorCode: %s\n", errno2errstr(readb(hw_addr + ErrorCode)));
197204
}
198205
if (ret == CryptoDevice_MsiReady)
206+
{
199207
printk("ReadyINT handled\n");
208+
/* 从dma buffer中取出数据 */
209+
struct aaaa *pa = cpu_out_addr;
210+
printk("Read Dma data back: %d %s\n", pa->a, pa->name);
211+
}
200212
if (ret == CryptoDevice_MsiReset)
201213
printk("ResetINT handled\n");
202214

@@ -322,10 +334,6 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
322334
#endif
323335

324336
#ifdef DMA_TEST_DEMO
325-
struct aaaa {
326-
int a;
327-
char name[10];
328-
};
329337
/* setup data */
330338
struct aaaa a = {
331339
.a = 911,

x86/crypto/crypto.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <openssl/sha.h>
99

10-
#define DMA_TEST_DEMO
10+
//#define DMA_TEST_DEMO
1111
#define NO2STR(n) case n: return #n
1212

1313
#define PCI_CRYPTO_DEV(obj) OBJECT_CHECK(PCICryptoState, obj, "crypto")
@@ -48,7 +48,8 @@ enum {
4848
CryptoDevice_ReadyState,
4949
CryptoDevice_ResetState,
5050
CryptoDevice_AesCbcState,
51-
CryptoDevice_Sha2State
51+
CryptoDevice_Sha2State,
52+
CryptoDevice_DmaTestState
5253
};
5354

5455
enum {
@@ -90,6 +91,9 @@ typedef struct DmaRequest
9091
* Decrypt
9192
* devmem 0xfebf1002 b 3
9293
*
94+
* Dma test command
95+
* devmem 0xfebf1002 b 5
96+
*
9397
* Enable interrupt flag to 2
9498
* devmem 0xfebf1003 b 2
9599
*/
@@ -133,7 +137,8 @@ typedef enum tagCryptoDeviceCommand {
133137
CryptoDevice_ResetCommand,
134138
CryptoDevice_AesCbcEncryptoCommand,
135139
CryptoDevice_AesCbcDecryptoCommand,
136-
CryptoDevice_Sha2Command
140+
CryptoDevice_Sha2Command,
141+
CryptoDevice_DmaTestCommand
137142
} CryptoDeviceCommand;
138143

139144
typedef enum tagCryptoDeviceMSI
@@ -455,13 +460,13 @@ static void clear_interrupt(PCICryptoState *dev)
455460
}
456461
}
457462

458-
#ifdef DMA_TEST_DEMO
463+
//#ifdef DMA_TEST_DEMO
459464
struct aaaa {
460465
int a;
461466
char name[10];
462467
};
463468
struct aaaa in;
464-
#endif
469+
//#endif
465470

466471
static void pci_crypto_memio_write(void *opaque,
467472
hwaddr addr,
@@ -503,6 +508,7 @@ static void pci_crypto_memio_write(void *opaque,
503508
case CryptoDevice_AesCbcEncryptoCommand:
504509
case CryptoDevice_AesCbcDecryptoCommand:
505510
case CryptoDevice_Sha2Command:
511+
case CryptoDevice_DmaTestCommand:
506512
qemu_cond_signal(&dev->thread_cond);
507513
break;
508514
default:
@@ -639,6 +645,22 @@ static int DoAesCbc(PCICryptoState *dev, DmaRequest *dma, bool encrypt)
639645
return 0;
640646
}
641647

648+
static int DoDmaTest(PCICryptoState *dev, DmaRequest *dma)
649+
{
650+
/* read data from driver */
651+
cpu_physical_memory_read(dma->in.page_addr, &in, sizeof(struct aaaa));
652+
printf("a = %d, name = %s\n", in.a, in.name);
653+
654+
/* we do some modify the data and pass to driver */
655+
in.a = 119;
656+
strcpy(in.name, "DmaOut");
657+
/* 将dma in的数据修改后写入到dma out物理地址 */
658+
cpu_physical_memory_write(dma->out.page_addr, &in, sizeof(struct aaaa));
659+
/* 产生中断通知驱动接收数据, 在驱动中断处理函数中接收数据 */
660+
661+
return 0;
662+
}
663+
642664
static int DoSha256(PCICryptoState *dev, DmaRequest *dma)
643665
{
644666
unsigned char digest[SHA256_DIGEST_LENGTH] = {};
@@ -748,6 +770,18 @@ static void *worker_thread(void *pdev)
748770
error = DoSha256(dev, &dma);
749771
qemu_mutex_lock(&dev->io_mutex);
750772
break;
773+
774+
/*
775+
* enable interrupt first and run dma
776+
* devmem 0xfebf1003 b 2
777+
* devmem 0xfebf1002 b 5
778+
*/
779+
case CryptoDevice_DmaTestCommand:
780+
dev->io->State = CryptoDevice_DmaTestState;
781+
qemu_mutex_unlock(&dev->io_mutex);
782+
error = DoDmaTest(dev, &dma);
783+
qemu_mutex_lock(&dev->io_mutex);
784+
break;
751785
}
752786

753787
switch (error)

0 commit comments

Comments
 (0)