source: rtems-libbsd/rtemsbsd/rtems/rtems-kernel-pci_cfgreg.c

6-freebsd-12
Last change on this file was 3c967ca, checked in by Sebastian Huber <sebastian.huber@…>, on 06/08/17 at 11:15:12

Use <sys/lock.h> provided by Newlib

  • Property mode set to 100644
File size: 3.2 KB
Line 
1#include <machine/rtems-bsd-kernel-space.h>
2
3/**
4 * @file
5 *
6 * @ingroup rtems_bsd_rtems
7 *
8 * @brief This is the rtems version for the FreeBSD cpu specific
9 * file pci_cfgreg.c.  Please note that the Ether Express is not
10 * supported in this version.
11 */
12
13/*
14 * COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR).
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 *    notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 *    notice, this list of conditions and the following disclaimer in the
24 *    documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39#include <sys/cdefs.h>
40__FBSDID("$FreeBSD$");
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/bus.h>
45#include <sys/lock.h>
46#include <sys/kernel.h>
47#include <sys/malloc.h>
48#include <sys/sysctl.h>
49#include <dev/pci/pcivar.h>
50#include <dev/pci/pcireg.h>
51#define pci_find_device rtems_pci_find_device
52#if HAVE_RTEMS_PCI_H
53#include <rtems/pci.h>
54#endif
55
56/*
57 * Initialise access to PCI configuration space
58 */
59int
60pci_cfgregopen(void)
61{
62  return(1);
63}
64
65/*
66 * Read configuration space register
67 */
68u_int32_t
69pci_cfgregread(int bus, int slot, int func, int reg, int bytes)
70{
71#if HAVE_RTEMS_PCI_H
72  u_int32_t value;
73  uint8_t   v8;
74  uint16_t  v16;
75  uint32_t  v32;
76  int       data;
77
78  switch (bytes) {
79    case 1:
80      data = pci_read_config_byte( bus, slot, func, reg, &v8 );
81      value = v8;
82      break;
83    case 2:
84      data = pci_read_config_word( bus, slot, func, reg, &v16 );
85      value = v16;
86      break;
87    case 4:
88      data = pci_read_config_dword( bus, slot, func, reg, &v32 );
89      value = v32;
90      break;
91  }
92
93  return value;
94#else
95  return 0;
96#endif
97}
98
99/*
100 * Write configuration space register
101 */
102void
103pci_cfgregwrite(int bus, int slot, int func, int reg, u_int32_t data, int bytes)
104{
105#if HAVE_RTEMS_PCI_H
106  uint8_t   v8  = data & 0xff;
107  uint16_t  v16 = data & 0xffff;
108  uint32_t  v32 = data;
109
110  switch (bytes) {
111    case 1:
112      pci_write_config_byte( bus, slot, func, reg, v8 );
113      break;
114    case 2:
115      pci_write_config_word( bus, slot, func, reg, v16 );
116      break;
117    case 4:
118      pci_write_config_dword( bus, slot, func, reg, v32 );
119      break;
120  }
121#endif
122}
Note: See TracBrowser for help on using the repository browser.