1ddi_peek(9F)             Kernel Functions for Drivers             ddi_peek(9F)
2
3
4

NAME

6       ddi_peek,  ddi_peek8,  ddi_peek16,  ddi_peek32,  ddi_peek64, ddi_peekc,
7       ddi_peeks, ddi_peekl, ddi_peekd - read a value from a location
8

SYNOPSIS

10       #include <sys/ddi.h>
11       #include <sys/sunddi.h>
12
13
14
15       int ddi_peek8(dev_info_t *dip, int8_t *addr, int8_t *valuep);
16
17
18       int ddi_peek16(dev_info_t *dip, int16_t *addr, int16_t *valuep);
19
20
21       int ddi_peek32(dev_info_t *dip, int32_t *addr, int32_t *valuep);
22
23
24       int ddi_peek64(dev_info_t *dip, int64_t *addr, int64_t *valuep);
25
26

INTERFACE LEVEL

28       Solaris DDI  specific  (Solaris  DDI).  The  ddi_peekc(),  ddi_peeks(),
29       ddi_peekl(), and ddi_peekd() functions are obsolete. Use, respectively,
30       ddi_peek8(), ddi_peek16(), ddi_peek32(), and ddi_peek64(), instead.
31

PARAMETERS

33       dip       A pointer to the device's dev_info structure.
34
35
36       addr      Virtual address of the location to be examined.
37
38
39       valuep    Pointer to a location to hold the result. If a  null  pointer
40                 is specified, then the value read from the location will sim‐
41                 ply be discarded.
42
43

DESCRIPTION

45       These routines cautiously attempt to read a value from a specified vir‐
46       tual  address,  and  return  the  value to the caller, using the parent
47       nexus driver to assist in the process where necessary.
48
49
50       If the address is not valid, or the value cannot  be  read  without  an
51       error occurring, an error code is returned.
52
53
54       The  routines  are most useful when first trying to establish the pres‐
55       ence of a device on the system in a driver's  probe(9E)  or  attach(9E)
56       routines.
57

RETURN VALUES

59       DDI_SUCCESS    The  value at the given virtual address was successfully
60                      read, and if valuep is non-null, *valuep will have  been
61                      updated.
62
63
64       DDI_FAILURE    An  error  occurred  while  trying to read the location.
65                      *valuep is unchanged.
66
67

CONTEXT

69       These functions can be called from user, interrupt, or kernel context.
70

EXAMPLES

72       Example 1 Checking to see that the  status  register  of  a  device  is
73       mapped into the kernel address space:
74
75         if (ddi_peek8(dip, csr, (int8_t *)0) != DDI_SUCCESS) {
76                 cmn_err(CE_WARN, "Status register not mapped");
77                 return (DDI_FAILURE);
78         }
79
80
81       Example 2 Reading and logging the device type of a particular device:
82
83         int
84         xx_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
85         {
86                ...
87               /* map device registers */
88                ...
89
90               if (ddi_peek32(dip, id_addr, &id_value) != DDI_SUCCESS) {
91                       cmn_err(CE_WARN, "%s%d: cannot read device identifier",
92                         ddi_get_name(dip), ddi_get_instance(dip));
93                       goto failure;
94               } else
95                       cmn_err(CE_CONT, "!%s%d: device type 0x%x\n",
96                         ddi_get_name(dip), ddi_get_instance(dip), id_value);
97                    ...
98                    ...
99
100               ddi_report_dev(dip);
101               return (DDI_SUCCESS);
102
103         failure:
104               /* free any resources allocated */
105               ...
106               return (DDI_FAILURE);
107         }
108
109

SEE ALSO

111       attach(9E), probe(9E), ddi_poke(9F)
112
113
114       Writing Device Drivers
115

NOTES

117       The  functions  described  in this manual page previously used symbolic
118       names which specified their data access size; the function  names  have
119       been  changed so they now specify a fixed-width data size. See the fol‐
120       lowing table for the new name equivalents:
121
122
123
124
125       ┌───────────────────────────────────────────────────────────┐
126Previous Name                 New Name                     
127ddi_peekc                     ddi_peek8                    
128ddi_peeks                     ddi_peek16                   
129ddi_peekl                     ddi_peek32                   
130ddi_peekd                     ddi_peek64                   
131       └───────────────────────────────────────────────────────────┘
132
133
134
135SunOS 5.11                        16 Jan 2006                     ddi_peek(9F)
Impressum