Benjamin Romer | f6d0c1e | 2014-04-23 14:58:34 -0400 | [diff] [blame] | 1 | /* Copyright (C) 2010 - 2013 UNISYS CORPORATION |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 2 | * All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or (at |
| 7 | * your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 12 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 13 | * details. |
| 14 | */ |
| 15 | |
| 16 | #ifndef __VBUSCHANNEL_H__ |
| 17 | #define __VBUSCHANNEL_H__ |
| 18 | |
| 19 | /* The vbus channel is the channel area provided via the BUS_CREATE controlvm |
| 20 | * message for each virtual bus. This channel area is provided to both server |
| 21 | * and client ends of the bus. The channel header area is initialized by |
| 22 | * the server, and the remaining information is filled in by the client. |
| 23 | * We currently use this for the client to provide various information about |
| 24 | * the client devices and client drivers for the server end to see. |
| 25 | */ |
Benjamin Romer | 90addb0 | 2014-05-06 09:58:23 -0400 | [diff] [blame^] | 26 | #include <linux/uuid.h> |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 27 | #include "commontypes.h" |
| 28 | #include "vbusdeviceinfo.h" |
| 29 | #include "channel.h" |
| 30 | |
| 31 | /* {193b331b-c58f-11da-95a9-00e08161165f} */ |
| 32 | #define ULTRA_VBUS_CHANNEL_PROTOCOL_GUID \ |
Benjamin Romer | 90addb0 | 2014-05-06 09:58:23 -0400 | [diff] [blame^] | 33 | UUID_LE(0x193b331b, 0xc58f, 0x11da, \ |
| 34 | 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f) |
| 35 | static const uuid_le UltraVbusChannelProtocolGuid = |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 36 | ULTRA_VBUS_CHANNEL_PROTOCOL_GUID; |
| 37 | |
| 38 | #define ULTRA_VBUS_CHANNEL_PROTOCOL_SIGNATURE ULTRA_CHANNEL_PROTOCOL_SIGNATURE |
| 39 | |
| 40 | /* Must increment this whenever you insert or delete fields within this channel |
| 41 | * struct. Also increment whenever you change the meaning of fields within this |
| 42 | * channel struct so as to break pre-existing software. Note that you can |
| 43 | * usually add fields to the END of the channel struct withOUT needing to |
| 44 | * increment this. */ |
| 45 | #define ULTRA_VBUS_CHANNEL_PROTOCOL_VERSIONID 1 |
| 46 | |
| 47 | #define ULTRA_VBUS_CHANNEL_OK_CLIENT(pChannel, logCtx) \ |
| 48 | (ULTRA_check_channel_client(pChannel, \ |
| 49 | UltraVbusChannelProtocolGuid, \ |
| 50 | "vbus", \ |
| 51 | sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL), \ |
| 52 | ULTRA_VBUS_CHANNEL_PROTOCOL_VERSIONID, \ |
| 53 | ULTRA_VBUS_CHANNEL_PROTOCOL_SIGNATURE, \ |
| 54 | __FILE__, __LINE__, logCtx)) |
| 55 | |
| 56 | #define ULTRA_VBUS_CHANNEL_OK_SERVER(actualBytes, logCtx) \ |
| 57 | (ULTRA_check_channel_server(UltraVbusChannelProtocolGuid, \ |
| 58 | "vbus", \ |
| 59 | sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL), \ |
| 60 | actualBytes, \ |
| 61 | __FILE__, __LINE__, logCtx)) |
| 62 | |
| 63 | |
| 64 | #pragma pack(push, 1) /* both GCC and VC now allow this pragma */ |
| 65 | typedef struct _ULTRA_VBUS_HEADERINFO { |
| 66 | U32 structBytes; /* size of this struct in bytes */ |
| 67 | U32 deviceInfoStructBytes; /* sizeof(ULTRA_VBUS_DEVICEINFO) */ |
| 68 | U32 devInfoCount; /* num of items in DevInfo member */ |
| 69 | /* (this is the allocated size) */ |
| 70 | U32 chpInfoByteOffset; /* byte offset from beginning of this struct */ |
| 71 | /* to the the ChpInfo struct (below) */ |
| 72 | U32 busInfoByteOffset; /* byte offset from beginning of this struct */ |
| 73 | /* to the the BusInfo struct (below) */ |
| 74 | U32 devInfoByteOffset; /* byte offset from beginning of this struct */ |
| 75 | /* to the the DevInfo array (below) */ |
| 76 | U8 reserved[104]; |
| 77 | } ULTRA_VBUS_HEADERINFO; |
| 78 | |
| 79 | typedef struct _ULTRA_VBUS_CHANNEL_PROTOCOL { |
| 80 | ULTRA_CHANNEL_PROTOCOL ChannelHeader; /* initialized by server */ |
| 81 | ULTRA_VBUS_HEADERINFO HdrInfo; /* initialized by server */ |
| 82 | /* the remainder of this channel is filled in by the client */ |
| 83 | ULTRA_VBUS_DEVICEINFO ChpInfo; /* describes client chipset device and |
| 84 | * driver */ |
| 85 | ULTRA_VBUS_DEVICEINFO BusInfo; /* describes client bus device and |
| 86 | * driver */ |
| 87 | ULTRA_VBUS_DEVICEINFO DevInfo[0]; /* describes client device and |
| 88 | * driver for */ |
| 89 | /* each device on the bus */ |
| 90 | } ULTRA_VBUS_CHANNEL_PROTOCOL; |
| 91 | |
| 92 | #define VBUS_CH_SIZE_EXACT(MAXDEVICES) \ |
| 93 | (sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL) + ((MAXDEVICES) * \ |
| 94 | sizeof(ULTRA_VBUS_DEVICEINFO))) |
| 95 | #define VBUS_CH_SIZE(MAXDEVICES) COVER(VBUS_CH_SIZE_EXACT(MAXDEVICES), 4096) |
| 96 | |
| 97 | static INLINE void |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 98 | ULTRA_VBUS_init_channel(ULTRA_VBUS_CHANNEL_PROTOCOL __iomem *x, |
| 99 | int bytesAllocated) |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 100 | { |
| 101 | /* Please note that the memory at <x> does NOT necessarily have space |
| 102 | * for DevInfo structs allocated at the end, which is why we do NOT use |
| 103 | * <bytesAllocated> to clear. */ |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 104 | memset_io(x, 0, sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL)); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 105 | if (bytesAllocated < (int) sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL)) |
| 106 | return; |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 107 | writel(ULTRA_VBUS_CHANNEL_PROTOCOL_VERSIONID, |
| 108 | &x->ChannelHeader.VersionId); |
| 109 | writeq(ULTRA_VBUS_CHANNEL_PROTOCOL_SIGNATURE, |
| 110 | &x->ChannelHeader.Signature); |
| 111 | writel(CHANNELSRV_READY, &x->ChannelHeader.SrvState); |
| 112 | writel(sizeof(x->ChannelHeader), &x->ChannelHeader.HeaderSize); |
| 113 | writeq(bytesAllocated, &x->ChannelHeader.Size); |
| 114 | memcpy_toio(&x->ChannelHeader.Type, &UltraVbusChannelProtocolGuid, |
| 115 | sizeof(x->ChannelHeader.Type)); |
Benjamin Romer | 90addb0 | 2014-05-06 09:58:23 -0400 | [diff] [blame^] | 116 | memcpy_toio(&x->ChannelHeader.ZoneGuid, &NULL_UUID_LE, sizeof(uuid_le)); |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 117 | writel(sizeof(ULTRA_VBUS_HEADERINFO), &x->HdrInfo.structBytes); |
| 118 | writel(sizeof(ULTRA_VBUS_HEADERINFO), &x->HdrInfo.chpInfoByteOffset); |
| 119 | writel(readl(&x->HdrInfo.chpInfoByteOffset) + |
| 120 | sizeof(ULTRA_VBUS_DEVICEINFO), |
| 121 | &x->HdrInfo.busInfoByteOffset); |
| 122 | writel(readl(&x->HdrInfo.busInfoByteOffset) |
| 123 | + sizeof(ULTRA_VBUS_DEVICEINFO), |
| 124 | &x->HdrInfo.devInfoByteOffset); |
| 125 | writel(sizeof(ULTRA_VBUS_DEVICEINFO), |
| 126 | &x->HdrInfo.deviceInfoStructBytes); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 127 | bytesAllocated -= (sizeof(ULTRA_CHANNEL_PROTOCOL) |
Ken Cox | a8d7f21 | 2014-03-13 15:39:19 -0500 | [diff] [blame] | 128 | + readl(&x->HdrInfo.devInfoByteOffset)); |
| 129 | writel(bytesAllocated / readl(&x->HdrInfo.deviceInfoStructBytes), |
| 130 | &x->HdrInfo.devInfoCount); |
Ken Cox | 12e364b | 2014-03-04 07:58:07 -0600 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | #pragma pack(pop) |
| 134 | |
| 135 | #endif |