Skip to content

Commit ed534b2

Browse files
committed
Using outl to trigger interrupt
1 parent ce27801 commit ed534b2

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

x86/crypto/hello-pci-dev.c

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ typedef struct PCIHelloDevState {
2929
#define TYPE_PCI_HELLO_DEV "pci-hellodev"
3030
#define PCI_HELLO_DEV(obj) OBJECT_CHECK(PCIHelloDevState, (obj), TYPE_PCI_HELLO_DEV)
3131
/* sizes must be power of 2 in PCI */
32-
#define HELLO_IO_SIZE 1<<4
33-
#define HELLO_MMIO_SIZE 1<<6
32+
#define HELLO_IO_SIZE 1<<4 /* 16 byte */
33+
#define HELLO_MMIO_SIZE 1<<6 /* 64 byte */
3434

3535
static void hello_iowrite(void *opaque, hwaddr addr, uint64_t value, unsigned size)
3636
{
3737
int i;
3838
PCIHelloDevState *d = (PCIHelloDevState *) opaque;
3939
PCIDevice *pci_dev = (PCIDevice *) opaque;
4040

41-
printf("Write Ordered, addr=%x, value=%lu, size=%d\n", (unsigned) addr, value, size);
41+
printf("PIO Write : addr=%x, value=%lu, size=%d\n", (unsigned) addr, value, size);
4242

4343
switch (addr) {
4444
case 0:
@@ -62,59 +62,73 @@ static void hello_iowrite(void *opaque, hwaddr addr, uint64_t value, unsigned si
6262
break;
6363
default:
6464
printf("Io not used\n");
65+
break;
6566
}
6667
}
6768

6869
static uint64_t hello_ioread(void *opaque, hwaddr addr, unsigned size)
6970
{
71+
int ret = 0;
72+
7073
PCIHelloDevState *d = (PCIHelloDevState *) opaque;
71-
printf("Read Ordered, addr =%x, size=%d\n", (unsigned) addr, size);
74+
printf("PIO Read : addr =%x, size=%d\n", (unsigned) addr, size);
7275

7376
switch (addr) {
7477
case 0:
7578
/* irq status */
76-
return d->threw_irq;
79+
ret = d->threw_irq;
7780
break;
7881
default:
7982
printf("Io not used\n");
80-
return 0x0;
83+
ret = 0x0;
84+
break;
8185
}
86+
87+
return ret;
8288
}
8389

8490
static uint64_t hello_mmioread(void *opaque, hwaddr addr, unsigned size)
8591
{
92+
int ret = 0;
93+
8694
PCIHelloDevState *d = (PCIHelloDevState *) opaque;
87-
printf("MMIO Read Ordered, addr =%x, size=%d\n",(unsigned) addr, size);
95+
96+
printf("MMIO Read: addr =%x, size=%d\n",(unsigned) addr, size);
8897

8998
switch (addr) {
9099
case 0:
91100
/* also irq status */
92-
printf("irq_status\n");
93-
return d->threw_irq;
101+
printf("read irq_status\n");
102+
ret = d->threw_irq;
94103
break;
95104
case 4:
96105
/* Id of the device */
97-
printf("id\n");
98-
return d->id;
106+
printf("read id\n");
107+
ret = d->id;
99108
break;
100109
default:
101110
printf("MMIO not used\n");
102-
return 0x0;
111+
break;
103112
}
113+
114+
return ret;
104115
}
105116

106117
static void hello_mmiowrite(void *opaque, hwaddr addr, uint64_t value, unsigned size)
107118
{
108119
PCIHelloDevState *d = (PCIHelloDevState *) opaque;
109-
printf("MMIO write Ordered, addr=%x, value=%lu, size=%d\n",(unsigned) addr, value, size);
120+
121+
printf("MMIO write: addr=%x, value=%lx, size=%d\n",(unsigned) addr, value, size);
110122

111123
switch (addr) {
112124
case 4:
113125
/* change the id */
126+
printf("write id\n");
114127
d->id = value;
115128
break;
116129
default:
117130
printf("MMIO not writable or not used\n");
131+
break;
118132
}
119133
}
120134

@@ -154,14 +168,13 @@ static void hello_io_setup(PCIHelloDevState *d)
154168
}
155169

156170
/* When device is loaded */
157-
static void pci_hellodev_init(PCIDevice *pci_dev, Error **errp)
171+
static void pci_hellodev_realize(PCIDevice *pci_dev, Error **errp)
158172
{
159173
uint8_t *pci_conf;
160174

161175
/* init the internal state of the device */
162176
PCIHelloDevState *d = PCI_HELLO_DEV(pci_dev);
163177

164-
printf("d=%lu\n", (unsigned long) &d);
165178
d->dma_size = 0x1ffff * sizeof(char);
166179
d->dma_buf = malloc(d->dma_size);
167180
d->id = 0x1337;
@@ -183,8 +196,8 @@ static void pci_hellodev_init(PCIDevice *pci_dev, Error **errp)
183196
pci_conf = pci_dev->config;
184197

185198
/*
186-
* also in ldd, a pci device has 4 pin for interrupt
187-
* here we use pin B.
199+
* also in ldd, a pci device has 4 pin for interrupt here we use pin B.
200+
* lspci -vv
188201
*/
189202
pci_conf[PCI_INTERRUPT_PIN] = 0x02;
190203

@@ -219,7 +232,7 @@ static void pci_hellodev_class_init(ObjectClass *klass, void *data)
219232
{
220233
DeviceClass *dc = DEVICE_CLASS(klass);
221234
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
222-
k->realize = pci_hellodev_init;
235+
k->realize = pci_hellodev_realize;
223236
k->exit = pci_hellodev_uninit;
224237
/* this identify our device */
225238
k->vendor_id = 0x1337;

x86/crypto/hello-pci-drv.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
#include <linux/interrupt.h>
55
#include <asm/io.h>
66

7-
#define PCI_TIC_VENDOR 0x1337
8-
#define PCI_TIC_DEVICE 0x0001
9-
#define PCI_TIC_SUBVENDOR 0x1af4
10-
#define PCI_TIC_SUBDEVICE 0x1100
7+
#define HELLO_PCI_VENDOR 0x1337
8+
#define HELLO_PCI_DEVICE 0x0001
119

12-
#define MAX_TIC_MAPS 1
13-
#define MAX_TIC_PORT_REGIONS 1
10+
#define HELLO_PCI_MAX_MAPS 1
11+
#define HELLO_PCI_MAX_PORT_REGIONS 1
1412
static struct pci_driver hello_pci;
1513
struct hello_pci_mem {
1614
const char *name;
@@ -25,8 +23,8 @@ struct hello_pci_io {
2523
};
2624

2725
struct hello_pci_info {
28-
struct hello_pci_mem mem[MAX_TIC_MAPS];
29-
struct hello_pci_io port[MAX_TIC_PORT_REGIONS];
26+
struct hello_pci_mem mem[HELLO_PCI_MAX_MAPS];
27+
struct hello_pci_io port[HELLO_PCI_MAX_PORT_REGIONS];
3028
u8 irq;
3129
};
3230

@@ -91,16 +89,18 @@ static int hello_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
9189
* get a mmio reg value and change it
9290
* access mmio via ioread/iowrite
9391
*/
94-
pr_alert("device id=%x\n", ioread32(info->mem[0].start + 4));
92+
pr_alert("mmio read device id=%x\n", ioread32(info->mem[0].start + 4));
93+
pr_alert("mmio write device id\n");
9594
iowrite32(0x4567, info->mem[0].start + 4);
96-
pr_alert("modified device id=%x\n", ioread32(info->mem[0].start + 4));
95+
pr_alert("mmio read modified device id=%x\n", ioread32(info->mem[0].start + 4));
9796

9897
/*
9998
* access pio via in/out
10099
*
101100
* assert an irq
102101
*/
103-
outb(1, info->port[0].start);
102+
pr_alert("PIO write, assert an interrupt\n");
103+
outl(1, info->port[0].start);
104104
/* try dma without iommu */
105105
outl(1, info->port[0].start + 4);
106106

@@ -137,11 +137,12 @@ static void hello_pci_remove(struct pci_dev *dev)
137137
kfree(info);
138138
}
139139

140-
/* vendor and device (+ subdevice and subvendor)
140+
/*
141+
* vendor and device (+ subdevice and subvendor)
141142
* identifies a device we support
142143
*/
143144
static struct pci_device_id hello_pci_ids[] = {
144-
{ PCI_DEVICE(PCI_TIC_VENDOR, PCI_TIC_DEVICE) },
145+
{ PCI_DEVICE(HELLO_PCI_VENDOR, HELLO_PCI_DEVICE) },
145146
{ 0, },
146147
};
147148

0 commit comments

Comments
 (0)