]> git.proxmox.com Git - mirror_qemu.git/blame - hw/net/vmware_utils.h
net: add Sun HME (Happy Meal Ethernet) on-board NIC
[mirror_qemu.git] / hw / net / vmware_utils.h
CommitLineData
75020a70
DF
1/*
2 * QEMU VMWARE paravirtual devices - auxiliary code
3 *
4 * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
5 *
6 * Developed by Daynix Computing LTD (http://www.daynix.com)
7 *
8 * Authors:
9 * Dmitry Fleytman <dmitry@daynix.com>
10 * Yan Vugenfirer <yan@daynix.com>
11 *
12 * This work is licensed under the terms of the GNU GPL, version 2 or later.
13 * See the COPYING file in the top-level directory.
14 *
15 */
16
17#ifndef VMWARE_UTILS_H
18#define VMWARE_UTILS_H
19
20#include "qemu/range.h"
dd3c1684 21#include "vmxnet_debug.h"
75020a70
DF
22
23/*
24 * Shared memory access functions with byte swap support
25 * Each function contains printout for reverse-engineering needs
26 *
27 */
28static inline void
c5082773 29vmw_shmem_read(PCIDevice *d, hwaddr addr, void *buf, int len)
75020a70
DF
30{
31 VMW_SHPRN("SHMEM r: %" PRIx64 ", len: %d to %p", addr, len, buf);
c5082773 32 pci_dma_read(d, addr, buf, len);
75020a70
DF
33}
34
35static inline void
c5082773 36vmw_shmem_write(PCIDevice *d, hwaddr addr, void *buf, int len)
75020a70
DF
37{
38 VMW_SHPRN("SHMEM w: %" PRIx64 ", len: %d to %p", addr, len, buf);
c5082773 39 pci_dma_write(d, addr, buf, len);
75020a70
DF
40}
41
42static inline void
c5082773 43vmw_shmem_rw(PCIDevice *d, hwaddr addr, void *buf, int len, int is_write)
75020a70
DF
44{
45 VMW_SHPRN("SHMEM r/w: %" PRIx64 ", len: %d (to %p), is write: %d",
46 addr, len, buf, is_write);
47
c5082773
KA
48 if (is_write)
49 pci_dma_write(d, addr, buf, len);
50 else
51 pci_dma_read(d, addr, buf, len);
75020a70
DF
52}
53
54static inline void
c5082773 55vmw_shmem_set(PCIDevice *d, hwaddr addr, uint8_t val, int len)
75020a70
DF
56{
57 int i;
58 VMW_SHPRN("SHMEM set: %" PRIx64 ", len: %d (value 0x%X)", addr, len, val);
59
60 for (i = 0; i < len; i++) {
c5082773 61 pci_dma_write(d, addr + i, &val, 1);
75020a70
DF
62 }
63}
64
65static inline uint32_t
c5082773 66vmw_shmem_ld8(PCIDevice *d, hwaddr addr)
75020a70 67{
c5082773
KA
68 uint8_t res;
69 pci_dma_read(d, addr, &res, 1);
75020a70
DF
70 VMW_SHPRN("SHMEM load8: %" PRIx64 " (value 0x%X)", addr, res);
71 return res;
72}
73
74static inline void
c5082773 75vmw_shmem_st8(PCIDevice *d, hwaddr addr, uint8_t value)
75020a70
DF
76{
77 VMW_SHPRN("SHMEM store8: %" PRIx64 " (value 0x%X)", addr, value);
c5082773 78 pci_dma_write(d, addr, &value, 1);
75020a70
DF
79}
80
81static inline uint32_t
c5082773 82vmw_shmem_ld16(PCIDevice *d, hwaddr addr)
75020a70 83{
c5082773
KA
84 uint16_t res;
85 pci_dma_read(d, addr, &res, 2);
75020a70
DF
86 VMW_SHPRN("SHMEM load16: %" PRIx64 " (value 0x%X)", addr, res);
87 return res;
88}
89
90static inline void
c5082773 91vmw_shmem_st16(PCIDevice *d, hwaddr addr, uint16_t value)
75020a70
DF
92{
93 VMW_SHPRN("SHMEM store16: %" PRIx64 " (value 0x%X)", addr, value);
c5082773 94 pci_dma_write(d, addr, &value, 2);
75020a70
DF
95}
96
97static inline uint32_t
c5082773 98vmw_shmem_ld32(PCIDevice *d, hwaddr addr)
75020a70 99{
c5082773
KA
100 uint32_t res;
101 pci_dma_read(d, addr, &res, 4);
75020a70
DF
102 VMW_SHPRN("SHMEM load32: %" PRIx64 " (value 0x%X)", addr, res);
103 return res;
104}
105
106static inline void
c5082773 107vmw_shmem_st32(PCIDevice *d, hwaddr addr, uint32_t value)
75020a70
DF
108{
109 VMW_SHPRN("SHMEM store32: %" PRIx64 " (value 0x%X)", addr, value);
c5082773 110 pci_dma_write(d, addr, &value, 4);
75020a70
DF
111}
112
113static inline uint64_t
c5082773 114vmw_shmem_ld64(PCIDevice *d, hwaddr addr)
75020a70 115{
c5082773
KA
116 uint64_t res;
117 pci_dma_read(d, addr, &res, 8);
75020a70
DF
118 VMW_SHPRN("SHMEM load64: %" PRIx64 " (value %" PRIx64 ")", addr, res);
119 return res;
120}
121
122static inline void
c5082773 123vmw_shmem_st64(PCIDevice *d, hwaddr addr, uint64_t value)
75020a70
DF
124{
125 VMW_SHPRN("SHMEM store64: %" PRIx64 " (value %" PRIx64 ")", addr, value);
c5082773 126 pci_dma_write(d, addr, &value, 8);
75020a70
DF
127}
128
129/* Macros for simplification of operations on array-style registers */
130
131/*
132 * Whether <addr> lies inside of array-style register defined by <base>,
133 * number of elements (<cnt>) and element size (<regsize>)
134 *
135*/
136#define VMW_IS_MULTIREG_ADDR(addr, base, cnt, regsize) \
137 range_covers_byte(base, cnt * regsize, addr)
138
139/*
140 * Returns index of given register (<addr>) in array-style register defined by
141 * <base> and element size (<regsize>)
142 *
143*/
144#define VMW_MULTIREG_IDX_BY_ADDR(addr, base, regsize) \
145 (((addr) - (base)) / (regsize))
146
147#endif