1f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell/*
2f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Copyright (c) 2009 QLogic Corporation. All rights reserved.
3f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *
4f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * This software is available to you under a choice of one of two
5f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * licenses.  You may choose to be licensed under the terms of the GNU
6f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * General Public License (GPL) Version 2, available from the file
7f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * COPYING in the main directory of this source tree, or the
8f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * OpenIB.org BSD license below:
9f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *
10f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *     Redistribution and use in source and binary forms, with or
11f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *     without modification, are permitted provided that the following
12f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *     conditions are met:
13f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *
14f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *      - Redistributions of source code must retain the above
15f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *        copyright notice, this list of conditions and the following
16f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *        disclaimer.
17f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *
18f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *      - Redistributions in binary form must reproduce the above
19f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *        copyright notice, this list of conditions and the following
20f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *        disclaimer in the documentation and/or other materials
21f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *        provided with the distribution.
22f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *
23f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * SOFTWARE.
31f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */
32f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell
33f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell#include "qib.h"
34f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell
35f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell/**
36f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * qib_pio_copy - copy data to MMIO space, in multiples of 32-bits
37f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @to: destination, in MMIO space (must be 64-bit aligned)
38f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @from: source (must be 64-bit aligned)
39f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @count: number of 32-bit quantities to copy
40f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *
41f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Copy data from kernel space to MMIO space, in multiples of 32 bits at a
42f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * time.  Order of access is not guaranteed, nor is a memory barrier
43f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * performed afterwards.
44f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */
45f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbellvoid qib_pio_copy(void __iomem *to, const void *from, size_t count)
46f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell{
47f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell#ifdef CONFIG_64BIT
48f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	u64 __iomem *dst = to;
49f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	const u64 *src = from;
50f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	const u64 *end = src + (count >> 1);
51f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell
52f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	while (src < end)
53f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell		__raw_writeq(*src++, dst++);
54f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	if (count & 1)
55f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell		__raw_writel(*(const u32 *)src, dst);
56f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell#else
57f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	u32 __iomem *dst = to;
58f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	const u32 *src = from;
59f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	const u32 *end = src + count;
60f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell
61f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell	while (src < end)
62f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell		__raw_writel(*src++, dst++);
63f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell#endif
64f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell}
65