Merge remote-tracking branch 'qemu/master'
[qemu/ar7.git] / hw / net / tnetw1130-vlynq.c
blobca71e1fb737bede07974e7f5b66ba6619ab81013
1 /*
2 * QEMU emulation for Texas Instruments TNETW1130 (ACX111) wireless.
4 * Copyright (C) 2007-2010 Stefan Weil
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * Texas Instruments does not provide any datasheets.
21 * TODO:
22 * - Add save, load support.
23 * - Much more emulation is needed.
26 #include "qemu/osdep.h"
27 #include "hw.h"
28 #include "net/net.h"
29 #include "pci/pci.h"
30 #include "tnetw1130.h"
31 #include "vlynq.h"
33 #if defined(CONFIG_VLYNQ) // TODO
35 /*****************************************************************************
37 * Common declarations.
39 ****************************************************************************/
41 #define BIT(n) (1 << (n))
42 #define BITS(n, m) (((0xffffffffU << (31 - n)) >> (31 - n + m)) << m)
44 #define KiB 1024
46 /*****************************************************************************
48 * Declarations for emulation options and debugging.
50 ****************************************************************************/
52 /* Debug TNETW1130 card. */
53 #define DEBUG_TNETW1130
55 #if defined(DEBUG_TNETW1130)
56 # define logout(fmt, ...) fprintf(stderr, "ACX111\t%-24s" fmt, __func__, ##__VA_ARGS__)
57 #else
58 # define logout(fmt, ...) ((void)0)
59 #endif
61 #define missing(text) assert(!"feature is missing in this emulation: " text)
62 #define MISSING() logout("%s:%u missing, %s!!!\n", __FILE__, __LINE__, backtrace())
63 #define UNEXPECTED() logout("%s:%u unexpected, %s!!!\n", __FILE__, __LINE__, backtrace())
64 #define backtrace() ""
66 /* Enable or disable logging categories. */
67 #define LOG_PHY 1
68 #define LOG_RX 1 /* receive messages */
69 #define LOG_TX 1 /* transmit messages */
71 #if defined(DEBUG_TNETW1130)
72 # define TRACE(condition, command) ((condition) ? (command) : (void)0)
73 #else
74 # define TRACE(condition, command) ((void)0)
75 #endif
77 #define TNETW1130_FW_SIZE (128 * KiB)
79 typedef struct {
80 VLYNQDevice dev;
81 tnetw1130_t tnetw1130;
82 } vlynq_tnetw1130_t;
84 /*****************************************************************************
86 * Helper functions.
88 ****************************************************************************/
90 #if defined(DEBUG_TNETW1130)
91 static uint32_t traceflags = 1;
93 #define TNETW traceflags
95 #define SET_TRACEFLAG(name) \
96 do { \
97 char *substring = strstr(envvalue, #name); \
98 if (substring) { \
99 name = ((substring > envvalue && substring[-1] == '-') ? 0 : 1); \
101 TRACE(name, logout("Logging enabled for " #name "\n")); \
102 } while(0)
104 static void set_traceflags(const char *envname)
106 const char *envvalue = getenv(envname);
107 if (envvalue != 0) {
108 unsigned long ul = strtoul(envvalue, 0, 0);
109 if ((ul == 0) && strstr(envvalue, "ALL")) ul = 0xffffffff;
110 traceflags = ul;
111 SET_TRACEFLAG(TNETW);
114 #endif /* DEBUG_TNETW1130 */
116 static void reg_write16(uint8_t * reg, uint32_t addr, uint16_t value)
118 assert(!(addr & 1));
119 *(uint16_t *) (&reg[addr]) = cpu_to_le16(value);
122 static void tnetw1130_mem_map(VLYNQDevice *vlynq_dev, int region_num,
123 pcibus_t addr, pcibus_t size, int type)
125 vlynq_tnetw1130_t *d = (vlynq_tnetw1130_t *)vlynq_dev;
126 tnetw1130_t *s = &d->tnetw1130;
128 TRACE(TNETW, logout("region %d, addr 0x%08" FMT_PCIBUS
129 ", size 0x%08" FMT_PCIBUS "\n",
130 region_num, addr, size));
131 assert((unsigned)region_num < TNETW1130_REGIONS);
132 s->region[region_num] = addr;
134 logout("vlynq i/o is missing\n");
135 // TODO: map memory (addr, size, s->io_memory[region_num]).
138 static int vlynq_tnetw1130_init(VLYNQDevice* vlynq_dev)
140 vlynq_tnetw1130_t *d = DO_UPCAST(vlynq_tnetw1130_t, dev, vlynq_dev);
141 //~ uint8_t *pci_conf = d->dev.config;
142 tnetw1130_t *s = &d->tnetw1130;
143 #if defined(DEBUG_TNETW1130)
144 set_traceflags("DEBUG_AR7");
145 #endif
146 TRACE(TNETW, logout("\n"));
147 /* TI TNETW1130 */
148 //~ tnetw1130_pci_config(pci_conf);
150 /* Handler for memory-mapped I/O */
151 // TODO: Code is missing.
152 logout("vlynq i/o is missing\n");
153 //~ s->io_memory[0] =
154 //~ cpu_register_io_memory(tnetw1130_region0_read, tnetw1130_region0_write,
155 //~ d, DEVICE_NATIVE_ENDIAN);
156 //~ s->io_memory[1] =
157 //~ cpu_register_io_memory(tnetw1130_region1_read, tnetw1130_region1_write,
158 //~ d, DEVICE_NATIVE_ENDIAN);
160 TRACE(TNETW, logout("io_memory = 0x%08x, 0x%08x\n", s->io_memory[0], s->io_memory[1]));
162 //~ memcpy(s->mem1 + 0x0001f000, pci_conf, 64);
164 /* eCPU is halted. */
165 reg_write16(s->mem0, TNETW1130_ECPU_CTRL, 1);
167 //~ tnetw1130_mem_map(&d->dev, 0, 0x04000000, 0x22000, 0); /* 0xf0000000 */
168 //~ tnetw1130_mem_map(&d->dev, 1, 0x04022000, 0x40000, 0); /* 0xc0000000 */
169 //~ tnetw1130_mem_map(&d->dev, 1, 0x04000000, 0x40000, 0);
170 //~ tnetw1130_mem_map(&d->dev, 0, 0x04040000, 0x22000, 0);
171 tnetw1130_mem_map(&d->dev, 0, 0x04000000, TNETW1130_MEM0_SIZE, 0);
172 tnetw1130_mem_map(&d->dev, 1, 0x04022000, TNETW1130_MEM1_SIZE, 0);
173 return 0;
176 static int vlynq_tnetw1130_uninit(VLYNQDevice *vlynq_dev)
178 vlynq_tnetw1130_t *d = DO_UPCAST(vlynq_tnetw1130_t, dev, vlynq_dev);
179 tnetw1130_t *s = &d->tnetw1130;
181 //~ vmstate_unregister(s->vmstate, s);
182 qemu_del_nic(s->nic);
183 return 0;
186 static VLYNQDeviceInfo vlynq_tnetw1130_info = {
187 //~ .name = "tnetw1130-vlynq",
188 //~ .desc = "Texas Instruments TNETW1130 (VLYNQ)",
189 //~ .instance_size = sizeof(vlynq_tnetw1130_t),
190 //~ .props = (Property[]) {
191 //~ DEFINE_NIC_PROPERTIES(vlynq_tnetw1130_t, tnetw1130.conf),
192 //~ DEFINE_PROP_END_OF_LIST(),
193 //~ },
194 .init = vlynq_tnetw1130_init,
195 .exit = vlynq_tnetw1130_uninit,
198 static void tnetw1130_register_types(void)
200 vlynq_qdev_register(&vlynq_tnetw1130_info);
203 type_init(tnetw1130_register_types)
205 #endif // CONFIG_VLYNQ
207 /* eof */