@@ -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
3535static 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
6869static 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
8490static 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
106117static 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 ;
0 commit comments