/[dynamips]/upstream/dynamips-0.2.6-RC3/pci_io.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /upstream/dynamips-0.2.6-RC3/pci_io.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sat Oct 6 16:06:49 2007 UTC (14 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 2946 byte(s)
dynamips-0.2.6-RC3

1 dpavlin 1 /*
2     * Cisco 7200 (Predator) simulation platform.
3     * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4     *
5     * PCI I/O space.
6     */
7    
8     #include <stdio.h>
9     #include <stdlib.h>
10     #include <string.h>
11     #include <unistd.h>
12     #include <sys/types.h>
13    
14     #include "mips64.h"
15     #include "dynamips.h"
16     #include "memory.h"
17     #include "device.h"
18     #include "pci_io.h"
19    
20     /* Debugging flags */
21     #define DEBUG_ACCESS 0
22    
23     /* Add a new PCI I/O device */
24     struct pci_io_device *pci_io_add(struct pci_io_data *d,
25     m_uint32_t start,m_uint32_t end,
26     struct vdevice *dev,dev_handler_t handler)
27     {
28     struct pci_io_device *p;
29    
30     if (!(p = malloc(sizeof(*p)))) {
31     fprintf(stderr,"pci_io_add: unable to create a new device.\n");
32     return NULL;
33     }
34    
35     p->start = start;
36     p->end = end;
37     p->real_dev = dev;
38     p->handler = handler;
39    
40     p->next = d->dev_list;
41     p->pprev = &d->dev_list;
42    
43     if (d->dev_list != NULL)
44     d->dev_list->pprev = &p->next;
45    
46     d->dev_list = p;
47     return p;
48     }
49    
50     /* Remove a PCI I/O device */
51     void pci_io_remove(struct pci_io_device *dev)
52     {
53     if (dev != NULL) {
54     if (dev->next)
55     dev->next->pprev = dev->pprev;
56    
57     *(dev->pprev) = dev->next;
58     free(dev);
59     }
60     }
61    
62     /*
63     * pci_io_access()
64     */
65     static void *pci_io_access(cpu_mips_t *cpu,struct vdevice *dev,
66     m_uint32_t offset,u_int op_size,u_int op_type,
67     m_uint64_t *data)
68     {
69     struct pci_io_data *d = dev->priv_data;
70     struct pci_io_device *p;
71    
72     #if DEBUG_ACCESS
73     if (op_type == MTS_READ) {
74     cpu_log(cpu,"PCI_IO","read request at pc=0x%llx, offset=0x%x\n",
75     cpu->pc,offset);
76     } else {
77     cpu_log(cpu,"PCI_IO",
78     "write request (data=0x%llx) at pc=0x%llx, offset=0x%x\n",
79     *data,cpu->pc,offset);
80     }
81     #endif
82    
83     if (op_type == MTS_READ)
84     *data = 0;
85    
86     for(p=d->dev_list;p;p=p->next)
87     if ((offset >= p->start) && (offset <= p->end)) {
88     return(p->handler(cpu,p->real_dev,(offset - p->start),
89     op_size,op_type,data));
90     }
91    
92     return NULL;
93     }
94    
95     /* Remove PCI I/O space */
96     void pci_io_data_remove(vm_instance_t *vm,struct pci_io_data *d)
97     {
98     if (d != NULL) {
99     /* Remove the device */
100     dev_remove(vm,&d->dev);
101    
102     /* Free the structure itself */
103     free(d);
104     }
105     }
106    
107     /* Initialize PCI I/O space */
108     struct pci_io_data *pci_io_data_init(vm_instance_t *vm,m_uint64_t paddr)
109     {
110     struct pci_io_data *d;
111    
112     /* Allocate the PCI I/O data structure */
113     if (!(d = malloc(sizeof(*d)))) {
114     fprintf(stderr,"PCI_IO: out of memory\n");
115     return NULL;
116     }
117    
118     memset(d,0,sizeof(*d));
119     dev_init(&d->dev);
120     d->dev.name = "pci_io";
121     d->dev.priv_data = d;
122     d->dev.phys_addr = paddr;
123     d->dev.phys_len = 2 * 1048576;
124     d->dev.handler = pci_io_access;
125    
126     /* Map this device to the VM */
127     vm_bind_device(vm,&d->dev);
128     return(d);
129     }

  ViewVC Help
Powered by ViewVC 1.1.26