VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/drm/vbox_hgsmi.c@ 69206

Last change on this file since 69206 was 67398, checked in by vboxsync, 8 years ago

bugref:8524: Additions/linux: play nicely with distribution-installed Additions
Additions: linux/drm: Fix checkpatch warning in vbox_hgsmi.c

Fix:

CHECK: Alignment should match open parenthesis

#123: FILE: drivers/staging/vboxvideo/vbox_hgsmi.c:123:

offset = gen_pool_virt_to_phys(guest_pool,

(unsigned long)buf - sizeof(HGSMIBUFFERHEADER));

Signed-off-by: Hans de Goede <hdegoede@…>

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/** @file
2 * VirtualBox Additions Linux kernel video driver hgsmi interface code
3 */
4
5/*
6 * Copyright (C) 2017 Oracle Corporation
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * The above copyright notice and this permission notice (including the
25 * next paragraph) shall be included in all copies or substantial portions
26 * of the Software.
27 *
28 * Authors: Hans de Goede <hdegoede@redhat.com>
29 */
30
31#include <HGSMIBase.h>
32#include <VBoxVideoVBE.h>
33
34/* One-at-a-Time Hash from http://www.burtleburtle.net/bob/hash/doobs.html */
35static u32 hgsmi_hash_process(u32 hash, const u8 *data, int size)
36{
37 while (size--) {
38 hash += *data++;
39 hash += (hash << 10);
40 hash ^= (hash >> 6);
41 }
42
43 return hash;
44}
45
46static u32 hgsmi_hash_end(u32 hash)
47{
48 hash += (hash << 3);
49 hash ^= (hash >> 11);
50 hash += (hash << 15);
51
52 return hash;
53}
54
55/* Not really a checksum but that is the naming used in all vbox code */
56static u32 hgsmi_checksum(u32 offset,
57 const HGSMIBUFFERHEADER *header,
58 const HGSMIBUFFERTAIL *tail)
59{
60 u32 checksum;
61
62 checksum = hgsmi_hash_process(0, (u8 *)&offset, sizeof(offset));
63 checksum = hgsmi_hash_process(checksum, (u8 *)header, sizeof(*header));
64 /* 4 -> Do not checksum the checksum itself */
65 checksum = hgsmi_hash_process(checksum, (u8 *)tail, 4);
66
67 return hgsmi_hash_end(checksum);
68}
69
70#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
71void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma)
72{
73 unsigned long vaddr = gen_pool_alloc(pool, size);
74
75 if (vaddr)
76 *dma = gen_pool_virt_to_phys(pool, vaddr);
77 return (void *)vaddr;
78}
79#endif
80
81void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
82 u8 channel, u16 channel_info)
83{
84 HGSMIBUFFERHEADER *h;
85 HGSMIBUFFERTAIL *t;
86 size_t total_size;
87 dma_addr_t offset;
88
89 total_size = size + sizeof(HGSMIBUFFERHEADER) + sizeof(HGSMIBUFFERTAIL);
90 h = gen_pool_dma_alloc(guest_pool, total_size, &offset);
91 if (!h)
92 return NULL;
93
94 t = (HGSMIBUFFERTAIL *)((u8 *)h + sizeof(HGSMIBUFFERHEADER) + size);
95
96 h->u8Flags = HGSMI_BUFFER_HEADER_F_SEQ_SINGLE;
97 h->u32DataSize = size;
98 h->u8Channel = channel;
99 h->u16ChannelInfo = channel_info;
100 memset(&h->u.au8Union, 0, sizeof(h->u.au8Union));
101
102 t->u32Reserved = 0;
103 t->u32Checksum = hgsmi_checksum(offset, h, t);
104
105 return (u8 *)h + sizeof(HGSMIBUFFERHEADER);
106}
107
108void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf)
109{
110 HGSMIBUFFERHEADER *h =
111 (HGSMIBUFFERHEADER *)((u8 *)buf - sizeof(HGSMIBUFFERHEADER));
112 size_t total_size = h->u32DataSize + sizeof(HGSMIBUFFERHEADER) +
113 sizeof(HGSMIBUFFERTAIL);
114
115 gen_pool_free(guest_pool, (unsigned long)h, total_size);
116}
117
118int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf)
119{
120 phys_addr_t offset;
121
122 offset = gen_pool_virt_to_phys(guest_pool, (unsigned long)buf -
123 sizeof(HGSMIBUFFERHEADER));
124 outl(offset, VGA_PORT_HGSMI_GUEST);
125 /* Make the compiler aware that the host has changed memory. */
126 mb();
127
128 return VINF_SUCCESS;
129}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette