|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /*
25: * probeAndInit.m.
26: * +probe: and init example, nrw kernel driver.
27: */
28:
29: #import "probeAndInit.h"
30:
31: /*
32: * Probe and initialization of direct device, kernel mode.
33: */
34:
35: static int myDeviceNum = 0;
36:
37: @implementation MyDevice
38:
39: /*
40: * Probe:deviceMaster: is called out during early system autoconfig when
41: * the autoconfig module finds a hardware device with a valid mapping
42: * in the internalDevMap[] table.
43: */
44: + (BOOL)probe:deviceDescription
45: {
46: MyDevice *myDev;
47: char devName[20];
48:
49: /*
50: * Instantiate and set common IODevice instance variables.
51: */
52: myDev = [self alloc];
53: [myDev setDeviceDescription:deviceDescription];
54: [myDev setUnit:myDeviceNum];
55: sprintf(devName, "myDevice%d", myDeviceNum++);
56: [myDev setName:devName];
57: [myDev setDeviceKind:"Example Driver"];
58:
59: /*
60: * Proceed with device-specific initialization.
61: */
62: if([myDev myDeviceInit]) {
63: return YES;
64: }
65: else {
66: return NO;
67: }
68: }
69:
70: /*
71: * Device-specific initialization. Returns nil on error. Assumes valid
72: * deviceDescription on entry.
73: */
74: - myDeviceInit
75: {
76: IOReturn rtn;
77: unsigned intr;
78: char location[15];
79:
80: /*
81: * ...Initialize instance variables here...
82: */
83:
84: /*
85: * Perform one-time only hardware initialization. First set up
86: * register pointer.
87: */
88: rtn = [self mapDevicePage:(vm_offset_t *)&devicePage
89: anywhere:YES
90: cache:IO_CacheOff];
91: if(rtn) {
92: IOLog("MyDevice: Error on mapDevicePage (%s)\n",
93: [self stringFromReturn:rtn]);
94: return nil;
95: }
96:
97: sprintf(location, "0x%x", (unsigned)devicePage);
98: [self setLocation:location];
99:
100: /*
101: * Clear and disable interrupts.
102: */
103: intr = chan_intr_cause(devicePage, MY_DEVICE_CHANNEL);
104: set_chan_intr_cause(devicePage, MY_DEVICE_CHANNEL, intr);
105: set_chan_intr_mask(devicePage, MY_DEVICE_CHANNEL, 0);
106: set_dev_intr_mask(devicePage, 0);
107:
108: /*
109: * Prepare for interrupt notification.
110: */
111: rtn = [self attachInterrupt];
112: if(rtn) {
113: IOLog("%s attachInterrupt returned %s\n",
114: [self stringFromReturn:rtn]);
115: return nil;
116: }
117:
118: /*
119: * Get a DMA channel.
120: */
121: rtn = [self attachChannel:MY_DEVICE_CHANNEL
122: streamMode:NO
123: bufferSize:MY_DEVICE_BUFSIZE];
124: if(rtn) {
125: IOLog("MyDevice: Error on attachChannel (%s)\n",
126: [self stringFromReturn:rtn]);
127: return nil;
128: }
129:
130: /*
131: * ...configure device-specific hardware...
132: */
133:
134: /*
135: * Enable interrupts at the channel, device, and kernel level.
136: */
137: set_chan_intr_mask(devicePage, MY_DEVICE_CHANNEL,
138: MY_DEVICE_CHAN_INTR_MASK);
139: set_dev_intr_mask(devicePage, MY_DEVICE_DEV_INTR_MASK);
140: [self enableInterruptsForChannel:MY_DEVICE_CHANNEL];
141:
142: /*
143: * Register with IODevice-level code.
144: */
145: [super init];
146: [self registerDevice];
147: return self;
148: }
149:
150: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.