Skip to contentSkip to conversation

Move runnable examples code from Documentation to samples

PATCH In review Shuah Khan 5 participants 9 messages Sep 21, 2016

Subsystems (4)
lore
Share & tools
lore

Shuah Khan

author
#0 lore raw

v2 cover Move runnable examples code from Documentation to samples

Move runnable examples code from Documentation to samples. I moved just the example code, and left documentation files as is.

I dropped accounting, laptops, and pcmcia from this v2 series as per the v1 feedback on these being a better fit under tools. I will send a separate v2 for them.

If v2 patches look good, and if I get an okay, I will try to get these into 4.9-rc1

Changes since v1:
- Updated location information in .txt for timers, watchdog, and auxdisplay
- Updated MAINTAINERS file for misc-devices/mei based on feedback from Tomas Winkler
- Added Acked-by from Jon Corbet for timers, and misc-devices/mei

Shuah Khan (4):
samples: move misc-devices/mei example code from Documentation
samples: move timers example code from Documentation
samples: move watchdog example code from Documentation
samples: move auxdisplay example code from Documentation

 Documentation/Makefile                           |   4 +-
 Documentation/auxdisplay/.gitignore              |   1 -
 Documentation/auxdisplay/Makefile                |   7 -
 Documentation/auxdisplay/cfag12864b              |   2 +-
 Documentation/auxdisplay/cfag12864b-example.c    | 281 -------------
 Documentation/misc-devices/Makefile              |   1 -
 Documentation/misc-devices/mei/.gitignore        |   1 -
 Documentation/misc-devices/mei/Makefile          |   5 -
 Documentation/misc-devices/mei/TODO              |   2 -
 Documentation/misc-devices/mei/mei-amt-version.c | 479 -----------------------
 Documentation/timers/.gitignore                  |   1 -
 Documentation/timers/Makefile                    |   5 -
 Documentation/timers/hpet.txt                    |   2 +-
 Documentation/timers/hpet_example.c              | 294 --------------
 Documentation/watchdog/Makefile                  |   1 -
 Documentation/watchdog/src/.gitignore            |   1 -
 Documentation/watchdog/src/Makefile              |   5 -
 Documentation/watchdog/src/watchdog-simple.c     |  24 --
 Documentation/watchdog/watchdog-api.txt          |   2 +-
 Documentation/watchdog/wdt.txt                   |   2 +-
 MAINTAINERS                                      |   1 +
 samples/auxdisplay/.gitignore                    |   1 +
 samples/auxdisplay/Makefile                      |   9 +
 samples/auxdisplay/cfag12864b-example.c          | 281 +++++++++++++
 samples/mei/.gitignore                           |   1 +
 samples/mei/Makefile                             |   9 +
 samples/mei/TODO                                 |   2 +
 samples/mei/mei-amt-version.c                    | 479 +++++++++++++++++++++++
 samples/timers/.gitignore                        |   1 +
 samples/timers/Makefile                          |  15 +
 samples/timers/hpet_example.c                    | 294 ++++++++++++++
 samples/watchdog/.gitignore                      |   1 +
 samples/watchdog/Makefile                        |   8 +
 samples/watchdog/watchdog-simple.c               |  24 ++
 34 files changed, 1132 insertions(+), 1114 deletions(-)
 delete mode 100644 Documentation/auxdisplay/.gitignore
 delete mode 100644 Documentation/auxdisplay/Makefile
 delete mode 100644 Documentation/auxdisplay/cfag12864b-example.c
 delete mode 100644 Documentation/misc-devices/Makefile
 delete mode 100644 Documentation/misc-devices/mei/.gitignore
 delete mode 100644 Documentation/misc-devices/mei/Makefile
 delete mode 100644 Documentation/misc-devices/mei/TODO
 delete mode 100644 Documentation/misc-devices/mei/mei-amt-version.c
 delete mode 100644 Documentation/timers/.gitignore
 delete mode 100644 Documentation/timers/Makefile
 delete mode 100644 Documentation/timers/hpet_example.c
 delete mode 100644 Documentation/watchdog/Makefile
 delete mode 100644 Documentation/watchdog/src/.gitignore
 delete mode 100644 Documentation/watchdog/src/Makefile
 delete mode 100644 Documentation/watchdog/src/watchdog-simple.c
 create mode 100644 samples/auxdisplay/.gitignore
 create mode 100644 samples/auxdisplay/Makefile
 create mode 100644 samples/auxdisplay/cfag12864b-example.c
 create mode 100644 samples/mei/.gitignore
 create mode 100644 samples/mei/Makefile
 create mode 100644 samples/mei/TODO
 create mode 100644 samples/mei/mei-amt-version.c
 create mode 100644 samples/timers/.gitignore
 create mode 100644 samples/timers/Makefile
 create mode 100644 samples/timers/hpet_example.c
 create mode 100644 samples/watchdog/.gitignore
 create mode 100644 samples/watchdog/Makefile
 create mode 100644 samples/watchdog/watchdog-simple.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/4 samples: move misc-devices/mei example code from Documentation

Move misc-devices/mei examples to samples/mei and remove it from Documentation Makefile. Delete misc-devices/Makefile.

Create a new Makefile to build samples/mei. It can be built from top level directory or from mei directory:

Run make -C samples/mei or cd samples/mei; make

---
 Documentation/Makefile                           |   2 +-
 Documentation/misc-devices/Makefile              |   1 -
 Documentation/misc-devices/mei/.gitignore        |   1 -
 Documentation/misc-devices/mei/Makefile          |   5 -
 Documentation/misc-devices/mei/TODO              |   2 -
 Documentation/misc-devices/mei/mei-amt-version.c | 479 -----------------------
 MAINTAINERS                                      |   1 +
 samples/mei/.gitignore                           |   1 +
 samples/mei/Makefile                             |   9 +
 samples/mei/TODO                                 |   2 +
 samples/mei/mei-amt-version.c                    | 479 +++++++++++++++++++++++
 11 files changed, 493 insertions(+), 489 deletions(-)
 delete mode 100644 Documentation/misc-devices/Makefile
 delete mode 100644 Documentation/misc-devices/mei/.gitignore
 delete mode 100644 Documentation/misc-devices/mei/Makefile
 delete mode 100644 Documentation/misc-devices/mei/TODO
 delete mode 100644 Documentation/misc-devices/mei/mei-amt-version.c
 create mode 100644 samples/mei/.gitignore
 create mode 100644 samples/mei/Makefile
 create mode 100644 samples/mei/TODO
 create mode 100644 samples/mei/mei-amt-version.c
Documentation/Makefile +1 -1
index 80b5bdc..3c2a207 100644
@@ -1,2 +1,2 @@
 subdir-y := accounting auxdisplay blackfin \
-	laptops misc-devices pcmcia timers watchdog
+	laptops pcmcia timers watchdog
Documentation/misc-devices/Makefile deleted +0 -1
deleted file mode 100644
index e2b7aa4..0000000
@@ -1 +0,0 @@
-subdir-y := mei
Documentation/misc-devices/mei/.gitignore deleted +0 -1
deleted file mode 100644
index f356b81..0000000
@@ -1 +0,0 @@
-mei-amt-version
Documentation/misc-devices/mei/Makefile deleted +0 -5
deleted file mode 100644
index d758047..0000000
@@ -1,5 +0,0 @@
-# List of programs to build
-hostprogs-y := mei-amt-version
-HOSTCFLAGS_mei-amt-version.o += -I$(objtree)/usr/include
-# Tell kbuild to always build the programs
-always := $(hostprogs-y)
Documentation/misc-devices/mei/TODO deleted +0 -2
deleted file mode 100644
index 6b3625d..0000000
@@ -1,2 +0,0 @@
-TODO:
-	- Cleanup and split the timer function
Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -479

479 lines not on this page · raw message

MAINTAINERS +1 -0
index a5e1270..afd3577 100644
@@ -6261,6 +6261,7 @@ F:	include/linux/mei_cl_bus.h
 F:	drivers/misc/mei/*
 F:	drivers/watchdog/mei_wdt.c
 F:	Documentation/misc-devices/mei/*
+F:	samples/mei/*
 
 INTEL MIC DRIVERS (mic)
 M:	Sudeep Dutt <[email protected]>
samples/mei/.gitignore new file +1 -0
new file mode 100644
index 0000000..f356b81
@@ -0,0 +1 @@
+mei-amt-version
samples/mei/Makefile new file +9 -0
new file mode 100644
index 0000000..7aac216
@@ -0,0 +1,9 @@
+CC := $(CROSS_COMPILE)gcc
+CFLAGS := -I../../usr/include
+
+PROGS := mei-amt-version
+
+all: $(PROGS)
+
+clean:
+	rm -fr $(PROGS)
samples/mei/TODO new file +2 -0
new file mode 100644
index 0000000..6b3625d
@@ -0,0 +1,2 @@
+TODO:
+	- Cleanup and split the timer function
samples/mei/mei-amt-version.c new file +479 -0

479 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] samples: move misc-devices/mei example code from Documentation

Quoted 11 lines · Shuah Khan

Move misc-devices/mei examples to samples/mei and remove it from Documentation Makefile. Delete misc-devices/Makefile.

Create a new Makefile to build samples/mei. It can be built from top level directory or from mei directory:

Run make -C samples/mei or cd samples/mei; make

---

Acked-by on v2 1/4
#3 lore raw

RE: [PATCH v2 1/4] samples: move misc-devices/mei example code from Documentation

In reply to Shuah Khan
Quoted 11 lines

Move misc-devices/mei examples to samples/mei and remove it from Documentation Makefile. Delete misc-devices/Makefile.

Create a new Makefile to build samples/mei. It can be built from top level directory or from mei directory:

Run make -C samples/mei or cd samples/mei; make

Quoted 1,149 lines
---
 Documentation/Makefile                           |   2 +-
 Documentation/misc-devices/Makefile              |   1 -
 Documentation/misc-devices/mei/.gitignore        |   1 -
 Documentation/misc-devices/mei/Makefile          |   5 -
 Documentation/misc-devices/mei/TODO              |   2 -
 Documentation/misc-devices/mei/mei-amt-version.c | 479 --------------------
---
 MAINTAINERS                                      |   1 +
 samples/mei/.gitignore                           |   1 +
 samples/mei/Makefile                             |   9 +
 samples/mei/TODO                                 |   2 +
 samples/mei/mei-amt-version.c                    | 479
+++++++++++++++++++++++
 11 files changed, 493 insertions(+), 489 deletions(-)  delete mode 100644
Documentation/misc-devices/Makefile
 delete mode 100644 Documentation/misc-devices/mei/.gitignore
 delete mode 100644 Documentation/misc-devices/mei/Makefile
 delete mode 100644 Documentation/misc-devices/mei/TODO
 delete mode 100644 Documentation/misc-devices/mei/mei-amt-version.c
 create mode 100644 samples/mei/.gitignore  create mode 100644

samples/mei/Makefile create mode 100644 samples/mei/TODO create mode 100644 samples/mei/mei-amt-version.c

Documentation/Makefile index renamed from Documentation/Makefile +0 -0

80b5bdc..3c2a207 100644

Documentation/Makefile +1 -1
@@ -1,2 +1,2 @@
 subdir-y := accounting auxdisplay blackfin \
-	laptops misc-devices pcmcia timers watchdog
+	laptops pcmcia timers watchdog
Documentation/misc- renamed from Documentation/misc-devices/Makefile +0 -0

devices/Makefile
deleted file mode 100644
index e2b7aa4..0000000

Documentation/misc-devices/Makefile deleted +0 -1
@@ -1 +0,0 @@
-subdir-y := mei
Documentation/misc-devices/mei/.gitignore deleted +0 -1
deleted file mode 100644
index f356b81..0000000
@@ -1 +0,0 @@
-mei-amt-version
Documentation/misc-devices/mei/Makefile deleted +0 -3
deleted file mode 100644
index d758047..0000000
@@ -1,5 +0,0 @@
-# List of programs to build
-hostprogs-y := mei-amt-version
-HOSTCFLAGS_mei-amt-version.o += -I$(objtree)/usr/include -# Tell kbuild

to always build the programs -always := $(hostprogs-y) diff --git a/Documentation/misc-devices/mei/TODO b/Documentation/misc- devices/mei/TODO
deleted file mode 100644
index 6b3625d..0000000

Documentation/misc-devices/mei/TODO deleted +0 -2
@@ -1,2 +0,0 @@
-TODO:
-	- Cleanup and split the timer function
Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -1
deleted file mode 100644
index 57d0d87..0000000
@@ -1,479 +0,0 @@
-

/**********************************************************
********************
- * Intel Management Engine Interface (Intel MEI) Linux driver
- * Intel MEI Interface Header
- *
- * This file is provided under a dual BSD/GPLv2 license. When using or
- * redistributing this file, you may do so under either license.
- *
- * GPL LICENSE SUMMARY
- *
- * Copyright(c) 2012 Intel Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
- * USA
- *
- * The full GNU General Public License is included in this distribution
- * in the file called LICENSE.GPL.
- *
- * Contact Information:
- * Intel Corporation.
- * [email protected]
- * http://www.intel.com
- *
- * BSD LICENSE
- *
- * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright

- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.

- * * Neither the name Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
-
**********************************************************
*******************/

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -14
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <bits/wordsize.h>
-#include <linux/mei.h>
-
-

/**********************************************************
*******************
- * Intel Management Engine Interface
-
**********************************************************
*******************/

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -41
-
-#define mei_msg(_me, fmt, ARGS...) do {         \
-	if (_me->verbose)                       \
-		fprintf(stderr, fmt, ##ARGS);	\
-} while (0)
-
-#define mei_err(_me, fmt, ARGS...) do {         \
-	fprintf(stderr, "Error: " fmt, ##ARGS); \
-} while (0)
-
-struct mei {
-	uuid_le guid;
-	bool initialized;
-	bool verbose;
-	unsigned int buf_size;
-	unsigned char prot_ver;
-	int fd;
-};
-
-static void mei_deinit(struct mei *cl)
-{
-	if (cl->fd != -1)
-		close(cl->fd);
-	cl->fd = -1;
-	cl->buf_size = 0;
-	cl->prot_ver = 0;
-	cl->initialized = false;
-}
-
-static bool mei_init(struct mei *me, const uuid_le *guid,
-		unsigned char req_protocol_version, bool verbose)
-{
-	int result;
-	struct mei_client *cl;
-	struct mei_connect_client_data data;
-
-	me->verbose = verbose;
-
-	me->fd = open("/dev/mei", O_RDWR);
-	if (me->fd == -1) {
-		mei_err(me, "Cannot establish a handle to the Intel MEI

driver\n");

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -10
-		goto err;
-	}
-	memcpy(&me->guid, guid, sizeof(*guid));
-	memset(&data, 0, sizeof(data));
-	me->initialized = true;
-
-	memcpy(&data.in_client_uuid, &me->guid, sizeof(me->guid));
-	result = ioctl(me->fd, IOCTL_MEI_CONNECT_CLIENT, &data);
-	if (result) {
-		mei_err(me, "IOCTL_MEI_CONNECT_CLIENT receive

message. err=%d\n", result);

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -82
-		goto err;
-	}
-	cl = &data.out_client_properties;
-	mei_msg(me, "max_message_length %d\n", cl->max_msg_length);
-	mei_msg(me, "protocol_version %d\n", cl->protocol_version);
-
-	if ((req_protocol_version > 0) &&
-	     (cl->protocol_version != req_protocol_version)) {
-		mei_err(me, "Intel MEI protocol version not supported\n");
-		goto err;
-	}
-
-	me->buf_size = cl->max_msg_length;
-	me->prot_ver = cl->protocol_version;
-
-	return true;
-err:
-	mei_deinit(me);
-	return false;
-}
-
-static ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer,
-			ssize_t len, unsigned long timeout)
-{
-	ssize_t rc;
-
-	mei_msg(me, "call read length = %zd\n", len);
-
-	rc = read(me->fd, buffer, len);
-	if (rc < 0) {
-		mei_err(me, "read failed with status %zd %s\n",
-				rc, strerror(errno));
-		mei_deinit(me);
-	} else {
-		mei_msg(me, "read succeeded with result %zd\n", rc);
-	}
-	return rc;
-}
-
-static ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer,
-			ssize_t len, unsigned long timeout)
-{
-	struct timeval tv;
-	ssize_t written;
-	ssize_t rc;
-	fd_set set;
-
-	tv.tv_sec = timeout / 1000;
-	tv.tv_usec = (timeout % 1000) * 1000000;
-
-	mei_msg(me, "call write length = %zd\n", len);
-
-	written = write(me->fd, buffer, len);
-	if (written < 0) {
-		rc = -errno;
-		mei_err(me, "write failed with status %zd %s\n",
-			written, strerror(errno));
-		goto out;
-	}
-
-	FD_ZERO(&set);
-	FD_SET(me->fd, &set);
-	rc = select(me->fd + 1 , &set, NULL, NULL, &tv);
-	if (rc > 0 && FD_ISSET(me->fd, &set)) {
-		mei_msg(me, "write success\n");
-	} else if (rc == 0) {
-		mei_err(me, "write failed on timeout with status\n");
-		goto out;
-	} else { /* rc < 0 */
-		mei_err(me, "write failed on select with status %zd\n", rc);
-		goto out;
-	}
-
-	rc = written;
-out:
-	if (rc < 0)
-		mei_deinit(me);
-
-	return rc;
-}
-
-

/**********************************************************
*****************
- * Intel Advanced Management Technology ME Client -
**********************************************************
*****************/

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -40
-
-#define AMT_MAJOR_VERSION 1
-#define AMT_MINOR_VERSION 1
-
-#define AMT_STATUS_SUCCESS                0x0
-#define AMT_STATUS_INTERNAL_ERROR         0x1
-#define AMT_STATUS_NOT_READY              0x2
-#define AMT_STATUS_INVALID_AMT_MODE       0x3
-#define AMT_STATUS_INVALID_MESSAGE_LENGTH 0x4
-
-#define AMT_STATUS_HOST_IF_EMPTY_RESPONSE  0x4000
-#define AMT_STATUS_SDK_RESOURCES      0x1004
-
-
-#define AMT_BIOS_VERSION_LEN   65
-#define AMT_VERSIONS_NUMBER    50
-#define AMT_UNICODE_STRING_LEN 20
-
-struct amt_unicode_string {
-	uint16_t length;
-	char string[AMT_UNICODE_STRING_LEN];
-} __attribute__((packed));
-
-struct amt_version_type {
-	struct amt_unicode_string description;
-	struct amt_unicode_string version;
-} __attribute__((packed));
-
-struct amt_version {
-	uint8_t major;
-	uint8_t minor;
-} __attribute__((packed));
-
-struct amt_code_versions {
-	uint8_t bios[AMT_BIOS_VERSION_LEN];
-	uint32_t count;
-	struct amt_version_type versions[AMT_VERSIONS_NUMBER];
-} __attribute__((packed));
-
-

/**********************************************************
*****************
- * Intel Advanced Management Technology Host Interface -
**********************************************************
*****************/

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -18
-
-struct amt_host_if_msg_header {
-	struct amt_version version;
-	uint16_t _reserved;
-	uint32_t command;
-	uint32_t length;
-} __attribute__((packed));
-
-struct amt_host_if_resp_header {
-	struct amt_host_if_msg_header header;
-	uint32_t status;
-	unsigned char data[0];
-} __attribute__((packed));
-
-const uuid_le MEI_IAMTHIF = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d,  \
-				0xac, 0xa8, 0x46, 0xe0, 0xff, 0x65, 0x81, 0x4c);
-
-#define AMT_HOST_IF_CODE_VERSIONS_REQUEST  0x0400001A -#define

AMT_HOST_IF_CODE_VERSIONS_RESPONSE 0x0480001A

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -21
-
-const struct amt_host_if_msg_header CODE_VERSION_REQ = {
-	.version = {AMT_MAJOR_VERSION, AMT_MINOR_VERSION},
-	._reserved = 0,
-	.command = AMT_HOST_IF_CODE_VERSIONS_REQUEST,
-	.length = 0
-};
-
-
-struct amt_host_if {
-	struct mei mei_cl;
-	unsigned long send_timeout;
-	bool initialized;
-};
-
-
-static bool amt_host_if_init(struct amt_host_if *acmd,
-		      unsigned long send_timeout, bool verbose)
-{
-	acmd->send_timeout = (send_timeout) ? send_timeout : 20000;
-	acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0,

verbose);

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -9
-	return acmd->initialized;
-}
-
-static void amt_host_if_deinit(struct amt_host_if *acmd) -{
-	mei_deinit(&acmd->mei_cl);
-	acmd->initialized = false;
-}
-
-static uint32_t amt_verify_code_versions(const struct

amt_host_if_resp_header *resp) -{

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -14
-	uint32_t status = AMT_STATUS_SUCCESS;
-	struct amt_code_versions *code_ver;
-	size_t code_ver_len;
-	uint32_t ver_type_cnt;
-	uint32_t len;
-	uint32_t i;
-
-	code_ver = (struct amt_code_versions *)resp->data;
-	/* length - sizeof(status) */
-	code_ver_len = resp->header.length - sizeof(uint32_t);
-	ver_type_cnt = code_ver_len -
-			sizeof(code_ver->bios) -
-			sizeof(code_ver->count);
-	if (code_ver->count != ver_type_cnt / sizeof(struct

amt_version_type)) {

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -25
-		status = AMT_STATUS_INTERNAL_ERROR;
-		goto out;
-	}
-
-	for (i = 0; i < code_ver->count; i++) {
-		len = code_ver->versions[i].description.length;
-
-		if (len > AMT_UNICODE_STRING_LEN) {
-			status = AMT_STATUS_INTERNAL_ERROR;
-			goto out;
-		}
-
-		len = code_ver->versions[i].version.length;
-		if (code_ver->versions[i].version.string[len] != '\0' ||
-		    len != strlen(code_ver->versions[i].version.string)) {
-			status = AMT_STATUS_INTERNAL_ERROR;
-			goto out;
-		}
-	}
-out:
-	return status;
-}
-
-static uint32_t amt_verify_response_header(uint32_t command,
-				const struct amt_host_if_msg_header

*resp_hdr,

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -20
-				uint32_t response_size)
-{
-	if (response_size < sizeof(struct amt_host_if_resp_header)) {
-		return AMT_STATUS_INTERNAL_ERROR;
-	} else if (response_size != (resp_hdr->length +
-				sizeof(struct amt_host_if_msg_header))) {
-		return AMT_STATUS_INTERNAL_ERROR;
-	} else if (resp_hdr->command != command) {
-		return AMT_STATUS_INTERNAL_ERROR;
-	} else if (resp_hdr->_reserved != 0) {
-		return AMT_STATUS_INTERNAL_ERROR;
-	} else if (resp_hdr->version.major != AMT_MAJOR_VERSION ||
-		   resp_hdr->version.minor < AMT_MINOR_VERSION) {
-		return AMT_STATUS_INTERNAL_ERROR;
-	}
-	return AMT_STATUS_SUCCESS;
-}
-
-static uint32_t amt_host_if_call(struct amt_host_if *acmd,
-			const unsigned char *command, ssize_t

command_sz,

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -18
-			uint8_t **read_buf, uint32_t rcmd,
-			unsigned int expected_sz)
-{
-	uint32_t in_buf_sz;
-	uint32_t out_buf_sz;
-	ssize_t written;
-	uint32_t status;
-	struct amt_host_if_resp_header *msg_hdr;
-
-	in_buf_sz = acmd->mei_cl.buf_size;
-	*read_buf = (uint8_t *)malloc(sizeof(uint8_t) * in_buf_sz);
-	if (*read_buf == NULL)
-		return AMT_STATUS_SDK_RESOURCES;
-	memset(*read_buf, 0, in_buf_sz);
-	msg_hdr = (struct amt_host_if_resp_header *)*read_buf;
-
-	written = mei_send_msg(&acmd->mei_cl,
-				command, command_sz, acmd-
Quoted 1 line

send_timeout);

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -4
-	if (written != command_sz)
-		return AMT_STATUS_INTERNAL_ERROR;
-
-	out_buf_sz = mei_recv_msg(&acmd->mei_cl, *read_buf, in_buf_sz,

2000);

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -39
-	if (out_buf_sz <= 0)
-		return AMT_STATUS_HOST_IF_EMPTY_RESPONSE;
-
-	status = msg_hdr->status;
-	if (status != AMT_STATUS_SUCCESS)
-		return status;
-
-	status = amt_verify_response_header(rcmd,
-				&msg_hdr->header, out_buf_sz);
-	if (status != AMT_STATUS_SUCCESS)
-		return status;
-
-	if (expected_sz && expected_sz != out_buf_sz)
-		return AMT_STATUS_INTERNAL_ERROR;
-
-	return AMT_STATUS_SUCCESS;
-}
-
-
-static uint32_t amt_get_code_versions(struct amt_host_if *cmd,
-			       struct amt_code_versions *versions)
-{
-	struct amt_host_if_resp_header *response = NULL;
-	uint32_t status;
-
-	status = amt_host_if_call(cmd,
-			(const unsigned char *)&CODE_VERSION_REQ,
-			sizeof(CODE_VERSION_REQ),
-			(uint8_t **)&response,
-			AMT_HOST_IF_CODE_VERSIONS_RESPONSE, 0);
-
-	if (status != AMT_STATUS_SUCCESS)
-		goto out;
-
-	status = amt_verify_code_versions(response);
-	if (status != AMT_STATUS_SUCCESS)
-		goto out;
-
-	memcpy(versions, response->data, sizeof(struct

amt_code_versions));

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -8
-out:
-	if (response != NULL)
-		free(response);
-
-	return status;
-}
-
-/************************** end of amt_host_if_command

***********************/ -int main(int argc, char **argv) -{

Documentation/misc-devices/mei/mei-amt-version.c deleted +0 -40
-	struct amt_code_versions ver;
-	struct amt_host_if acmd;
-	unsigned int i;
-	uint32_t status;
-	int ret;
-	bool verbose;
-
-	verbose = (argc > 1 && strcmp(argv[1], "-v") == 0);
-
-	if (!amt_host_if_init(&acmd, 5000, verbose)) {
-		ret = 1;
-		goto out;
-	}
-
-	status = amt_get_code_versions(&acmd, &ver);
-
-	amt_host_if_deinit(&acmd);
-
-	switch (status) {
-	case AMT_STATUS_HOST_IF_EMPTY_RESPONSE:
-		printf("Intel AMT: DISABLED\n");
-		ret = 0;
-		break;
-	case AMT_STATUS_SUCCESS:
-		printf("Intel AMT: ENABLED\n");
-		for (i = 0; i < ver.count; i++) {
-			printf("%s:\t%s\n", ver.versions[i].description.string,
-				ver.versions[i].version.string);
-		}
-		ret = 0;
-		break;
-	default:
-		printf("An error has occurred\n");
-		ret = 1;
-		break;
-	}
-
-out:
-	return ret;
-}
MAINTAINERS +1 -0
index a5e1270..afd3577 100644
@@ -6261,6 +6261,7 @@ F:	include/linux/mei_cl_bus.h
 F:	drivers/misc/mei/*
 F:	drivers/watchdog/mei_wdt.c
 F:	Documentation/misc-devices/mei/*
+F:	samples/mei/*
 
 INTEL MIC DRIVERS (mic)
 M:	Sudeep Dutt <[email protected]>
samples/mei/.gitignore new file mode renamed from samples/mei/.gitignore +0 -0

100644 index 0000000..f356b81

samples/mei/.gitignore new file +1 -0
@@ -0,0 +1 @@
+mei-amt-version
samples/mei/Makefile new file mode renamed from samples/mei/Makefile +0 -0

100644 index 0000000..7aac216

samples/mei/Makefile new file +9 -0
@@ -0,0 +1,9 @@
+CC := $(CROSS_COMPILE)gcc
+CFLAGS := -I../../usr/include
+
+PROGS := mei-amt-version
+
+all: $(PROGS)
+
+clean:
+	rm -fr $(PROGS)
samples/mei/TODO new file +2 -0
index 0000000..6b3625d
@@ -0,0 +1,2 @@
+TODO:
+	- Cleanup and split the timer function
samples/mei/mei-amt- renamed from samples/mei/mei-amt-version.c +0 -0

version.c new file mode 100644 index 0000000..57d0d87

samples/mei/mei-amt-version.c new file +1 -0
@@ -0,0 +1,479 @@
+/*********************************************************

*************
+********
+ * Intel Management Engine Interface (Intel MEI) Linux driver
+ * Intel MEI Interface Header
+ *
+ * This file is provided under a dual BSD/GPLv2 license. When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2012 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
+ * USA
+ *
+ * The full GNU General Public License is included in this distribution
+ * in the file called LICENSE.GPL.
+ *
+ * Contact Information:
+ * Intel Corporation.
+ * [email protected]
+ * http://www.intel.com
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright

+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.

+ * * Neither the name Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *

samples/mei/mei-amt-version.c new file +2 -0
+
+*********************************************************

**************

samples/mei/mei-amt-version.c new file +15 -0
+******/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <bits/wordsize.h>
+#include <linux/mei.h>
+
+/*********************************************************

*************

samples/mei/mei-amt-version.c new file +4 -0
+*******
+ * Intel Management Engine Interface
+
+*********************************************************

**************

samples/mei/mei-amt-version.c new file +40 -0
+******/
+
+#define mei_msg(_me, fmt, ARGS...) do {         \
+	if (_me->verbose)                       \
+		fprintf(stderr, fmt, ##ARGS);	\
+} while (0)
+
+#define mei_err(_me, fmt, ARGS...) do {         \
+	fprintf(stderr, "Error: " fmt, ##ARGS); \ } while (0)
+
+struct mei {
+	uuid_le guid;
+	bool initialized;
+	bool verbose;
+	unsigned int buf_size;
+	unsigned char prot_ver;
+	int fd;
+};
+
+static void mei_deinit(struct mei *cl)
+{
+	if (cl->fd != -1)
+		close(cl->fd);
+	cl->fd = -1;
+	cl->buf_size = 0;
+	cl->prot_ver = 0;
+	cl->initialized = false;
+}
+
+static bool mei_init(struct mei *me, const uuid_le *guid,
+		unsigned char req_protocol_version, bool verbose) {
+	int result;
+	struct mei_client *cl;
+	struct mei_connect_client_data data;
+
+	me->verbose = verbose;
+
+	me->fd = open("/dev/mei", O_RDWR);
+	if (me->fd == -1) {
+		mei_err(me, "Cannot establish a handle to the Intel MEI

driver\n");

samples/mei/mei-amt-version.c new file +10 -0
+		goto err;
+	}
+	memcpy(&me->guid, guid, sizeof(*guid));
+	memset(&data, 0, sizeof(data));
+	me->initialized = true;
+
+	memcpy(&data.in_client_uuid, &me->guid, sizeof(me->guid));
+	result = ioctl(me->fd, IOCTL_MEI_CONNECT_CLIENT, &data);
+	if (result) {
+		mei_err(me, "IOCTL_MEI_CONNECT_CLIENT receive

message. err=%d\n", result);

samples/mei/mei-amt-version.c new file +82 -0
+		goto err;
+	}
+	cl = &data.out_client_properties;
+	mei_msg(me, "max_message_length %d\n", cl->max_msg_length);
+	mei_msg(me, "protocol_version %d\n", cl->protocol_version);
+
+	if ((req_protocol_version > 0) &&
+	     (cl->protocol_version != req_protocol_version)) {
+		mei_err(me, "Intel MEI protocol version not supported\n");
+		goto err;
+	}
+
+	me->buf_size = cl->max_msg_length;
+	me->prot_ver = cl->protocol_version;
+
+	return true;
+err:
+	mei_deinit(me);
+	return false;
+}
+
+static ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer,
+			ssize_t len, unsigned long timeout)
+{
+	ssize_t rc;
+
+	mei_msg(me, "call read length = %zd\n", len);
+
+	rc = read(me->fd, buffer, len);
+	if (rc < 0) {
+		mei_err(me, "read failed with status %zd %s\n",
+				rc, strerror(errno));
+		mei_deinit(me);
+	} else {
+		mei_msg(me, "read succeeded with result %zd\n", rc);
+	}
+	return rc;
+}
+
+static ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer,
+			ssize_t len, unsigned long timeout)
+{
+	struct timeval tv;
+	ssize_t written;
+	ssize_t rc;
+	fd_set set;
+
+	tv.tv_sec = timeout / 1000;
+	tv.tv_usec = (timeout % 1000) * 1000000;
+
+	mei_msg(me, "call write length = %zd\n", len);
+
+	written = write(me->fd, buffer, len);
+	if (written < 0) {
+		rc = -errno;
+		mei_err(me, "write failed with status %zd %s\n",
+			written, strerror(errno));
+		goto out;
+	}
+
+	FD_ZERO(&set);
+	FD_SET(me->fd, &set);
+	rc = select(me->fd + 1 , &set, NULL, NULL, &tv);
+	if (rc > 0 && FD_ISSET(me->fd, &set)) {
+		mei_msg(me, "write success\n");
+	} else if (rc == 0) {
+		mei_err(me, "write failed on timeout with status\n");
+		goto out;
+	} else { /* rc < 0 */
+		mei_err(me, "write failed on select with status %zd\n", rc);
+		goto out;
+	}
+
+	rc = written;
+out:
+	if (rc < 0)
+		mei_deinit(me);
+
+	return rc;
+}
+
+/*********************************************************

*************

samples/mei/mei-amt-version.c new file +3 -0
+*****
+ * Intel Advanced Management Technology ME Client
+*********************************************************

**************

samples/mei/mei-amt-version.c new file +41 -0
+****/
+
+#define AMT_MAJOR_VERSION 1
+#define AMT_MINOR_VERSION 1
+
+#define AMT_STATUS_SUCCESS                0x0
+#define AMT_STATUS_INTERNAL_ERROR         0x1
+#define AMT_STATUS_NOT_READY              0x2
+#define AMT_STATUS_INVALID_AMT_MODE       0x3
+#define AMT_STATUS_INVALID_MESSAGE_LENGTH 0x4
+
+#define AMT_STATUS_HOST_IF_EMPTY_RESPONSE  0x4000
+#define AMT_STATUS_SDK_RESOURCES      0x1004
+
+
+#define AMT_BIOS_VERSION_LEN   65
+#define AMT_VERSIONS_NUMBER    50
+#define AMT_UNICODE_STRING_LEN 20
+
+struct amt_unicode_string {
+	uint16_t length;
+	char string[AMT_UNICODE_STRING_LEN];
+} __attribute__((packed));
+
+struct amt_version_type {
+	struct amt_unicode_string description;
+	struct amt_unicode_string version;
+} __attribute__((packed));
+
+struct amt_version {
+	uint8_t major;
+	uint8_t minor;
+} __attribute__((packed));
+
+struct amt_code_versions {
+	uint8_t bios[AMT_BIOS_VERSION_LEN];
+	uint32_t count;
+	struct amt_version_type versions[AMT_VERSIONS_NUMBER]; }
+__attribute__((packed));
+
+/*********************************************************

*************

samples/mei/mei-amt-version.c new file +3 -0
+*****
+ * Intel Advanced Management Technology Host Interface
+*********************************************************

**************

samples/mei/mei-amt-version.c new file +40 -0
+****/
+
+struct amt_host_if_msg_header {
+	struct amt_version version;
+	uint16_t _reserved;
+	uint32_t command;
+	uint32_t length;
+} __attribute__((packed));
+
+struct amt_host_if_resp_header {
+	struct amt_host_if_msg_header header;
+	uint32_t status;
+	unsigned char data[0];
+} __attribute__((packed));
+
+const uuid_le MEI_IAMTHIF = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d,  \
+				0xac, 0xa8, 0x46, 0xe0, 0xff, 0x65, 0x81, 0x4c);
+
+#define AMT_HOST_IF_CODE_VERSIONS_REQUEST  0x0400001A #define
+AMT_HOST_IF_CODE_VERSIONS_RESPONSE 0x0480001A
+
+const struct amt_host_if_msg_header CODE_VERSION_REQ = {
+	.version = {AMT_MAJOR_VERSION, AMT_MINOR_VERSION},
+	._reserved = 0,
+	.command = AMT_HOST_IF_CODE_VERSIONS_REQUEST,
+	.length = 0
+};
+
+
+struct amt_host_if {
+	struct mei mei_cl;
+	unsigned long send_timeout;
+	bool initialized;
+};
+
+
+static bool amt_host_if_init(struct amt_host_if *acmd,
+		      unsigned long send_timeout, bool verbose) {
+	acmd->send_timeout = (send_timeout) ? send_timeout : 20000;
+	acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0,

verbose);

samples/mei/mei-amt-version.c new file +24 -0
+	return acmd->initialized;
+}
+
+static void amt_host_if_deinit(struct amt_host_if *acmd) {
+	mei_deinit(&acmd->mei_cl);
+	acmd->initialized = false;
+}
+
+static uint32_t amt_verify_code_versions(const struct
+amt_host_if_resp_header *resp) {
+	uint32_t status = AMT_STATUS_SUCCESS;
+	struct amt_code_versions *code_ver;
+	size_t code_ver_len;
+	uint32_t ver_type_cnt;
+	uint32_t len;
+	uint32_t i;
+
+	code_ver = (struct amt_code_versions *)resp->data;
+	/* length - sizeof(status) */
+	code_ver_len = resp->header.length - sizeof(uint32_t);
+	ver_type_cnt = code_ver_len -
+			sizeof(code_ver->bios) -
+			sizeof(code_ver->count);
+	if (code_ver->count != ver_type_cnt / sizeof(struct

amt_version_type)) {

samples/mei/mei-amt-version.c new file +25 -0
+		status = AMT_STATUS_INTERNAL_ERROR;
+		goto out;
+	}
+
+	for (i = 0; i < code_ver->count; i++) {
+		len = code_ver->versions[i].description.length;
+
+		if (len > AMT_UNICODE_STRING_LEN) {
+			status = AMT_STATUS_INTERNAL_ERROR;
+			goto out;
+		}
+
+		len = code_ver->versions[i].version.length;
+		if (code_ver->versions[i].version.string[len] != '\0' ||
+		    len != strlen(code_ver->versions[i].version.string)) {
+			status = AMT_STATUS_INTERNAL_ERROR;
+			goto out;
+		}
+	}
+out:
+	return status;
+}
+
+static uint32_t amt_verify_response_header(uint32_t command,
+				const struct amt_host_if_msg_header

*resp_hdr,

samples/mei/mei-amt-version.c new file +20 -0
+				uint32_t response_size)
+{
+	if (response_size < sizeof(struct amt_host_if_resp_header)) {
+		return AMT_STATUS_INTERNAL_ERROR;
+	} else if (response_size != (resp_hdr->length +
+				sizeof(struct amt_host_if_msg_header))) {
+		return AMT_STATUS_INTERNAL_ERROR;
+	} else if (resp_hdr->command != command) {
+		return AMT_STATUS_INTERNAL_ERROR;
+	} else if (resp_hdr->_reserved != 0) {
+		return AMT_STATUS_INTERNAL_ERROR;
+	} else if (resp_hdr->version.major != AMT_MAJOR_VERSION ||
+		   resp_hdr->version.minor < AMT_MINOR_VERSION) {
+		return AMT_STATUS_INTERNAL_ERROR;
+	}
+	return AMT_STATUS_SUCCESS;
+}
+
+static uint32_t amt_host_if_call(struct amt_host_if *acmd,
+			const unsigned char *command, ssize_t

command_sz,

samples/mei/mei-amt-version.c new file +18 -0
+			uint8_t **read_buf, uint32_t rcmd,
+			unsigned int expected_sz)
+{
+	uint32_t in_buf_sz;
+	uint32_t out_buf_sz;
+	ssize_t written;
+	uint32_t status;
+	struct amt_host_if_resp_header *msg_hdr;
+
+	in_buf_sz = acmd->mei_cl.buf_size;
+	*read_buf = (uint8_t *)malloc(sizeof(uint8_t) * in_buf_sz);
+	if (*read_buf == NULL)
+		return AMT_STATUS_SDK_RESOURCES;
+	memset(*read_buf, 0, in_buf_sz);
+	msg_hdr = (struct amt_host_if_resp_header *)*read_buf;
+
+	written = mei_send_msg(&acmd->mei_cl,
+				command, command_sz, acmd-
Quoted 1 line

send_timeout);

samples/mei/mei-amt-version.c new file +4 -0
+	if (written != command_sz)
+		return AMT_STATUS_INTERNAL_ERROR;
+
+	out_buf_sz = mei_recv_msg(&acmd->mei_cl, *read_buf, in_buf_sz,

2000);

samples/mei/mei-amt-version.c new file +38 -0
+	if (out_buf_sz <= 0)
+		return AMT_STATUS_HOST_IF_EMPTY_RESPONSE;
+
+	status = msg_hdr->status;
+	if (status != AMT_STATUS_SUCCESS)
+		return status;
+
+	status = amt_verify_response_header(rcmd,
+				&msg_hdr->header, out_buf_sz);
+	if (status != AMT_STATUS_SUCCESS)
+		return status;
+
+	if (expected_sz && expected_sz != out_buf_sz)
+		return AMT_STATUS_INTERNAL_ERROR;
+
+	return AMT_STATUS_SUCCESS;
+}
+
+
+static uint32_t amt_get_code_versions(struct amt_host_if *cmd,
+			       struct amt_code_versions *versions) {
+	struct amt_host_if_resp_header *response = NULL;
+	uint32_t status;
+
+	status = amt_host_if_call(cmd,
+			(const unsigned char *)&CODE_VERSION_REQ,
+			sizeof(CODE_VERSION_REQ),
+			(uint8_t **)&response,
+			AMT_HOST_IF_CODE_VERSIONS_RESPONSE, 0);
+
+	if (status != AMT_STATUS_SUCCESS)
+		goto out;
+
+	status = amt_verify_code_versions(response);
+	if (status != AMT_STATUS_SUCCESS)
+		goto out;
+
+	memcpy(versions, response->data, sizeof(struct

amt_code_versions));

samples/mei/mei-amt-version.c new file +49 -1
+out:
+	if (response != NULL)
+		free(response);
+
+	return status;
+}
+
+/************************** end of amt_host_if_command
+***********************/ int main(int argc, char **argv) {
+	struct amt_code_versions ver;
+	struct amt_host_if acmd;
+	unsigned int i;
+	uint32_t status;
+	int ret;
+	bool verbose;
+
+	verbose = (argc > 1 && strcmp(argv[1], "-v") == 0);
+
+	if (!amt_host_if_init(&acmd, 5000, verbose)) {
+		ret = 1;
+		goto out;
+	}
+
+	status = amt_get_code_versions(&acmd, &ver);
+
+	amt_host_if_deinit(&acmd);
+
+	switch (status) {
+	case AMT_STATUS_HOST_IF_EMPTY_RESPONSE:
+		printf("Intel AMT: DISABLED\n");
+		ret = 0;
+		break;
+	case AMT_STATUS_SUCCESS:
+		printf("Intel AMT: ENABLED\n");
+		for (i = 0; i < ver.count; i++) {
+			printf("%s:\t%s\n", ver.versions[i].description.string,
+				ver.versions[i].version.string);
+		}
+		ret = 0;
+		break;
+	default:
+		printf("An error has occurred\n");
+		ret = 1;
+		break;
+	}
+
+out:
+	return ret;
+}
--

2.7.4

author
#4 lore raw

PATCH v2 2/4 samples: move timers example code from Documentation

In reply to Shuah Khan

Move timers examples to samples and remove it from Documentation Makefile. Create a new Makefile to build timers. It can be built from top level directory or from timers directory:

Run make -C samples/timers or cd samples/timers; make

---
 Documentation/Makefile              |   2 +-
 Documentation/timers/.gitignore     |   1 -
 Documentation/timers/Makefile       |   5 -
 Documentation/timers/hpet.txt       |   2 +-
 Documentation/timers/hpet_example.c | 294 ------------------------------------
 samples/timers/.gitignore           |   1 +
 samples/timers/Makefile             |  15 ++
 samples/timers/hpet_example.c       | 294 ++++++++++++++++++++++++++++++++++++
 8 files changed, 312 insertions(+), 302 deletions(-)
 delete mode 100644 Documentation/timers/.gitignore
 delete mode 100644 Documentation/timers/Makefile
 delete mode 100644 Documentation/timers/hpet_example.c
 create mode 100644 samples/timers/.gitignore
 create mode 100644 samples/timers/Makefile
 create mode 100644 samples/timers/hpet_example.c
Documentation/Makefile +1 -1
index 3c2a207..fc386b7 100644
@@ -1,2 +1,2 @@
 subdir-y := accounting auxdisplay blackfin \
-	laptops pcmcia timers watchdog
+	laptops pcmcia watchdog
Documentation/timers/.gitignore deleted +0 -1
deleted file mode 100644
index c5c45d7..0000000
@@ -1 +0,0 @@
-hpet_example
Documentation/timers/Makefile deleted +0 -5
deleted file mode 100644
index 6c09ee6..0000000
@@ -1,5 +0,0 @@
-# List of programs to build
-hostprogs-$(CONFIG_X86) := hpet_example
-
-# Tell kbuild to always build the programs
-always := $(hostprogs-y)
Documentation/timers/hpet.txt +1 -1
index a484d2c..895345e 100644
@@ -25,4 +25,4 @@ arch/x86/kernel/hpet.c.
 
 The driver provides a userspace API which resembles the API found in the
 RTC driver framework.  An example user space program is provided in
-file:Documentation/timers/hpet_example.c
+file:samples/timers/hpet_example.c
Documentation/timers/hpet_example.c deleted +0 -294

294 lines not on this page · raw message

samples/timers/.gitignore new file +1 -0
new file mode 100644
index 0000000..c5c45d7
@@ -0,0 +1 @@
+hpet_example
samples/timers/Makefile new file +15 -0
new file mode 100644
index 0000000..a5c3c4a
@@ -0,0 +1,15 @@
+ifndef CROSS_COMPILE
+uname_M := $(shell uname -m 2>/dev/null || echo not)
+ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
+
+ifeq ($(ARCH),x86)
+CC := $(CROSS_COMPILE)gcc
+PROGS := hpet_example
+
+all: $(PROGS)
+
+clean:
+	rm -fr $(PROGS)
+
+endif
+endif
samples/timers/hpet_example.c new file +294 -0

294 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v2 2/4
#5 lore raw

Re: [PATCH v2 2/4] samples: move timers example code from Documentation

Quoted 8 lines · Shuah Khan

Move timers examples to samples and remove it from Documentation Makefile. Create a new Makefile to build timers. It can be built from top level directory or from timers directory:

Run make -C samples/timers or cd samples/timers; make

author
#6 lore raw

PATCH v2 3/4 samples: move watchdog example code from Documentation

In reply to Shuah Khan

Move watchdog examples to samples and remove it from Documentation Makefile. Create a new Makefile to build watchdog. It can be built from top level directory or from watchdog directory:

Run make -C samples/watchdog or cd samples/watchdog; make

---
 Documentation/Makefile                       |  2 +-
 Documentation/watchdog/Makefile              |  1 -
 Documentation/watchdog/src/.gitignore        |  1 -
 Documentation/watchdog/src/Makefile          |  5 -----
 Documentation/watchdog/src/watchdog-simple.c | 24 ------------------------
 Documentation/watchdog/watchdog-api.txt      |  2 +-
 Documentation/watchdog/wdt.txt               |  2 +-
 samples/watchdog/.gitignore                  |  1 +
 samples/watchdog/Makefile                    |  8 ++++++++
 samples/watchdog/watchdog-simple.c           | 24 ++++++++++++++++++++++++
 10 files changed, 36 insertions(+), 34 deletions(-)
 delete mode 100644 Documentation/watchdog/Makefile
 delete mode 100644 Documentation/watchdog/src/.gitignore
 delete mode 100644 Documentation/watchdog/src/Makefile
 delete mode 100644 Documentation/watchdog/src/watchdog-simple.c
 create mode 100644 samples/watchdog/.gitignore
 create mode 100644 samples/watchdog/Makefile
 create mode 100644 samples/watchdog/watchdog-simple.c
Documentation/Makefile +1 -1
index fc386b7..b2210b7 100644
@@ -1,2 +1,2 @@
 subdir-y := accounting auxdisplay blackfin \
-	laptops pcmcia watchdog
+	laptops pcmcia
Documentation/watchdog/Makefile deleted +0 -1
deleted file mode 100644
index 6018f45..0000000
@@ -1 +0,0 @@
-subdir-y := src
Documentation/watchdog/src/.gitignore deleted +0 -1
deleted file mode 100644
index ff0ebb5..0000000
@@ -1 +0,0 @@
-watchdog-simple
Documentation/watchdog/src/Makefile deleted +0 -5
deleted file mode 100644
index 47be791..0000000
@@ -1,5 +0,0 @@
-# List of programs to build
-hostprogs-y := watchdog-simple
-
-# Tell kbuild to always build the programs
-always := $(hostprogs-y)
Documentation/watchdog/src/watchdog-simple.c deleted +0 -24
deleted file mode 100644
index ba45803..0000000
@@ -1,24 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-int main(void)
-{
-	int fd = open("/dev/watchdog", O_WRONLY);
-	int ret = 0;
-	if (fd == -1) {
-		perror("watchdog");
-		exit(EXIT_FAILURE);
-	}
-	while (1) {
-		ret = write(fd, "\0", 1);
-		if (ret != 1) {
-			ret = -1;
-			break;
-		}
-		sleep(10);
-	}
-	close(fd);
-	return ret;
-}
Documentation/watchdog/watchdog-api.txt +1 -1
index b3a701f..0e62ba3 100644
@@ -37,7 +37,7 @@ activates as soon as /dev/watchdog is opened and will reboot unless
 the watchdog is pinged within a certain time, this time is called the
 timeout or margin.  The simplest way to ping the watchdog is to write
 some data to the device.  So a very simple watchdog daemon would look
-like this source file:  see Documentation/watchdog/src/watchdog-simple.c
+like this source file:  see samples/watchdog/watchdog-simple.c
 
 A more advanced driver could for example check that a HTTP server is
 still responding before doing the write call to ping the watchdog.
Documentation/watchdog/wdt.txt +1 -1
index 061c2e3..ed2f0b8 100644
@@ -47,4 +47,4 @@ The external event interfaces on the WDT boards are not currently supported.
 Minor numbers are however allocated for it.
 
 
-Example Watchdog Driver:  see Documentation/watchdog/src/watchdog-simple.c
+Example Watchdog Driver:  see samples/watchdog/watchdog-simple.c
samples/watchdog/.gitignore new file +1 -0
new file mode 100644
index 0000000..ff0ebb5
@@ -0,0 +1 @@
+watchdog-simple
samples/watchdog/Makefile new file +8 -0
new file mode 100644
index 0000000..9b53d89
@@ -0,0 +1,8 @@
+CC := $(CROSS_COMPILE)gcc
+PROGS := watchdog-simple
+
+all: $(PROGS)
+
+clean:
+	rm -fr $(PROGS)
+
samples/watchdog/watchdog-simple.c new file +24 -0
new file mode 100644
index 0000000..ba45803
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int main(void)
+{
+	int fd = open("/dev/watchdog", O_WRONLY);
+	int ret = 0;
+	if (fd == -1) {
+		perror("watchdog");
+		exit(EXIT_FAILURE);
+	}
+	while (1) {
+		ret = write(fd, "\0", 1);
+		if (ret != 1) {
+			ret = -1;
+			break;
+		}
+		sleep(10);
+	}
+	close(fd);
+	return ret;
+}
Signature · 1 line
2.7.4
author
#7 lore raw

PATCH v2 4/4 samples: move auxdisplay example code from Documentation

In reply to Shuah Khan

Move auxdisplay examples to samples and remove it from Documentation Makefile. Create a new Makefile to build auxdisplay. It can be built from top level directory or from auxdisplay directory:

Run make -C samples/auxdisplay or cd samples/auxdisplay; make

---
 Documentation/Makefile                        |   2 +-
 Documentation/auxdisplay/.gitignore           |   1 -
 Documentation/auxdisplay/Makefile             |   7 -
 Documentation/auxdisplay/cfag12864b           |   2 +-
 Documentation/auxdisplay/cfag12864b-example.c | 281 --------------------------
 samples/auxdisplay/.gitignore                 |   1 +
 samples/auxdisplay/Makefile                   |   9 +
 samples/auxdisplay/cfag12864b-example.c       | 281 ++++++++++++++++++++++++++
 8 files changed, 293 insertions(+), 291 deletions(-)
 delete mode 100644 Documentation/auxdisplay/.gitignore
 delete mode 100644 Documentation/auxdisplay/Makefile
 delete mode 100644 Documentation/auxdisplay/cfag12864b-example.c
 create mode 100644 samples/auxdisplay/.gitignore
 create mode 100644 samples/auxdisplay/Makefile
 create mode 100644 samples/auxdisplay/cfag12864b-example.c
Documentation/Makefile +1 -1
index b2210b7..0b8cd50 100644
@@ -1,2 +1,2 @@
-subdir-y := accounting auxdisplay blackfin \
+subdir-y := accounting blackfin \
 	laptops pcmcia
Documentation/auxdisplay/.gitignore deleted +0 -1
deleted file mode 100644
index 7af2228..0000000
@@ -1 +0,0 @@
-cfag12864b-example
Documentation/auxdisplay/Makefile deleted +0 -7
deleted file mode 100644
index ada4dac..0000000
@@ -1,7 +0,0 @@
-# List of programs to build
-hostprogs-y := cfag12864b-example
-
-# Tell kbuild to always build the programs
-always := $(hostprogs-y)
-
-HOSTCFLAGS_cfag12864b-example.o += -I$(objtree)/usr/include
Documentation/auxdisplay/cfag12864b +1 -1
index eb7be39..12fd51b 100644
@@ -101,5 +101,5 @@ Although the LCD won't get updated until the next refresh time arrives.
 Also, you can mmap the framebuffer: open & mmap, munmap & close...
 which is the best option for most uses.
 
-Check Documentation/auxdisplay/cfag12864b-example.c
+Check samples/auxdisplay/cfag12864b-example.c
 for a real working userspace complete program with usage examples.
Documentation/auxdisplay/cfag12864b-example.c deleted +0 -281

281 lines not on this page · raw message

samples/auxdisplay/.gitignore new file +1 -0
new file mode 100644
index 0000000..7af2228
@@ -0,0 +1 @@
+cfag12864b-example
samples/auxdisplay/Makefile new file +9 -0
new file mode 100644
index 0000000..05e471f
@@ -0,0 +1,9 @@
+CC := $(CROSS_COMPILE)gcc
+CFLAGS := -I../../usr/include
+
+PROGS := cfag12864b-example
+
+all: $(PROGS)
+
+clean:
+	rm -fr $(PROGS)
samples/auxdisplay/cfag12864b-example.c new file +281 -0

281 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#8 lore raw
In reply to Shuah Khan
Quoted 10 lines · On Wed, 21 Sep 2016 13:47:29 -0600 Shuah Khan <[email protected]> wrote:

Move runnable examples code from Documentation to samples. I moved just the example code, and left documentation files as is.

I dropped accounting, laptops, and pcmcia from this v2 series as per the v1 feedback on these being a better fit under tools. I will send a separate v2 for them.

If v2 patches look good, and if I get an okay, I will try to get these into 4.9-rc1

Quoted 6 lines

Changes since v1:
- Updated location information in .txt for timers, watchdog, and auxdisplay
- Updated MAINTAINERS file for misc-devices/mei based on feedback from Tomas Winkler
- Added Acked-by from Jon Corbet for timers, and misc-devices/mei

Looks good, feel free to add my ack to the rest.

jon
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html